diff --git a/escape/escape.go b/escape/escape.go index 16bb889..e21ab4b 100644 --- a/escape/escape.go +++ b/escape/escape.go @@ -13,6 +13,7 @@ var orderedList = regexp.MustCompile(`(?m)^(\W* {0,3})(\d+)\. `) var unorderedList = regexp.MustCompile(`(?m)^([^\\\w]*)[*+-] `) var horizontalDivider = regexp.MustCompile(`(?m)^([-*_] *){3,}$`) var blockquote = regexp.MustCompile(`(?m)^(\W* {0,3})> `) +var link = regexp.MustCompile(`([\[\]])`) var replacer = strings.NewReplacer( `*`, `\*`, @@ -57,10 +58,8 @@ func MarkdownCharacters(text string) string { // Escape code _ text = replacer.Replace(text) - // Escape link brackets - // (disabled) - // var link = regexp.MustCompile(`[\[\]]`) - // text = link.ReplaceAllString(text, `\$&`) + // Escape link & image brackets + text = link.ReplaceAllString(text, `\$1`) return text } diff --git a/testdata/TestCommonmark/p_tag/output.default.golden b/testdata/TestCommonmark/p_tag/output.default.golden index e5dadd6..267084d 100644 --- a/testdata/TestCommonmark/p_tag/output.default.golden +++ b/testdata/TestCommonmark/p_tag/output.default.golden @@ -6,7 +6,7 @@ Some Text Some Content -jmap –histo[:live] +jmap –histo\[:live\] Sometimes a struct field, function, type, or even a whole package becomes diff --git a/testdata/TestRealWorld/snippets/square_brackets/goldmark.golden b/testdata/TestRealWorld/snippets/square_brackets/goldmark.golden index bf92531..657f2c6 100644 --- a/testdata/TestRealWorld/snippets/square_brackets/goldmark.golden +++ b/testdata/TestRealWorld/snippets/square_brackets/goldmark.golden @@ -1,3 +1,7 @@
first [literal] brackets
then [one] way to escape
then [another] one
+jmap –histo[:live]
+[this should be escaped](http://test)
+before: [this should be escaped](http://test) after
+image ![alt](/img.png)
diff --git a/testdata/TestRealWorld/snippets/square_brackets/input.html b/testdata/TestRealWorld/snippets/square_brackets/input.html index 128c504..3130161 100644 --- a/testdata/TestRealWorld/snippets/square_brackets/input.html +++ b/testdata/TestRealWorld/snippets/square_brackets/input.html @@ -1,3 +1,9 @@first [literal] brackets
then [one] way to escape
then [another] one
+ +jmap –histo[:live]
+ +[this should be escaped](http://test)
+before: [this should be escaped](http://test) after
+image ![alt](/img.png)
diff --git a/testdata/TestRealWorld/snippets/square_brackets/output.default.golden b/testdata/TestRealWorld/snippets/square_brackets/output.default.golden index 64eb1c2..6567af5 100644 --- a/testdata/TestRealWorld/snippets/square_brackets/output.default.golden +++ b/testdata/TestRealWorld/snippets/square_brackets/output.default.golden @@ -1,5 +1,13 @@ -first [literal] brackets +first \[literal\] brackets -then [one] way to escape +then \[one\] way to escape -then [another] one \ No newline at end of file +then \[another\] one + +jmap –histo\[:live\] + +\[this should be escaped\](http://test) + +before: \[this should be escaped\](http://test) after + +image !\[alt\](/img.png) \ No newline at end of file