From bf60631ce05d021afb09c47dabb557733100a56e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Dec 2018 15:38:14 +0530 Subject: [PATCH] Avoid the need to use a patched version of MathJax See https://github.com/mathjax/MathJax/pull/1453 --- setup/mathjax.py | 5 +++-- src/pyj/read_book/mathjax.pyj | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/setup/mathjax.py b/setup/mathjax.py index 04997d8aab..72d7b53dff 100644 --- a/setup/mathjax.py +++ b/setup/mathjax.py @@ -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: diff --git a/src/pyj/read_book/mathjax.pyj b/src/pyj/read_book/mathjax.pyj index 9923e4d3f6..33fcd79626 100644 --- a/src/pyj/read_book/mathjax.pyj +++ b/src/pyj/read_book/mathjax.pyj @@ -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 ''