KaTeX: don't use autorenderer.
We no longer surround formulas with `\(..\)` or `\[..\]` and rely on the autorenderer. Instead, we tell katex to convert the contents of span elements with class "math". Since math has already been identified, this avoids wasted time parsing for LaTeX delimiters. Note, however, that this may yield unexpected results if you have span elements with class "math" that don't contain LaTeX math. Also, use latest version of KaTeX by default (0.9.0). Closes #4946.
This commit is contained in:
parent
2caf198b46
commit
f766348fd8
2 changed files with 6 additions and 6 deletions
|
@ -277,10 +277,10 @@ pandocToHtml opts (Pandoc meta blocks) = do
|
|||
KaTeX url -> do
|
||||
H.script !
|
||||
A.src (toValue $ url ++ "katex.min.js") $ mempty
|
||||
H.script !
|
||||
A.src (toValue $ url ++ "contrib/auto-render.min.js") $ mempty
|
||||
nl opts
|
||||
H.script
|
||||
"document.addEventListener(\"DOMContentLoaded\", function() {\n renderMathInElement(document.body);\n});"
|
||||
"document.addEventListener(\"DOMContentLoaded\", function () {\n var mathElements = document.getElementsByClassName(\"math\");\n for (var i = 0; i < mathElements.length; i++) {\n var texText = mathElements[i].firstChild;\n if (mathElements[i].tagName == \"SPAN\") { katex.render(texText.data, mathElements[i], { displayMode: mathElements[i].classList.contains(\"display\"), throwOnError: false } );\n }}});"
|
||||
nl opts
|
||||
H.link ! A.rel "stylesheet" !
|
||||
A.href (toValue $ url ++ "katex.min.css")
|
||||
|
||||
|
@ -1065,8 +1065,8 @@ inlineToHtml opts inline = do
|
|||
DisplayMath -> "\\[" ++ str ++ "\\]"
|
||||
KaTeX _ -> return $ H.span ! A.class_ mathClass $ toHtml $
|
||||
case t of
|
||||
InlineMath -> "\\(" ++ str ++ "\\)"
|
||||
DisplayMath -> "\\[" ++ str ++ "\\]"
|
||||
InlineMath -> str
|
||||
DisplayMath -> str
|
||||
PlainMath -> do
|
||||
x <- lift (texMathToInlines t str) >>= inlineListToHtml opts
|
||||
let m = H.span ! A.class_ mathClass $ x
|
||||
|
|
|
@ -55,4 +55,4 @@ defaultMathJaxURL :: String
|
|||
defaultMathJaxURL = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/"
|
||||
|
||||
defaultKaTeXURL :: String
|
||||
defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/"
|
||||
defaultKaTeXURL = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0/"
|
||||
|
|
Loading…
Reference in a new issue