Skip to content

Commit 46c3f3b

Browse files
committed
fix
1 parent 6ead30d commit 46c3f3b

File tree

4 files changed

+24
-38
lines changed

4 files changed

+24
-38
lines changed

modules/markup/markdown/ast.go

-7
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ func NewColorPreview(color []byte) *ColorPreview {
175175
}
176176
}
177177

178-
// IsColorPreview returns true if the given node implements the ColorPreview interface,
179-
// otherwise false.
180-
func IsColorPreview(node ast.Node) bool {
181-
_, ok := node.(*ColorPreview)
182-
return ok
183-
}
184-
185178
// Attention is an inline for an attention
186179
type Attention struct {
187180
ast.BaseInline

modules/markup/markdown/goldmark.go

+9-15
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
216216
attentionType := strings.ToLower(strings.TrimPrefix(string(secondTextNode.Segment.Value(reader.Source())), "!"))
217217

218218
// color the blockquote
219-
v.SetAttributeString("class", []byte("gt-py-3 attention attention-"+attentionType))
219+
v.SetAttributeString("class", []byte("attention-header attention-"+attentionType))
220220

221221
// create an emphasis to make it bold
222222
attentionParagraph := ast.NewParagraph()
@@ -364,27 +364,21 @@ func (r *HTMLRenderer) renderCodeSpan(w util.BufWriter, source []byte, n ast.Nod
364364
// renderAttention renders a quote marked with i.e. "> **Note**" or "> **Warning**" with a corresponding svg
365365
func (r *HTMLRenderer) renderAttention(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
366366
if entering {
367-
_, _ = w.WriteString(`<span class="gt-mr-2 gt-vm attention-`)
368367
n := node.(*Attention)
369-
_, _ = w.WriteString(strings.ToLower(n.AttentionType))
370-
_, _ = w.WriteString(`">`)
371-
372-
var octiconType string
368+
var octiconName string
373369
switch n.AttentionType {
374-
case "note":
375-
octiconType = "info"
376370
case "tip":
377-
octiconType = "light-bulb"
371+
octiconName = "light-bulb"
378372
case "important":
379-
octiconType = "report"
373+
octiconName = "report"
380374
case "warning":
381-
octiconType = "alert"
375+
octiconName = "alert"
382376
case "caution":
383-
octiconType = "stop"
377+
octiconName = "stop"
378+
default: // including "note"
379+
octiconName = "info"
384380
}
385-
_, _ = w.WriteString(string(svg.RenderHTML("octicon-" + octiconType)))
386-
} else {
387-
_, _ = w.WriteString("</span>\n")
381+
_, _ = w.WriteString(string(svg.RenderHTML("octicon-"+octiconName, 16, "attention-icon attention-"+n.AttentionType)))
388382
}
389383
return ast.WalkContinue, nil
390384
}

modules/markup/sanitizer.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ func createDefaultPolicy() *bluemonday.Policy {
6464
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^color-preview$`)).OnElements("span")
6565

6666
// For attention
67-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^gt-py-3 attention attention-\w+$`)).OnElements("blockquote")
67+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^attention-header attention-\w+$`)).OnElements("blockquote")
6868
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^attention-\w+$`)).OnElements("strong")
69-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^gt-mr-2 gt-vm attention-\w+$`)).OnElements("span", "strong")
70-
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^svg octicon-(\w|-)+$`)).OnElements("svg")
69+
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^attention-icon attention-\w+ svg octicon-[\w-]+$`)).OnElements("svg")
7170
policy.AllowAttrs("viewBox", "width", "height", "aria-hidden").OnElements("svg")
7271
policy.AllowAttrs("fill-rule", "d").OnElements("path")
7372

@@ -105,18 +104,12 @@ func createDefaultPolicy() *bluemonday.Policy {
105104
// Allow icons
106105
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^icon(\s+[\p{L}\p{N}_-]+)+$`)).OnElements("i")
107106

108-
// Allow unlabelled labels
109-
policy.AllowNoAttrs().OnElements("label")
110-
111107
// Allow classes for emojis
112108
policy.AllowAttrs("class").Matching(regexp.MustCompile(`emoji`)).OnElements("img")
113109

114110
// Allow icons, emojis, chroma syntax and keyword markup on span
115111
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji)|(language-math display)|(language-math inline))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$`)).OnElements("span")
116112

117-
// Allow 'style' attribute on text elements.
118-
policy.AllowAttrs("style").OnElements("span", "p")
119-
120113
// Allow 'color' and 'background-color' properties for the style attribute on text elements.
121114
policy.AllowStyles("color", "background-color").OnElements("span", "p")
122115

@@ -144,7 +137,7 @@ func createDefaultPolicy() *bluemonday.Policy {
144137

145138
generalSafeElements := []string{
146139
"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", "br", "b", "i", "strong", "em", "a", "pre", "code", "img", "tt",
147-
"div", "ins", "del", "sup", "sub", "p", "ol", "ul", "table", "thead", "tbody", "tfoot", "blockquote",
140+
"div", "ins", "del", "sup", "sub", "p", "ol", "ul", "table", "thead", "tbody", "tfoot", "blockquote", "label",
148141
"dl", "dt", "dd", "kbd", "q", "samp", "var", "hr", "ruby", "rt", "rp", "li", "tr", "td", "th", "s", "strike", "summary",
149142
"details", "caption", "figure", "figcaption",
150143
"abbr", "bdo", "cite", "dfn", "mark", "small", "span", "time", "video", "wbr",

web_src/css/base.css

+12-6
Original file line numberDiff line numberDiff line change
@@ -1279,42 +1279,48 @@ input:-webkit-autofill:active,
12791279
border-radius: var(--border-radius);
12801280
}
12811281

1282-
.attention {
1282+
.attention-header {
1283+
padding: 0.5em 0.75em !important;
12831284
color: var(--color-text) !important;
12841285
}
12851286

1287+
.attention-icon {
1288+
vertical-align: middle;
1289+
margin-right: 0.25em;
1290+
}
1291+
12861292
blockquote.attention-note {
12871293
border-left-color: var(--color-blue-dark-1);
12881294
}
1289-
strong.attention-note, span.attention-note {
1295+
strong.attention-note, svg.attention-note {
12901296
color: var(--color-blue-dark-1);
12911297
}
12921298

12931299
blockquote.attention-tip {
12941300
border-left-color: var(--color-success-text);
12951301
}
1296-
strong.attention-tip, span.attention-tip {
1302+
strong.attention-tip, svg.attention-tip {
12971303
color: var(--color-success-text);
12981304
}
12991305

13001306
blockquote.attention-important {
13011307
border-left-color: var(--color-violet-dark-1);
13021308
}
1303-
strong.attention-important, span.attention-important {
1309+
strong.attention-important, svg.attention-important {
13041310
color: var(--color-violet-dark-1);
13051311
}
13061312

13071313
blockquote.attention-warning {
13081314
border-left-color: var(--color-warning-text);
13091315
}
1310-
strong.attention-warning, span.attention-warning {
1316+
strong.attention-warning, svg.attention-warning {
13111317
color: var(--color-warning-text);
13121318
}
13131319

13141320
blockquote.attention-caution {
13151321
border-left-color: var(--color-red-dark-1);
13161322
}
1317-
strong.attention-caution, span.attention-caution {
1323+
strong.attention-caution, svg.attention-caution {
13181324
color: var(--color-red-dark-1);
13191325
}
13201326

0 commit comments

Comments
 (0)