diff options
| -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("