EmphasisExtraOptions.Strikethrough and EmphasisExtraOptions.Subscript Influence each other #246

Closed
opened 2026-01-29 14:31:35 +00:00 by claunia · 6 comments
Owner

Originally created by @daxianji007 on GitHub (Nov 26, 2018).

~Subscript~ ~~Strike~~ tunrs to <p><sub>Subscript</sub> <del>Strike</del></p> no matter I choose .UseEmphasisExtras(EmphasisExtraOptions.Subscript) or .UseEmphasisExtras(EmphasisExtraOptions.Strikethrough)

Root cause: they both use ~ as opening characters and parser did not distinguish them. I have finished a test case but find it difficult to fix... I just create an issue here first.

Originally created by @daxianji007 on GitHub (Nov 26, 2018). `~Subscript~ ~~Strike~~` tunrs to `<p><sub>Subscript</sub> <del>Strike</del></p>` no matter I `choose .UseEmphasisExtras(EmphasisExtraOptions.Subscript)` or `.UseEmphasisExtras(EmphasisExtraOptions.Strikethrough)` Root cause: they both use `~` as opening characters and parser did not distinguish them. I have finished a test case but find it difficult to fix... I just create an issue here first.
claunia added the enhancementPR Welcome! labels 2026-01-29 14:31:35 +00:00
Author
Owner

@xoofx commented on GitHub (Nov 26, 2018):

Yeah, the code is actually not assuming that you can ask one without the other...

6c2702f9fd/src/Markdig/Extensions/EmphasisExtras/EmphasisExtraExtension.cs (L71)

I would expect that changing the parameter 1, 2 to 1, 1 only if subscript is asked, 2, 2 if strikethrough is asked, and 1,2 if both are asked could work, but not sure (for 2, 2 never tried)

@xoofx commented on GitHub (Nov 26, 2018): Yeah, the code is actually not assuming that you can ask one without the other... https://github.com/lunet-io/markdig/blob/6c2702f9fd0a277881f06e881b044a849676f480/src/Markdig/Extensions/EmphasisExtras/EmphasisExtraExtension.cs#L71 I would expect that changing the parameter `1, 2` to `1, 1` only if subscript is asked, `2, 2` if strikethrough is asked, and `1,2` if both are asked could work, but not sure (for `2, 2` never tried)
Author
Owner

@daxianji007 commented on GitHub (Nov 26, 2018):

Yeah, I have tried the following code:

if (requireTilde && !hasTilde)
{
	var minimumCount = (Options & EmphasisExtraOptions.Subscript) != 0 ? 1 : 2;
	var maximumCount = (Options & EmphasisExtraOptions.Strikethrough) != 0 ? 2 : 1;
	parser.EmphasisDescriptors.Add(new EmphasisDescriptor('~', minimumCount, maximumCount, true));
}

But it does not work. I find that the maximumCount is actually not used in the parser...

@daxianji007 commented on GitHub (Nov 26, 2018): Yeah, I have tried the following code: ``` if (requireTilde && !hasTilde) { var minimumCount = (Options & EmphasisExtraOptions.Subscript) != 0 ? 1 : 2; var maximumCount = (Options & EmphasisExtraOptions.Strikethrough) != 0 ? 2 : 1; parser.EmphasisDescriptors.Add(new EmphasisDescriptor('~', minimumCount, maximumCount, true)); } ``` But it does not work. I find that the maximumCount is actually not used in the parser...
Author
Owner

@FranklinWhale commented on GitHub (Jan 15, 2019):

@daxianji007, @xoofx:

I have created a PR (#286) for this issue and incorporated @daxianji007's code into it. UseEmphasisExtras(EmphasisExtraOptions.Strikethrough) now works as expected but UseEmphasisExtras(EmphasisExtraOptions.Subscript) does not because of the following test case:

~~test~~

I tried to add checks for MaximumCount in c19840d663 and ea0bf3388f but neither of them has the intended result.

Also, I am not sure whether my expected result, <p><sub>~test~</sub></p>, is correct.

In case UseEmphasisExtras(EmphasisExtraOptions.Subscript) is hard to fix, can the fix for UseEmphasisExtras(EmphasisExtraOptions.Strikethrough) be merged first?

@FranklinWhale commented on GitHub (Jan 15, 2019): @daxianji007, @xoofx: I have created a PR (#286) for this issue and incorporated @daxianji007's code into it. `UseEmphasisExtras(EmphasisExtraOptions.Strikethrough)` now works as expected but `UseEmphasisExtras(EmphasisExtraOptions.Subscript)` does not because of the following test case: ```markdown ~~test~~ ``` I tried to add checks for `MaximumCount` in https://github.com/lunet-io/markdig/pull/286/commits/c19840d663607968357bfa119280ed75eec71c2e and https://github.com/lunet-io/markdig/pull/286/commits/ea0bf3388f220377e3f2d88b1ccd0506eb1fca1e but neither of them has the intended result. Also, I am not sure whether my expected result, `<p><sub>~test~</sub></p>`, is correct. In case `UseEmphasisExtras(EmphasisExtraOptions.Subscript)` is hard to fix, can the fix for `UseEmphasisExtras(EmphasisExtraOptions.Strikethrough)` be merged first?
Author
Owner

@MihaZupan commented on GitHub (Jan 15, 2019):

@FranklinWhale I believe that for that test case the correct output would be two nested <sub> tags.
~~foo~~ => <sub><sub>foo</sub></sub>
Same as with nested strong tags
****foo**** => <strong><strong>foo</strong></strong>

@MihaZupan commented on GitHub (Jan 15, 2019): @FranklinWhale I believe that for that test case the correct output would be two nested `<sub>` tags. `~~foo~~` => `<sub><sub>foo</sub></sub>` Same as with nested strong tags `****foo****` => `<strong><strong>foo</strong></strong>`
Author
Owner

@xoofx commented on GitHub (Jan 15, 2019):

Fixed by #287

@xoofx commented on GitHub (Jan 15, 2019): Fixed by #287
Author
Owner

@FranklinWhale commented on GitHub (Jan 15, 2019):

Thanks all

@FranklinWhale commented on GitHub (Jan 15, 2019): Thanks all
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#246