From 238ae29b594cef3071e5e2663effbd7a2bb3561f Mon Sep 17 00:00:00 2001 From: Bernd Ahlers Date: Thu, 30 Mar 2023 14:30:15 +0200 Subject: [PATCH 1/2] Fix "" tag rendering Extend the existing workaround to avoid HTML element escaping to handle more variants. --- pkg/mark/markdown.go | 15 ++++++++------- pkg/mark/testdata/macro-include.html | 6 ++++++ pkg/mark/testdata/macro-include.md | 7 +++++++ 3 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 pkg/mark/testdata/macro-include.html create mode 100644 pkg/mark/testdata/macro-include.md diff --git a/pkg/mark/markdown.go b/pkg/mark/markdown.go index 335166d5..324c74ae 100644 --- a/pkg/mark/markdown.go +++ b/pkg/mark/markdown.go @@ -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(`]+>`) - markdown = tags.ReplaceAll( - markdown, - []byte(`<$1`+colon.String()+`$2>`), - ) + for _, sm := range tags.FindAll(markdown, -1) { + // Replace the colon in all "" tags with the colon bytes to avoid having Goldmark escape the HTML output. + markdown = bytes.ReplaceAll(markdown, sm, bytes.ReplaceAll(sm, []byte(":"), colon)) + } converter := goldmark.New( goldmark.WithExtensions( @@ -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)) diff --git a/pkg/mark/testdata/macro-include.html b/pkg/mark/testdata/macro-include.html new file mode 100644 index 00000000..55f14962 --- /dev/null +++ b/pkg/mark/testdata/macro-include.html @@ -0,0 +1,6 @@ +

bar

+ +true +Attention +This is an info! + \ No newline at end of file diff --git a/pkg/mark/testdata/macro-include.md b/pkg/mark/testdata/macro-include.md new file mode 100644 index 00000000..c8d3d899 --- /dev/null +++ b/pkg/mark/testdata/macro-include.md @@ -0,0 +1,7 @@ +bar + + +true +Attention +This is an info! + \ No newline at end of file From 974de93ef1a48db19662225bd94ccf6a318deef4 Mon Sep 17 00:00:00 2001 From: Bernd Ahlers Date: Thu, 30 Mar 2023 14:34:19 +0200 Subject: [PATCH 2/2] Rename variable --- pkg/mark/markdown.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/mark/markdown.go b/pkg/mark/markdown.go index 324c74ae..2ff2b717 100644 --- a/pkg/mark/markdown.go +++ b/pkg/mark/markdown.go @@ -441,9 +441,9 @@ func CompileMarkdown(markdown []byte, stdlib *stdlib.Lib) string { tags := regexp.MustCompile(`]+>`) - for _, sm := range tags.FindAll(markdown, -1) { + for _, match := range tags.FindAll(markdown, -1) { // Replace the colon in all "" tags with the colon bytes to avoid having Goldmark escape the HTML output. - markdown = bytes.ReplaceAll(markdown, sm, bytes.ReplaceAll(sm, []byte(":"), colon)) + markdown = bytes.ReplaceAll(markdown, match, bytes.ReplaceAll(match, []byte(":"), colon)) } converter := goldmark.New(