From f7ffb60ac957df7b6295da3d1327f4526b46f364 Mon Sep 17 00:00:00 2001 From: maboroshin Date: Thu, 20 Sep 2018 10:19:58 +1000 Subject: Backport: Fix highlighting of non-ASCII characters in links. Backport of changeset 7092:a55c26c645f8. --- doc/ScintillaHistory.html | 5 ++++ lexers/LexMarkdown.cxx | 60 +++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 9f94a1744..0a50bfd6a 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -525,6 +525,8 @@ Andreas Rönnquist Henrik Hank Luke Rasmussen + + maboroshin

@@ -557,6 +559,9 @@ Feature #1144.

  • + Markdown lexer fixes highlighting of non-ASCII characters in links. +
  • +
  • Fix margin cursor on Cocoa to point more accurately.
  • diff --git a/lexers/LexMarkdown.cxx b/lexers/LexMarkdown.cxx index 0dc3e374a..e3410f6ca 100644 --- a/lexers/LexMarkdown.cxx +++ b/lexers/LexMarkdown.cxx @@ -145,6 +145,7 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int WordList **, Accessor &styler) { Sci_PositionU endPos = startPos + length; int precharCount = 0; + bool isLinkNameDetecting = false; // Don't advance on a new loop iteration and retry at the same position. // Useful in the corner case of having to start at the beginning file position // in the default state. @@ -337,6 +338,27 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int ++precharCount; } + // Any link + if (sc.state == SCE_MARKDOWN_LINK) { + if (sc.Match("](") && sc.GetRelative(-1) != '\\') { + sc.Forward(2); + isLinkNameDetecting = true; + } + else if (sc.Match("]:") && sc.GetRelative(-1) != '\\') { + sc.Forward(2); + sc.SetState(SCE_MARKDOWN_DEFAULT); + } + else if (!isLinkNameDetecting && sc.ch == ']' && sc.GetRelative(-1) != '\\') { + sc.Forward(); + sc.SetState(SCE_MARKDOWN_DEFAULT); + } + else if (isLinkNameDetecting && sc.ch == ')' && sc.GetRelative(-1) != '\\') { + sc.Forward(); + sc.SetState(SCE_MARKDOWN_DEFAULT); + isLinkNameDetecting = false; + } + } + // New state anywhere in doc if (sc.state == SCE_MARKDOWN_DEFAULT) { if (sc.atLineStart && sc.ch == '#') { @@ -344,38 +366,16 @@ static void ColorizeMarkdownDoc(Sci_PositionU startPos, Sci_Position length, int freezeCursor = true; } // Links and Images - if (sc.Match("![") || sc.ch == '[') { - Sci_Position i = 0, j = 0, k = 0; - Sci_Position len = endPos - sc.currentPos; - while (i < len && (sc.GetRelative(++i) != ']' || sc.GetRelative(i - 1) == '\\')) - ; - if (sc.GetRelative(i) == ']') { - j = i; - if (sc.GetRelative(++i) == '(') { - while (i < len && (sc.GetRelative(++i) != ')' || sc.GetRelative(i - 1) == '\\')) - ; - if (sc.GetRelative(i) == ')') - k = i; - } - else if (sc.GetRelative(i) == '[' || sc.GetRelative(++i) == '[') { - while (i < len && (sc.GetRelative(++i) != ']' || sc.GetRelative(i - 1) == '\\')) - ; - if (sc.GetRelative(i) == ']') - k = i; - } - } - // At least a link text - if (j) { - sc.SetState(SCE_MARKDOWN_LINK); - sc.Forward(j); - // Also has a URL or reference portion - if (k) - sc.Forward(k - j); - sc.ForwardSetState(SCE_MARKDOWN_DEFAULT); - } + if (sc.Match("![")) { + sc.SetState(SCE_MARKDOWN_LINK); + sc.Forward(2); + } + else if (sc.ch == '[' && sc.GetRelative(-1) != '\\') { + sc.SetState(SCE_MARKDOWN_LINK); + sc.Forward(); } // Code - also a special case for alternate inside spacing - if (sc.Match("``") && sc.GetRelative(3) != ' ' && AtTermStart(sc)) { + else if (sc.Match("``") && sc.GetRelative(3) != ' ' && AtTermStart(sc)) { sc.SetState(SCE_MARKDOWN_CODE2); sc.Forward(); } -- cgit v1.2.3