diff options
Diffstat (limited to 'modules/markup/markdown/transform_blockquote.go')
-rw-r--r-- | modules/markup/markdown/transform_blockquote.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/modules/markup/markdown/transform_blockquote.go b/modules/markup/markdown/transform_blockquote.go index 65b735e83b..933f0e5c59 100644 --- a/modules/markup/markdown/transform_blockquote.go +++ b/modules/markup/markdown/transform_blockquote.go @@ -6,12 +6,37 @@ package markdown import ( "strings" + "code.gitea.io/gitea/modules/svg" + "github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/text" + "github.com/yuin/goldmark/util" "golang.org/x/text/cases" "golang.org/x/text/language" ) +// renderAttention renders a quote marked with i.e. "> **Note**" or "> **Warning**" with a corresponding svg +func (r *HTMLRenderer) renderAttention(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { + if entering { + n := node.(*Attention) + var octiconName string + switch n.AttentionType { + case "tip": + octiconName = "light-bulb" + case "important": + octiconName = "report" + case "warning": + octiconName = "alert" + case "caution": + octiconName = "stop" + default: // including "note" + octiconName = "info" + } + _, _ = w.WriteString(string(svg.RenderHTML("octicon-"+octiconName, 16, "attention-icon attention-"+n.AttentionType))) + } + return ast.WalkContinue, nil +} + func (g *ASTTransformer) transformBlockquote(v *ast.Blockquote, reader text.Reader) (ast.WalkStatus, error) { // We only want attention blockquotes when the AST looks like: // > Text("[") Text("!TYPE") Text("]") @@ -43,7 +68,7 @@ func (g *ASTTransformer) transformBlockquote(v *ast.Blockquote, reader text.Read // grab attention type from markdown source attentionType := strings.ToLower(val2[1:]) - if !g.AttentionTypes.Contains(attentionType) { + if !g.attentionTypes.Contains(attentionType) { return ast.WalkContinue, nil } |