mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Avoid the need to use a patched version of MathJax
See https://github.com/mathjax/MathJax/pull/1453
This commit is contained in:
parent
f6ef5f3cf7
commit
bf60631ce0
@ -21,7 +21,8 @@ from setup import Command, download_securely
|
||||
class MathJax(Command):
|
||||
|
||||
description = 'Create the MathJax bundle'
|
||||
MATH_JAX_URL = 'https://github.com/kovidgoyal/MathJax/archive/master.zip'
|
||||
MATH_JAX_VERSION = '2.7.5'
|
||||
MATH_JAX_URL = 'https://github.com/mathjax/MathJax/archive/%s.zip' % MATH_JAX_VERSION
|
||||
FONT_FAMILY = 'TeX'
|
||||
|
||||
def add_options(self, parser):
|
||||
@ -33,7 +34,7 @@ class MathJax(Command):
|
||||
raw = download_securely(url)
|
||||
with ZipFile(BytesIO(raw)) as zf:
|
||||
zf.extractall(tdir)
|
||||
return os.path.join(tdir, 'MathJax-master')
|
||||
return os.path.join(tdir, 'MathJax-' + self.MATH_JAX_VERSION)
|
||||
|
||||
def add_file(self, zf, path, name):
|
||||
with open(path, 'rb') as f:
|
||||
|
@ -13,6 +13,18 @@ def get_url(mathjax_files, name):
|
||||
return ans
|
||||
|
||||
def monkeypatch(mathjax_files):
|
||||
StyleString = window.MathJax.Ajax.StyleString.bind(window.MathJax.Ajax)
|
||||
|
||||
def style_string(styles):
|
||||
# replace the URLs in the generated stylesheet
|
||||
return StyleString(styles).replace(/url\('?(.*?)'?\)/g, def (match, url):
|
||||
if not url.endsWith('.woff'):
|
||||
return match
|
||||
url = get_url(mathjax_files, url)
|
||||
ans = f"url('{url}')"
|
||||
return ans
|
||||
)
|
||||
|
||||
orig = window.MathJax.Ajax.fileURL.bind(window.MathJax.Ajax)
|
||||
def file_url(file):
|
||||
ans = orig(file)
|
||||
@ -28,6 +40,7 @@ def monkeypatch(mathjax_files):
|
||||
print('WARNING: Failed to resolve MathJax file:', name)
|
||||
return ans
|
||||
window.MathJax.Ajax.fileURL = file_url
|
||||
window.MathJax.Ajax.StyleString = style_string
|
||||
window.MathJax.Ajax.fileRev = def(file):
|
||||
return ''
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user