forked from forgejo/forgejo
[BUG] Don't color dot literal color names
- Colordots are generated for colors in inline code, such as `red`, `rgb(255, 0, 124)`, `#ffaabb` and `hsl(124, 52%, 50%)`. However this shouldn't be doon for literal color names as these can be too common assiocated with non-color related stuff _and matches the behavior of some other forge_. - Move the regexes from bluemonday to Forgejo and do the checking ourselves. - Adds unit tests. - Resolves https://codeberg.org/Codeberg/Community/issues/1510
This commit is contained in:
parent
053ab13f99
commit
80f22ab0d8
3 changed files with 70 additions and 2 deletions
|
@ -16,7 +16,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/setting"
|
||||
giteautil "code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/microcosm-cc/bluemonday/css"
|
||||
"github.com/yuin/goldmark/ast"
|
||||
east "github.com/yuin/goldmark/extension/ast"
|
||||
"github.com/yuin/goldmark/parser"
|
||||
|
@ -199,7 +198,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
|
|||
}
|
||||
case *ast.CodeSpan:
|
||||
colorContent := n.Text(reader.Source())
|
||||
if css.ColorHandler(strings.ToLower(string(colorContent))) {
|
||||
if matchColor(strings.ToLower(string(colorContent))) {
|
||||
v.AppendChild(v, NewColorPreview(colorContent))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue