diff options
author | maboroshin <unknown> | 2018-09-20 10:19:58 +1000 |
---|---|---|
committer | maboroshin <unknown> | 2018-09-20 10:19:58 +1000 |
commit | 756607afb6cd74445c220ac1d96776a35a4d537f (patch) | |
tree | 67be24ec83792e304081c167e8fceed54a401eed | |
parent | fd4b343d83d1adaf2ca966e941c6c422c50b8666 (diff) | |
download | scintilla-mirror-756607afb6cd74445c220ac1d96776a35a4d537f.tar.gz |
Fix highlighting of non-ASCII characters in links.
-rw-r--r-- | doc/ScintillaHistory.html | 5 | ||||
-rw-r--r-- | lexers/LexMarkdown.cxx | 60 |
2 files changed, 35 insertions, 30 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index e9b4fda29..97ea20408 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -533,6 +533,8 @@ <td>Andreas Rönnquist</td> <td>Henrik Hank</td> <td>Luke Rasmussen</td> + </tr><tr> + <td>maboroshin</td> </tr> </table> <p> @@ -551,6 +553,9 @@ <li> Released 9 September 2018. </li> + <li> + Markdown lexer fixes highlighting of non-ASCII characters in links. + </li> </ul> <h3> <a href="https://www.scintilla.org/scite411.zip">Release 4.1.1</a> 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(); } |