Skip to content

Commit b5c418f

Browse files
Don't use <br /> in alert block (#29650)
- Follows #29121 When I implemented alert blocks I was always testing the markdown in issue comments. I used `<br />` for line breaks and it looked good. I have since learned that the markdown on README files doesn't allow these tags. So a comment with ```md > [!NOTE] > If you're interested in using our APIs, we have experimental support with [documentation](https://try.gitea.io/api/swagger). ``` looked like this in a comment ![image](https://github.com/go-gitea/gitea/assets/20454870/96b1de01-2c87-4d4f-83dd-98192b83e9d0) but looked like this in a README ![image](https://github.com/go-gitea/gitea/assets/20454870/474b636d-dd7a-4b7f-ba27-643803c71aa3) So I changed how we render the alert block by having the alert itself have a dedicated paragraph, so line breaks happen naturally between paragraphs. # Before ![image](https://github.com/go-gitea/gitea/assets/20454870/474b636d-dd7a-4b7f-ba27-643803c71aa3) ![image](https://github.com/go-gitea/gitea/assets/20454870/167a8d37-9a44-4479-9340-5dc80347b595) # After ![image](https://github.com/go-gitea/gitea/assets/20454870/2f99fec0-98ff-4ba8-97fe-b4567041ae79) ![image](https://github.com/go-gitea/gitea/assets/20454870/ffdeae11-fb06-4d00-b497-eae135f0d7ad) --------- Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: silverwind <[email protected]>
1 parent 9dc8a63 commit b5c418f

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

modules/markup/markdown/goldmark.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,18 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
219219
v.SetAttributeString("class", []byte("gt-py-3 attention attention-"+attentionType))
220220

221221
// create an emphasis to make it bold
222+
attentionParagraph := ast.NewParagraph()
222223
emphasis := ast.NewEmphasis(2)
223224
emphasis.SetAttributeString("class", []byte("attention-"+attentionType))
224-
firstParagraph.InsertBefore(firstParagraph, firstTextNode, emphasis)
225225

226226
// capitalize first letter
227227
attentionText := ast.NewString([]byte(strings.ToUpper(string(attentionType[0])) + attentionType[1:]))
228228

229-
// replace the ![TYPE] with icon+Type
229+
// replace the ![TYPE] with a dedicated paragraph of icon+Type
230230
emphasis.AppendChild(emphasis, attentionText)
231-
for i := 0; i < 2; i++ {
232-
lineBreak := ast.NewText()
233-
lineBreak.SetSoftLineBreak(true)
234-
firstParagraph.InsertAfter(firstParagraph, emphasis, lineBreak)
235-
}
236-
firstParagraph.InsertBefore(firstParagraph, emphasis, NewAttention(attentionType))
231+
attentionParagraph.AppendChild(attentionParagraph, NewAttention(attentionType))
232+
attentionParagraph.AppendChild(attentionParagraph, emphasis)
233+
firstParagraph.Parent().InsertBefore(firstParagraph.Parent(), firstParagraph, attentionParagraph)
237234
firstParagraph.RemoveChild(firstParagraph, firstTextNode)
238235
firstParagraph.RemoveChild(firstParagraph, secondTextNode)
239236
firstParagraph.RemoveChild(firstParagraph, thirdTextNode)

0 commit comments

Comments
 (0)