xoofx / markdig

A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
BSD 2-Clause "Simplified" License
4.21k stars 444 forks source link

Single `+` in superscript or subscript #791

Open geoffreymcgill opened 3 months ago

geoffreymcgill commented 3 months ago

We ran into a very specific scenario using a + in superscript or subscript that appears to fail parsing correctly.

Sample 1

Superscript^+^ or Subscript~+~

The above renders as...

Screen Shot 2024-04-16 at 11 09 26 AM

Sample 2

If a space is added before the ^+^, then it parses correctly:

Superscript ^+^ or Subscript ~+~

The above renders as...

Screen Shot 2024-04-16 at 11 09 35 AM

Sample 3

Interestingly, using ^+^ also fails:

Superscript^+^ or Subscript~+~

The above renders as...

Screen Shot 2024-04-16 at 11 09 40 AM

The parsing issue only happens when using a single + char. If revised to a - char, then the subscript and subscript parse and render correctly.

Can anyone else reproduce?

Hope this helps.

xoofx commented 1 month ago

It is reproduced here

I would believe it is a bug but don't have personal time dedicated to fix it, so PR welcome if someone is motivated. Not entirely sure that the fix is easy, as the parsing of the matching opening/closing super/sub scripts might be reusing the same rules that we use for bold/italic, and these rules are quite strict (e.g need a space before and after the opening/closing braces)