modules/markup: Lift out the GitHub callout transformer

This lifts out the GitHub callout transformer from
`modules/markup/markdown/goldmark.go` to `callout/github.go`.

While there, clean up the transformer code:

- Use a map to look up supported callout types, rather than a regexp.
- Allow the callout type to be in any case, rather than just uppercase.
- Simplified `.Segment.Value()` to `.Text()`.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-02-17 17:36:07 +01:00
parent 0b3193bbbe
commit a177a5c4cb
No known key found for this signature in database
5 changed files with 183 additions and 112 deletions

View file

@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/common"
"code.gitea.io/gitea/modules/markup/markdown/callout"
"code.gitea.io/gitea/modules/markup/markdown/math"
"code.gitea.io/gitea/modules/setting"
giteautil "code.gitea.io/gitea/modules/util"
@ -124,6 +125,7 @@ func SpecializedMarkdown() goldmark.Markdown {
parser.WithAttribute(),
parser.WithAutoHeadingID(),
parser.WithASTTransformers(
util.Prioritized(&callout.GitHubCalloutTransformer{}, 9000),
util.Prioritized(&ASTTransformer{}, 10000),
),
),
@ -135,6 +137,7 @@ func SpecializedMarkdown() goldmark.Markdown {
// Override the original Tasklist renderer!
specMarkdown.Renderer().AddOptions(
renderer.WithNodeRenderers(
util.Prioritized(callout.NewGitHubCalloutHTMLRenderer(), 10),
util.Prioritized(NewHTMLRenderer(), 10),
),
)