diff --git a/README.md b/README.md index 6652732..d4eb335 100644 --- a/README.md +++ b/README.md @@ -118,8 +118,8 @@ When enabled the extension will make a GET request every second to: The following `mathjax` delimiters are supported: -- inline math: `\(math\)` and `$math$` -- display math: `\[math\]` and `$$math$$` +- inline math: `\(math\)`, `$math$`, and ``$`math`$`` +- display math: `\[math\]`, `$$math$$`, and math code blocks (```` ```math ````) The following rules apply to your content when `mathjax` is enabled: diff --git a/background/mathjax.js b/background/mathjax.js index 4bd9214..3d51cbe 100644 --- a/background/mathjax.js +++ b/background/mathjax.js @@ -7,6 +7,7 @@ md.mathjax = () => { /\\\[[^`]*?\\\]/, /\\begin\{.*?\}[^`]*?\\end\{.*?\}/, /\$[^`\n]*?\$/, + /\$`[^`\n]*?`\$/, ] .map((regex) => `(?:${regex.source})`).join('|'), 'gi') diff --git a/content/index.js b/content/index.js index 34875fd..41140d8 100644 --- a/content/index.js +++ b/content/index.js @@ -104,6 +104,14 @@ function mount () { dom.push(m('script', { src: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js' })) + dom.push(m('script', {type: 'text/javascript'}, ` + ;(() => { + var mathblocks = document.querySelectorAll('code.language-math') + mathblocks.forEach(mathblock => { + mathblock.parentNode.replaceWith("$$" + mathblock.textContent + "$$") + }) + })() + `)) } if (state.content.mermaid) { dom.push(m('script', { @@ -336,6 +344,7 @@ var mathjax = ` inlineMath: [ ['$', '$'], ['\\\\(', '\\\\)'], + ['$\`', '\`$'], ], displayMath: [ ['$$', '$$'],