markdown-it-bracketed-spans icon indicating copy to clipboard operation
markdown-it-bracketed-spans copied to clipboard

Duplicate spans with extra opening brackets

Open cemulate opened this issue 3 years ago • 2 comments

With no plugins except markdown-it-bracketed-spans enabled, the source string

[[b]{}

renders as

<p><span>b</span>[<span>b</span>{}</p>

whereas I would expect

<p>[<span>b</span>{}</p>

the content inside the intended bracketed span is duplicated before it. With markdown-it-attrs included as well, you can observe the following minimal example:

[[b]{.c}

renders as

<p><span>b</span>[<span class="c">b</span></p>

I've tried for a little bit to debug this, but I just don't know a lot about markdown-it internals.

cemulate avatar Jul 17 '22 07:07 cemulate

That's seems indeed a weird behaviour... not sure it's easily fixable though... it's been some time since I've been hacking on this :-)

I just don't know a lot about markdown-it internals.

see https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md

mb21 avatar Jul 18 '22 14:07 mb21

Pretty sure the problem is that we go into this if, which says we "probably" found a span... but ideally we would verify this some more inside the if...

I think I originally mostly copy-pasted, then adjusted markdown-it's link parser, which has this line saying:

We found the end of the link, and know for a fact it's a valid link;

but I'm not sure how they got that additional information at that point 🤷

mb21 avatar Jul 18 '22 15:07 mb21