remarkjs/remark-math

When there are non space characters after $$ the parser ends up interpreting the whole doc as part of the node (v3)

Stvad opened this issue · 8 comments

Stvad commented

When trying to parse the following document:

# Debug

$$
\LaTeX
$$ words

more words

I end up with the following HTML:

<h1 id="debug">Debug</h1>
<div class="math math-display">\LaTeX
$$ words

more words


export const _frontmatter = {}</div>

So the $$ latter is not interpreted as the end of the node and the rest of the document is consumed =\

Your environment

  • OS: macOS 10.15.7
  • Packages: remark-math 3.0.1.
  • Env: Node v15.6.0
  • This is done in the context of Gatsby & gatsby-plugin-mdx (1.10.1) and hence remark 12.

Steps to reproduce

Render the example above.

Codesandbox: https://codesandbox.io/s/remark-rehype-debug-forked-no50m?file=/src/index.js

Expected behavior

Only content inside $$ is interpreted as part of the node

Actual behavior

The second $$ is ignored and the rest of the document is consumed

This is in line with how fenced code works too. Take this markdown.

# Debug

```
\LaTeX
``` words

more words

Debug

\LaTeX
``` words

more words

So everything after it becomes code.

Why not fix your “closing” fence?

Closing this as it’s intended behavior documented in the changelog: 9b4b3c3

Stvad commented

I see, this is unfortunate 🙁. This has really bad consequences when used with MDX - if you interleave this somewhere within the document - it's gonna consume JSX components/any meta code/etc after till the end of the document =\ . Leading to MDX failing to parse things

Please elaborate.

Stvad commented

I've described my context in mdx-js/mdx#1477 (reply in thread) which I believe you saw.
If a snippet like described in this issue - gets passed in to me as an input and I put it into an MDX document - It's going to corrupt the overall constructed document as it's going to consume the closing tag for it's section and the rest of the document making the parsing and the build fail 🙁

If a snippet like described in this issue - gets passed in to me as an input and I put it into an MDX document - It's going to corrupt the overall constructed document as it's going to consume the closing tag for it's section and the rest of the document making the parsing and the build fail 🙁

That’s how things work. If you pass <div></div> to an HTML parser, it’s going to see an element. If you pass console.log(1) to a JavaScript parser, it’s going to see a function call.

This isn’t an issue here (https://xyproblem.info): it has to do with the overall discussion over there

whoops 😅 should be closed I think

Very bad design 👎 . Almost every MarkDown extension support inline $$expr$$, both marked, markdown-it, GitHub ...

I'm now migrating some MarkDown-with-math files from markdown-it to remark. Holy **** this behavior just make everything a mess.