Markdown.ToPlainText() returns HTML tags for mathematics #479

Closed
opened 2026-01-29 14:37:48 +00:00 by claunia · 4 comments
Owner

Originally created by @Sleepyowl on GitHub (Aug 12, 2021).

Invalid conversion to plain text for mathematic blocks:

Repro:

Markdown.ToPlainText("$$ x_{1}=\frac{-b + \\sqrt{b^{2} - 4ac}}{2a} $$", new MarkdownPipelineBuilder().UseMathematics().Build())

expected result: no HTML tags
actual result: <span class="math">\(x_{1}=\frac{-b + \sqrt{b^{2} - 4ac}}{2a}\)</span>

Originally created by @Sleepyowl on GitHub (Aug 12, 2021). Invalid conversion to plain text for mathematic blocks: Repro: ``` Markdown.ToPlainText("$$ x_{1}=\frac{-b + \\sqrt{b^{2} - 4ac}}{2a} $$", new MarkdownPipelineBuilder().UseMathematics().Build()) ``` expected result: no HTML tags actual result: `<span class="math">\(x_{1}=\frac{-b + \sqrt{b^{2} - 4ac}}{2a}\)</span>`
claunia added the enhancementPR Welcome! labels 2026-01-29 14:37:48 +00:00
Author
Owner

@xoofx commented on GitHub (Aug 22, 2021):

Plain text does not support many extensions. You will need to create a PR to fix it.

@xoofx commented on GitHub (Aug 22, 2021): Plain text does not support many extensions. You will need to create a PR to fix it.
Author
Owner

@Sleepyowl commented on GitHub (Aug 24, 2021):

Makes sense.

Giving this a second thought, simply removing html tags and outputting source LaTeX is not “Plain Text” enough for my purposes.

If you’re OK with dragging in LaTeX parser dependency, I’ll create a PR when (or to be honest, more like “if”) I get it done.

@Sleepyowl commented on GitHub (Aug 24, 2021): Makes sense. Giving this a second thought, simply removing html tags and outputting source LaTeX is not “Plain Text” enough for my purposes. If you’re OK with dragging in LaTeX parser dependency, I’ll create a PR when (or to be honest, more like “if”) I get it done.
Author
Owner

@xoofx commented on GitHub (Aug 24, 2021):

If you’re OK with dragging in LaTeX parser dependency, I’ll create a PR when (or to be honest, more like “if”) I get it done.

Unfortunately, Markdig has a policy to not take any dependencies. As Markdig can embed any kind of non-markdown content (HTML, custom content like LaTex...etc.), it is not practical to support these scenarios (that can be very app/end-user specific and difficult to fit-for-all)
Though, the markdig API should provide enough pluggability to develop what you are looking for as an extension, outside of the Markdig lib/repo.

@xoofx commented on GitHub (Aug 24, 2021): > If you’re OK with dragging in LaTeX parser dependency, I’ll create a PR when (or to be honest, more like “if”) I get it done. Unfortunately, Markdig has a policy to not take any dependencies. As Markdig can embed any kind of non-markdown content (HTML, custom content like LaTex...etc.), it is not practical to support these scenarios (that can be very app/end-user specific and difficult to fit-for-all) Though, the markdig API should provide enough pluggability to develop what you are looking for as an extension, outside of the Markdig lib/repo.
Author
Owner

@Sleepyowl commented on GitHub (Aug 24, 2021):

Ok I went with a simple approach for the PR: I've added checks for EnableHtml* flags to the extension.

I cannot figure out though how to link the PR to this issue, but here it is: https://github.com/xoofx/markdig/pull/570

@Sleepyowl commented on GitHub (Aug 24, 2021): Ok I went with a simple approach for the PR: I've added checks for EnableHtml* flags to the extension. I cannot figure out though how to link the PR to this issue, but here it is: https://github.com/xoofx/markdig/pull/570
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#479