mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-23 19:47:07 +09:00
fix(markdown): parse escaped alerts by default (#39633)
Previously, recognition of escaped alert markers such as `\[!NOTE\]` accidentally depended on enabling the optional `inline-parentheses` math setting, resulting in such escaped alerts not rendering properly. Goldmark splits the escaped marker differently based on the setting being enabled or disabled, and only one form was handled. This commit handles both forms. For example, in a README or issue: ``` > \[!NOTE\] > text ``` Before this commit, we'd get an ordinary blockquote displaying literal `[!NOTE]` followed by `text`. With this commit, we get the styled admonition. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
8a553332f7
commit
ab9bcd6a79
3 files changed
+20
-9
No files matched your search
@@ -62,7 +62,7 @@ func (g *ASTTransformer) extractBlockquoteAttention2(firstParagraph ast.Node, re
|
||||
return "", nil
|
||||
}
|
||||
node1, ok := firstParagraph.FirstChild().(*ast.Text)
|
||||
if !ok {
|
||||
if !ok || node1.SoftLineBreak() || node1.HardLineBreak() {
|
||||
return "", nil
|
||||
}
|
||||
node2, ok := node1.NextSibling().(*ast.Text)
|
||||
@@ -71,8 +71,9 @@ func (g *ASTTransformer) extractBlockquoteAttention2(firstParagraph ast.Node, re
|
||||
}
|
||||
val1 := string(node1.Segment.Value(reader.Source()))
|
||||
val2 := string(node2.Segment.Value(reader.Source()))
|
||||
if strings.HasPrefix(val1, `\[!`) && val2 == `\]` {
|
||||
attentionType := strings.ToLower(val1[3:])
|
||||
// Inline math options change where Goldmark splits the escaped marker.
|
||||
if inner, ok := strings.CutPrefix(val1+val2, `\[!`); ok && strings.HasSuffix(val2, `\]`) {
|
||||
attentionType := strings.ToLower(strings.TrimSuffix(inner, `\]`))
|
||||
if g.attentionTypes.Contains(attentionType) {
|
||||
return attentionType, []ast.Node{node1, node2}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user