badboy / mdbook-toc

A preprocessor for mdbook to add inline Table of Contents support.
Mozilla Public License 2.0
163 stars 20 forks source link

TOC does not render Mathjax correctly #51

Open malachid opened 7 months ago

malachid commented 7 months ago

When using Mathjax along with mdbook-toc, there is a discrepancy in how it is rendered.

Let's say you add a heading like:

### Some header \\( \lfloor\sqrt 2 \\)

The header will render properly using Mathjax. The TOC at the top of the page will show the raw text instead.

badboy commented 7 months ago

Can you show a screenshot of that? And maybe share the HTML code it generates.

malachid commented 7 months ago

Sure:

<li><a href="#same--lfloorsqrt-pq-">Same ( \lfloor\sqrt pq )</a></li>

Screenshot from 2024-03-10 11-54-21 Screenshot from 2024-03-10 11-54-38

badboy commented 6 months ago

Looks like that's what we get from pulldown-cmark at the moment, so I might re-escape the data before outputting it.

badboy commented 6 months ago

upstream issue: https://github.com/pulldown-cmark/pulldown-cmark/issues/572 And it would require a bunch of work to make that possible in mdbook-toc. If we "just" use the span of the header event we would get the original text instead of the unescaped one, but because headers can now include additional tag (# header {#additional .stuff}) we would need to parse that out again. Which I don't want to, because that's half-way to a markdown parser again.

For now I don't have a solution.