Add version dependent selection of js for preview.
Anki 2.1.44 and prior used a different set of javascript in the reviewer. There is no easy way to obtain those programmatically, so this is a crude fix. Fixes #2 Signed-off-by: Tobias Manske <tobias.manske@mailbox.org>
This commit is contained in:
parent
55ba8a273d
commit
f69933d7bd
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from anki import hooks
|
from anki import hooks, buildinfo
|
||||||
from aqt import editor, gui_hooks, mw
|
from aqt import editor, gui_hooks, mw
|
||||||
from aqt.utils import *
|
from aqt.utils import *
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
@ -8,10 +8,23 @@ from aqt.webview import AnkiWebView
|
|||||||
|
|
||||||
|
|
||||||
class EditorPreview(object):
|
class EditorPreview(object):
|
||||||
|
js=[
|
||||||
|
"js/mathjax.js",
|
||||||
|
"js/vendor/mathjax/tex-chtml.js",
|
||||||
|
"js/reviewer.js",
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
gui_hooks.editor_did_init.append(self.editor_init_hook)
|
gui_hooks.editor_did_init.append(self.editor_init_hook)
|
||||||
gui_hooks.editor_did_init_buttons.append(self.editor_init_button_hook)
|
gui_hooks.editor_did_init_buttons.append(self.editor_init_button_hook)
|
||||||
|
if int(buildinfo.version.split(".")[2]) < 45: # < 2.1.45
|
||||||
|
self.js = [
|
||||||
|
"js/vendor/jquery.min.js",
|
||||||
|
"js/vendor/css_browser_selector.min.js",
|
||||||
|
"js/mathjax.js",
|
||||||
|
"js/vendor/mathjax/tex-chtml.js",
|
||||||
|
"js/reviewer.js",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def editor_init_hook(self, ed: editor.Editor):
|
def editor_init_hook(self, ed: editor.Editor):
|
||||||
@ -20,16 +33,10 @@ class EditorPreview(object):
|
|||||||
ed.webview.stdHtml(
|
ed.webview.stdHtml(
|
||||||
ed.mw.reviewer.revHtml(),
|
ed.mw.reviewer.revHtml(),
|
||||||
css=["css/reviewer.css"],
|
css=["css/reviewer.css"],
|
||||||
js=[
|
js=self.js,
|
||||||
"js/mathjax.js",
|
|
||||||
"js/vendor/mathjax/tex-chtml.js",
|
|
||||||
"js/reviewer.js",
|
|
||||||
],
|
|
||||||
context=ed,
|
context=ed,
|
||||||
)
|
)
|
||||||
# very arbitrary max size
|
|
||||||
# otherwise the browse window is not usable
|
|
||||||
# ed.webview.setMaximumHeight = 400
|
|
||||||
self._inject_splitter(ed)
|
self._inject_splitter(ed)
|
||||||
gui_hooks.editor_did_fire_typing_timer.append(lambda o: self.onedit_hook(ed, o))
|
gui_hooks.editor_did_fire_typing_timer.append(lambda o: self.onedit_hook(ed, o))
|
||||||
gui_hooks.editor_did_load_note.append(lambda o: None if o != ed else self.editor_note_hook(o))
|
gui_hooks.editor_did_load_note.append(lambda o: None if o != ed else self.editor_note_hook(o))
|
||||||
@ -76,5 +83,4 @@ class EditorPreview(object):
|
|||||||
if editor.note == origin:
|
if editor.note == origin:
|
||||||
editor.webview.eval(self._obtainCardText(editor.note))
|
editor.webview.eval(self._obtainCardText(editor.note))
|
||||||
|
|
||||||
|
|
||||||
eprev = EditorPreview()
|
eprev = EditorPreview()
|
||||||
|
Loading…
Reference in New Issue
Block a user