sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 588 forks source link

[Markdown] Tilde within kbd tag matched as beginning of strikethough #2846

Open deathaxe opened 3 years ago

deathaxe commented 3 years ago

Code

*   <kbd>~</kbd> wraps selected text with `~~` (strikethrough). When you for instance select the word "foo" and hit  `~`, the result will be `~~foo~~`.

GitHub rendering result

Sublime Text highlighting

The whole paragraph after <kbd>~</kbd> is scoped markup.strikethrough

grafik

keith-hall commented 3 years ago

This is essentially the same issue as https://github.com/sublimehq/Packages/issues/1499, which we can potentially resolve with branching now.

deathaxe commented 3 years ago

Why? Markup should be disabled between html tags, shouldn't it? So none of those chars -, *, ~ should have any special meaning then. Just pushing a context onto stack once <kbd> is matched, expecting it to be closed by </kbd> should do the trick.

keith-hall commented 3 years ago

Why? Markup should be disabled between html tags, shouldn't it?

Only block level tags which start the line iirc. We have a test assertion to prove bold and italic work even through closing tags, which is how GFM and CommonMark also treat it - as valid.

deathaxe commented 3 years ago

That's not exactly what I see, when calling MarkdownPreview > Github

grafik

FichteFoll commented 3 years ago

I don't understand what you mean

<kbd>~~I don't understand what you mean~~</kbd>

Inline markup is valid inside inline HTML tags. What we shoul do is prevent ~ from being able to capture across tag boundaries, because HTML is strictly hierarchical, but in order to do that properly we need branching. We definitely should, however.

keith-hall commented 3 years ago

https://spec.commonmark.org/dingus/?text=__test%20%3Cspan%3Etext__%20*formatted%3C%2Fspan%3Etest*%0A%0A*test%20%3Cspan%3Etext*%20__formatted%3C%2Fspan%3Etest__%0A

__test <span>text__ *formatted</span>test*

*test <span>text* __formatted</span>test__

image

deathaxe commented 3 years ago

Up to this point I was confident Markdon to be something reasonable structured peace of standard - seems I have been wrong.

deathaxe commented 3 years ago

Hmm. Formatting stops at closing tags, but is applied only if closing ~~ exists. What a mess.

grafik

FichteFoll commented 3 years ago

spec.commonmark.org/dingus/?text=test%20%3Cspan%3Etext%20formatted%3C%2Fspan%3Etest%0A%0Atest%20%3Cspan%3Etext%20formatted%3C%2Fspan%3Etest%0A

I am legitimately surprised that these work. They even produce the HTML you would expect. It even makes sense if you consider that li tags also don't need to be closed, so what happens above is that the span tag is closed implicitly by </strong> and the following </span> does nothing.

2021-06-02_02-38-51

Also explains @deathaxe's examples.

Now, watch me make things even more confusing in GFM, where the kbd tag just resets inline markdown (unlike with the span tag).

test text normal formattedtest test text normal formattedtest test text normal formattedtest test text normal formattedtest

__test <span>text__ normal *formatted</span>test*
__test <kbd>text__ normal *formatted</kbd>test*
~~test <span>text~~ normal ~~formatted</span>test~~
~~test <kbd>text~~ normal ~~formatted</kbd>test~~