highlight.js icon indicating copy to clipboard operation
highlight.js copied to clipboard

(markdown) List items inside blockquotes/HTML comments aren't highlighted correctly

Open double-beep opened this issue 2 years ago • 3 comments

Consider this markdown:

> * One (this point is italic)
> * Two
> * Three

This is italic, and because of a lack of termination (#21), everything after is italic

<!-- * but a comment terminates the italic -->

Regular text

It gets highlighted like this:

incorrect markdown highlighting


It is, however, valid markdown:

  • One (this point is italic)
  • Two
  • Three

This should not be italic

Regular text


Compare with the following markdown:

> - One
> - Two
> - Three

some text

that gets highlighted like this:

correct markdown highlighting

or this:

* One
* Two
* Three

some text

which gets highlighted like this:

correct markdown highlighting

double-beep avatar Apr 11 '22 13:04 double-beep

Thanks for the report!

Hmmm... How does a typical Markdown parser know this isn't the beginning of italics (which can span lines typically, no?)... are the rules for italics different inside quotes? What would this be:

> * One (this point is italic) *
> * Two *
> * Three *

Or this:

> *One (this point is italic)*
> *Two*
> *Three*

Is there a difference?

joshgoebel avatar Apr 11 '22 15:04 joshgoebel

I believe that in lists a space between the -/*/... character and the list content is necessary, while in italic/bold there must be no space between **/__/... and the emphasised content.

The CommonMark specification has more examples than the original MD syntax.

double-beep avatar Apr 12 '22 04:04 double-beep

I think the attached PR fixes the false positive, but I'm not sure how to detect the bullets in blockquotes... we don't have sequencing abilities for nesting so there is no way to match the block quote then say "match a bullet, BUT only if it begins immediately after the quote"...

Look-behind could help here, but we can't do that yet because of lagging Safari support.

joshgoebel avatar Apr 12 '22 18:04 joshgoebel