Packages icon indicating copy to clipboard operation
Packages copied to clipboard

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

Open deathaxe opened this issue 4 years ago • 9 comments

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

  • ~ wraps selected text with ~~ (strikethrough). When you for instance select the word "foo" and hit ~, the result will be ~~foo~~.

Sublime Text highlighting

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

grafik

deathaxe avatar May 30 '21 08:05 deathaxe

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

keith-hall avatar May 31 '21 19:05 keith-hall

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.

deathaxe avatar May 31 '21 19:05 deathaxe

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.

keith-hall avatar May 31 '21 19:05 keith-hall

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

grafik

deathaxe avatar May 31 '21 20:05 deathaxe

~~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.

FichteFoll avatar Jun 01 '21 00:06 FichteFoll

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

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

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

image

keith-hall avatar Jun 01 '21 18:06 keith-hall

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

deathaxe avatar Jun 01 '21 19:06 deathaxe

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

grafik

deathaxe avatar Jun 01 '21 20:06 deathaxe

spec.commonmark.org/dingus/?text=test%20%3Cspan%3Etext%20formatted%3C%2Fspan%3Etest%0A%0Atest%20%3Cspan%3Etext%20__formatted%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~~

FichteFoll avatar Jun 02 '21 00:06 FichteFoll