diff --git a/scintilla/lexers/LexMarkdown.cxx b/scintilla/lexers/LexMarkdown.cxx index 87adb65766..1b70b44c8c 100644 --- a/scintilla/lexers/LexMarkdown.cxx +++ b/scintilla/lexers/LexMarkdown.cxx @@ -1222,11 +1222,18 @@ bool MarkdownLexer::HighlightAutoLink() { break; case SCE_H_COMMENT: - invalid = sc.Match('-', '-', '>'); + if (sc.Match('-', '-')) { + const char chNext = sc.styler[sc.currentPos + 2]; + if (chNext == '>' || chNext == '?') { + invalid = true; + } + } break; case SCE_H_CDATA: - invalid = sc.Match(']', ']', '>'); + if (sc.Match(']', ']', '>')) { + invalid = true; + } break; } } @@ -1313,6 +1320,13 @@ bool MarkdownLexer::HandleHtmlTag(HtmlTagType tagType) { if (chNext == '-' && sc.GetRelative(3) == '-') { sc.SetState(SCE_H_COMMENT); sc.Advance(3); + // handle empty comment: , + // https://html.spec.whatwg.org/multipage/parsing.html#parse-error-abrupt-closing-of-empty-comment + if (sc.chNext == '>' || sc.MatchNext('-', '>')) { + sc.Forward((sc.chNext == '>') ? 2 : 3); + sc.SetState(current); + return true; + } } else if (chNext == '[' && sc.styler.Match(sc.currentPos + 3, "CDATA[")) { // sc.SetState(SCE_H_CDATA); @@ -2276,11 +2290,18 @@ void ColouriseMarkdownDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int in break; case SCE_H_COMMENT: - if (sc.Match('-', '-', '>')) { - lexer.tagState = HtmlTagState::None; - sc.Advance(3); - sc.SetState(lexer.TryTakeOuterStyle()); - continue; + if (sc.Match('-', '-')) { + do { + sc.Forward(); + } while (sc.ch == '-'); + // close HTML comment with --!> + // https://html.spec.whatwg.org/multipage/parsing.html#parse-error-incorrectly-closed-comment + if (sc.ch == '>' || sc.Match('!', '>')) { + lexer.tagState = HtmlTagState::None; + sc.Forward((sc.ch == '>') ? 1 : 2); + sc.SetState(lexer.TryTakeOuterStyle()); + continue; + } } lexer.DetectAutoLink(); break;