Skip to content

Commit

Permalink
Merge pull request #270 from bernd/fix/ac-tag-escaping
Browse files Browse the repository at this point in the history
Fix "<ac:*>" tag rendering
  • Loading branch information
mrueg committed Mar 30, 2023
2 parents 98e15ed + 974de93 commit a60dd52
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/mark/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@ func (r *ConfluenceRenderer) renderCodeBlock(writer util.BufWriter, source []byt
func CompileMarkdown(markdown []byte, stdlib *stdlib.Lib) string {
log.Tracef(nil, "rendering markdown:\n%s", string(markdown))

colon := regexp.MustCompile(`---bf-COLON---`)
colon := []byte("---bf-COLON---")

tags := regexp.MustCompile(`<(/?ac):(\S+?)>`)
tags := regexp.MustCompile(`</?ac:[^>]+>`)

markdown = tags.ReplaceAll(
markdown,
[]byte(`<$1`+colon.String()+`$2>`),
)
for _, match := range tags.FindAll(markdown, -1) {
// Replace the colon in all "<ac:*>" tags with the colon bytes to avoid having Goldmark escape the HTML output.
markdown = bytes.ReplaceAll(markdown, match, bytes.ReplaceAll(match, []byte(":"), colon))
}

converter := goldmark.New(
goldmark.WithExtensions(
Expand Down Expand Up @@ -472,7 +472,8 @@ func CompileMarkdown(markdown []byte, stdlib *stdlib.Lib) string {
panic(err)
}

html := colon.ReplaceAll(buf.Bytes(), []byte(`:`))
// Restore all the colons we previously replaced.
html := bytes.ReplaceAll(buf.Bytes(), colon, []byte(":"))

log.Tracef(nil, "rendered markdown to html:\n%s", string(html))

Expand Down
6 changes: 6 additions & 0 deletions pkg/mark/testdata/macro-include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p><foo>bar</foo></p>
<ac:structured-macro ac:name="info">
<ac:parameter ac:name="icon">true</ac:parameter>
<ac:parameter ac:name="title">Attention</ac:parameter>
<ac:rich-text-body>This is an info!</ac:rich-text-body>
</ac:structured-macro>
7 changes: 7 additions & 0 deletions pkg/mark/testdata/macro-include.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<foo>bar</foo>

<ac:structured-macro ac:name="info">
<ac:parameter ac:name="icon">true</ac:parameter>
<ac:parameter ac:name="title">Attention</ac:parameter>
<ac:rich-text-body>This is an info!</ac:rich-text-body>
</ac:structured-macro>

0 comments on commit a60dd52

Please sign in to comment.