diff --git a/modules/markup/markdown/callout/github.go b/modules/markup/markdown/callout/github.go index 78f1db7e9..0a6ab10ca 100644 --- a/modules/markup/markdown/callout/github.go +++ b/modules/markup/markdown/callout/github.go @@ -68,7 +68,7 @@ func (g *GitHubCalloutTransformer) Transform(node *ast.Document, reader text.Rea } // color the blockquote - v.SetAttributeString("class", []byte("gt-py-3 attention attention-"+attentionType)) + v.SetAttributeString("class", []byte("attention-header attention-"+attentionType)) // create an emphasis to make it bold attentionParagraph := ast.NewParagraph() @@ -104,27 +104,24 @@ func (r *GitHubCalloutHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncR // renderAttention renders a quote marked with i.e. "> **Note**" or "> **Warning**" with a corresponding svg func (r *GitHubCalloutHTMLRenderer) renderAttention(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { if entering { - _, _ = w.WriteString(``) - var octiconType string + var octiconName string switch n.AttentionType { case "note": - octiconType = "info" + octiconName = "info" case "tip": - octiconType = "light-bulb" + octiconName = "light-bulb" case "important": - octiconType = "report" + octiconName = "report" case "warning": - octiconType = "alert" + octiconName = "alert" case "caution": - octiconType = "stop" + octiconName = "stop" + default: + octiconName = "info" } - _, _ = w.WriteString(string(svg.RenderHTML("octicon-" + octiconType))) - } else { - _, _ = w.WriteString("\n") + _, _ = w.WriteString(string(svg.RenderHTML("octicon-"+octiconName, 16, "attention-icon attention-"+n.AttentionType))) } return ast.WalkContinue, nil } diff --git a/modules/markup/markdown/callout/github_legacy.go b/modules/markup/markdown/callout/github_legacy.go index add6b0a84..080cbe625 100644 --- a/modules/markup/markdown/callout/github_legacy.go +++ b/modules/markup/markdown/callout/github_legacy.go @@ -49,7 +49,7 @@ func (g *GitHubLegacyCalloutTransformer) Transform(node *ast.Document, reader te calloutNode.SetAttributeString("class", []byte("attention-"+calloutType)) // color the blockquote - v.SetAttributeString("class", []byte("gt-py-3 attention attention-"+calloutType)) + v.SetAttributeString("class", []byte("attention-header attention-"+calloutType)) // Prepend callout icon before the callout node itself firstParagraph.InsertBefore(firstParagraph, calloutNode, NewAttention(calloutType)) diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go index b94240690..79a2ba0df 100644 --- a/modules/markup/sanitizer.go +++ b/modules/markup/sanitizer.go @@ -64,10 +64,9 @@ func createDefaultPolicy() *bluemonday.Policy { policy.AllowAttrs("class").Matching(regexp.MustCompile(`^color-preview$`)).OnElements("span") // For attention - policy.AllowAttrs("class").Matching(regexp.MustCompile(`^gt-py-3 attention attention-\w+$`)).OnElements("blockquote") + policy.AllowAttrs("class").Matching(regexp.MustCompile(`^attention-header attention-\w+$`)).OnElements("blockquote") policy.AllowAttrs("class").Matching(regexp.MustCompile(`^attention-\w+$`)).OnElements("strong") - policy.AllowAttrs("class").Matching(regexp.MustCompile(`^gt-mr-2 gt-vm attention-\w+$`)).OnElements("span", "strong") - policy.AllowAttrs("class").Matching(regexp.MustCompile(`^svg octicon-(\w|-)+$`)).OnElements("svg") + policy.AllowAttrs("class").Matching(regexp.MustCompile(`^attention-icon attention-\w+ svg octicon-[\w-]+$`)).OnElements("svg") policy.AllowAttrs("viewBox", "width", "height", "aria-hidden").OnElements("svg") policy.AllowAttrs("fill-rule", "d").OnElements("path") diff --git a/tests/integration/markup_test.go b/tests/integration/markup_test.go index b054abdaa..d63190a88 100644 --- a/tests/integration/markup_test.go +++ b/tests/integration/markup_test.go @@ -25,9 +25,9 @@ func TestRenderAlertBlocks(t *testing.T) { assertAlertBlock := func(t *testing.T, input, alertType, alertIcon string) { t.Helper() - blockquoteAttr := fmt.Sprintf(`