badboy / mdbook-mermaid

A preprocessor for mdbook to add mermaid support
Mozilla Public License 2.0
311 stars 31 forks source link

Mermaid Syntax Error in text on mdbook highlight #42

Open anistark opened 7 months ago

anistark commented 7 months ago

Mermaid diagram is failing on mdbook search.

How to reproduce:

Search anything on mdbook that matches the texts inside mermaid diagram. It fails with said message.

Screenshot 2024-03-29 at 3 37 59 PM

Possible keyword clashes between query param highlight

badboy commented 7 months ago

Highlighting is done client-side in JS. It inserts some additional HTML around the words to highlight. The mermaid code is still in the HTML and the highlighter runs before mermaid.js. There's really not much we can do here.

anistark commented 7 months ago

@badboy any way to avoid it ? Like disable highlight in mermaid?

badboy commented 7 months ago

The highlighting is done in mdbook's JavaScript here: https://github.com/rust-lang/mdBook/blob/bd323fb930eaadff4e8ee3859b064731617fd875/src/theme/searcher/searcher.js#L298-L315

I don't know how it works. Maybe mark_exclude can be a list of things? It's always set to the empty list though, so you would either need to modify that file and deploy it or find a way to inject your own configuration before it runs. Alternatively figure out a way for mermaid.js to run before the searcher.js does its job.