E-book viewer: Fix errors when viewing books with mathematics that are split over multiple internal files. Fixes #1919033 [Unhandled mathjax loading related error in Viewer](https://bugs.launchpad.net/calibre/+bug/1919033)

This commit is contained in:
Kovid Goyal 2021-03-16 12:18:27 +05:30
parent de1dfc28e5
commit f2d92d2060
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -31,12 +31,27 @@ def load_mathjax(src):
document.head.appendChild(script) document.head.appendChild(script)
standalone_proceed_data = {
'link_uid': None,
'proceed': None,
'event_listender_added': False,
}
def standalone_proceed():
if standalone_proceed_data.proceed:
postprocess(standalone_proceed_data.link_uid)
standalone_proceed_data.proceed()
standalone_proceed_data.proceed = None
def apply_mathjax(mathjax_files, link_uid, proceed): def apply_mathjax(mathjax_files, link_uid, proceed):
if runtime.is_standalone_viewer: if runtime.is_standalone_viewer:
document.documentElement.addEventListener("calibre-mathjax-typeset-done", def(ev): if not standalone_proceed_data.event_listender_added:
postprocess(link_uid) standalone_proceed_data.event_listender_added = True
proceed() document.documentElement.addEventListener("calibre-mathjax-typeset-done", standalone_proceed)
) standalone_proceed_data.link_uid = link_uid
standalone_proceed_data.proceed = proceed
load_mathjax(f'{runtime.FAKE_PROTOCOL}://{runtime.SANDBOX_HOST}/mathjax/startup.js') load_mathjax(f'{runtime.FAKE_PROTOCOL}://{runtime.SANDBOX_HOST}/mathjax/startup.js')
return return
window.MathJax = v'{}' window.MathJax = v'{}'
@ -65,7 +80,7 @@ def apply_mathjax(mathjax_files, link_uid, proceed):
} }
# also do any changes in pdf-mathjax-loader.js for the standalone # also do any changes in pdf-mathjax-loader.js for the standalone
# viewer/editor/pdf outpu # viewer/editor/pdf output
window.MathJax.loader = { window.MathJax.loader = {
'load': v"['input/tex-full', 'input/asciimath', 'input/mml', 'output/chtml']", 'load': v"['input/tex-full', 'input/asciimath', 'input/mml', 'output/chtml']",
'require': def (url): 'require': def (url):