-
-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Library Version
v2.6.0
Description
When processing markdown content that contains inline LaTeX expressions with underscores (e.g., $(a_n)_{n \in \mathbb{N}}$ und $(b_n)_{n \in \mathbb{N}}$ sind geometrische Folgen.), swift-markdown's parser treats the underscores as emphasis markers and splits the text into separate nodes before any custom visitor logic can process the complete expression.
This fundamentally breaks any downstream processing that needs to see the raw, unsplit text - particularly for LaTeX/math rendering where underscores are used for subscripts.
When visiting a Paragraph node, instead of having access to the full raw text, the paragraph's children are already split:
- Text:
$(a_n) - Emphasis:
{n \in \mathbb{N}}$ und $(b_n) - Text:
{n \in \mathbb{N}}$ sind geometrische Folgen.
This prevents any visitor from correctly identifying that there are two complete LaTeX expressions ($(a_n)_{n \in \mathbb{N}}$ and $(b_n)_{n \in \mathbb{N}}$) that should not have their underscores interpreted as markdown emphasis.
Minimum reproducible code
Just use the referenced markdown below to reproduce the behaviour. Here's a screenshot which visualizes the issue. At the top, the text using the LaTeX SwiftUI view directly with the referenced markdown. Below the rendering of the MarkdownView SwiftUI view.
Raw markdown
$(a_n)_{n \in \mathbb{N}}$ und $(b_n)_{n \in \mathbb{N}}$ sind geometrische Folgen.Additional comments
I know this is how swift-markdown is working and parsing the markdown but maybe we could visit the inline math first before we're handling the children of the paragraph? 🤔