use AutoLink rule to all links except ac: namespace

This commit is contained in:
Egor Kovetskiy 2021-11-11 14:45:08 +06:00
parent 07926611cf
commit f0e00468e9
3 changed files with 10 additions and 3 deletions

View File

@ -5,9 +5,9 @@ import (
"regexp"
"strings"
bf "github.com/kovetskiy/blackfriday/v2"
"github.com/kovetskiy/mark/pkg/mark/stdlib"
"github.com/reconquest/pkg/log"
bf "github.com/kovetskiy/blackfriday/v2"
)
type ConfluenceRenderer struct {
@ -78,7 +78,8 @@ func (renderer ConfluenceRenderer) RenderNode(
// compileMarkdown will replace tags like <ac:rich-tech-body> with escaped
// equivalent, because bf markdown parser replaces that tags with
// <a href="ac:rich-text-body">ac:rich-text-body</a> for whatever reason.
// <a href="ac:rich-text-body">ac:rich-text-body</a> because of the autolink
// rule.
func CompileMarkdown(
markdown []byte,
stdlib *stdlib.Lib,
@ -87,7 +88,7 @@ func CompileMarkdown(
colon := regexp.MustCompile(`---bf-COLON---`)
tags := regexp.MustCompile(`<(/?\S+?):(\S+?)>`)
tags := regexp.MustCompile(`<(/?ac):(\S+?)>`)
markdown = tags.ReplaceAll(
markdown,

3
pkg/mark/testdata/links.html vendored Normal file
View File

@ -0,0 +1,3 @@
<p>Use <a href="https://example.com">https://example.com</a></p>
<p>Use <ac:rich-text-body>aaa</ac:rich-text-body></p>

3
pkg/mark/testdata/links.md vendored Normal file
View File

@ -0,0 +1,3 @@
Use <https://example.com>
Use <ac:rich-text-body>aaa</ac:rich-text-body>