1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-01-26 03:20:10 +02:00

Remove whitespace tokenizing rule in markdown lexer (#1008)

fix #744 
related issue: go-gitea/gitea#32136

current markdown lexer is tokenizing by whitespace, but in markdown
sytanx this implementation can cause some errors.
This commit is contained in:
cloudchamb3r 2024-11-14 17:45:38 +09:00 committed by GitHub
parent 6622bd571f
commit 539d031254
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 2 deletions

View File

@ -40,7 +40,6 @@ func markdownRules() Rules {
{"`[^`]+`", LiteralStringBacktick, nil},
{`[@#][\w/:]+`, NameEntity, nil},
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
{`[^\\\s]+`, Other, nil},
{`.|\n`, Other, nil},
},
}

View File

@ -85,3 +85,9 @@ end loop;
end
$$;
```
## MarkdownLink Test
[normal link](https://google.com)
[whitespace before link](https://google.com)
abc[non-whitespace before link](https://google.com)
([first link](https://google.com) and [second link](https://google.com))

View File

@ -441,5 +441,27 @@
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n"},
{"type":"LiteralString","value":"```"},
{"type":"Text","value":"\n"}
{"type":"Text","value":"\n\n"},
{"type":"GenericSubheading","value":"## MarkdownLink Test\n"},
{"type":"Text","value":"["},
{"type":"NameTag","value":"normal link"},
{"type":"Text","value":"]("},
{"type":"NameAttribute","value":"https://google.com"},
{"type":"Text","value":") \n ["},
{"type":"NameTag","value":"whitespace before link"},
{"type":"Text","value":"]("},
{"type":"NameAttribute","value":"https://google.com"},
{"type":"Text","value":") \nabc["},
{"type":"NameTag","value":"non-whitespace before link"},
{"type":"Text","value":"]("},
{"type":"NameAttribute","value":"https://google.com"},
{"type":"Text","value":") \n(["},
{"type":"NameTag","value":"first link"},
{"type":"Text","value":"]("},
{"type":"NameAttribute","value":"https://google.com"},
{"type":"Text","value":") and ["},
{"type":"NameTag","value":"second link"},
{"type":"Text","value":"]("},
{"type":"NameAttribute","value":"https://google.com"},
{"type":"Text","value":")) \n"}
]