@@ -14,6 +14,7 @@ import (
14
14
"code.gitea.io/gitea/modules/markup"
15
15
"code.gitea.io/gitea/modules/markup/common"
16
16
"code.gitea.io/gitea/modules/setting"
17
+ "code.gitea.io/gitea/modules/svg"
17
18
giteautil "code.gitea.io/gitea/modules/util"
18
19
19
20
"github.com/microcosm-cc/bluemonday/css"
@@ -46,6 +47,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
46
47
ctx .TableOfContents = make ([]markup.Header , 0 , 100 )
47
48
}
48
49
50
+ attentionMarkedBlockquotes := make (container.Set [* ast.Blockquote ])
49
51
_ = ast .Walk (node , func (n ast.Node , entering bool ) (ast.WalkStatus , error ) {
50
52
if ! entering {
51
53
return ast .WalkContinue , nil
@@ -184,6 +186,18 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
184
186
if css .ColorHandler (strings .ToLower (string (colorContent ))) {
185
187
v .AppendChild (v , NewColorPreview (colorContent ))
186
188
}
189
+ case * ast.Emphasis :
190
+ // check if inside blockquote for attention, expected hierarchy is
191
+ // Emphasis < Paragraph < Blockquote
192
+ blockquote , isInBlockquote := n .Parent ().Parent ().(* ast.Blockquote )
193
+ if isInBlockquote && ! attentionMarkedBlockquotes .Contains (blockquote ) {
194
+ fullText := string (n .Text (reader .Source ()))
195
+ if fullText == AttentionNote || fullText == AttentionWarning {
196
+ v .SetAttributeString ("class" , []byte ("attention-" + strings .ToLower (fullText )))
197
+ v .Parent ().InsertBefore (v .Parent (), v , NewAttention (fullText ))
198
+ attentionMarkedBlockquotes .Add (blockquote )
199
+ }
200
+ }
187
201
}
188
202
return ast .WalkContinue , nil
189
203
})
@@ -273,6 +287,7 @@ func (r *HTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
273
287
reg .Register (KindSummary , r .renderSummary )
274
288
reg .Register (KindIcon , r .renderIcon )
275
289
reg .Register (ast .KindCodeSpan , r .renderCodeSpan )
290
+ reg .Register (KindAttention , r .renderAttention )
276
291
reg .Register (KindTaskCheckBoxListItem , r .renderTaskCheckBoxListItem )
277
292
reg .Register (east .KindTaskCheckBox , r .renderTaskCheckBox )
278
293
}
@@ -309,6 +324,28 @@ func (r *HTMLRenderer) renderCodeSpan(w util.BufWriter, source []byte, n ast.Nod
309
324
return ast .WalkContinue , nil
310
325
}
311
326
327
+ // renderAttention renders a quote marked with i.e. "> **Note**" or "> **Warning**" with a corresponding svg
328
+ func (r * HTMLRenderer ) renderAttention (w util.BufWriter , source []byte , node ast.Node , entering bool ) (ast.WalkStatus , error ) {
329
+ if entering {
330
+ _ , _ = w .WriteString (`<span class="attention-icon attention-` )
331
+ n := node .(* Attention )
332
+ _ , _ = w .WriteString (strings .ToLower (n .AttentionType ))
333
+ _ , _ = w .WriteString (`">` )
334
+
335
+ var octiconType string
336
+ switch n .AttentionType {
337
+ case AttentionNote :
338
+ octiconType = "info"
339
+ case AttentionWarning :
340
+ octiconType = "alert"
341
+ }
342
+ _ , _ = w .WriteString (string (svg .RenderHTML ("octicon-" + octiconType )))
343
+ } else {
344
+ _ , _ = w .WriteString ("</span>\n " )
345
+ }
346
+ return ast .WalkContinue , nil
347
+ }
348
+
312
349
func (r * HTMLRenderer ) renderDocument (w util.BufWriter , source []byte , node ast.Node , entering bool ) (ast.WalkStatus , error ) {
313
350
n := node .(* ast.Document )
314
351
0 commit comments