tsung-ju / eleventy-plugin-mathjax

Eleventy plugin for server-side MathJax rendering
Apache License 2.0
8 stars 3 forks source link

Error when HTML attributes start with special character #6

Open asterixpound opened 1 year ago

asterixpound commented 1 year ago

I was trying to use this plugin with eleventy-notes. However, the plugin does not seem to work when there are HTML attributes starting with special characters, as with :aria-label or @click which are used for Alpine and should be valid HTML attributes. Attempting to do so gives the following error:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble writing to "dist/404.html" from "../.app/pages/404.njk" (via EleventyTemplateError)
[11ty] 2. Transform `mathjax` encountered an error when transforming ../.app/pages/404.njk. (via EleventyTransformError)
[11ty] 3. Can't find handler for document (via Error)

Using the longhand syntax for Alpine, we can replace :foo with x-bind:foo and @bar with x-on:bar in which case there are no errors and equations are displayed as expected.

See the original discussion at https://github.com/rothsandro/eleventy-notes/issues/37.

tsung-ju commented 1 year ago

Hi, thanks for reporting the issue. This looks like a bug in mathjax's HTML parser, which I believe can only be fixed by the upstream.

If you only need latex syntax in markdown files, I recommend using tani/markdown-it-mathjax3 instead. It works directly on Markdown sources, so it shouldn't have issue with syntax errors in HTML. It can be added to an eleventy website through the custom mardown-it instance feature.

asterixpound commented 1 year ago

Thanks @tsung-ju, I wanted to report the bug upstream but I hesitate to do so without a clear understanding of how the liteDom adaptor is being used or how to bring about the error outside of eleventy.

I appreciate your suggestion of using https://github.com/tani/markdown-it-mathjax3. I will give it a try.