Skip to content

Commit c20436c

Browse files
enable link brackets escaper
1 parent 03131f3 commit c20436c

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

escape/escape.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var orderedList = regexp.MustCompile(`(?m)^(\W* {0,3})(\d+)\. `)
1313
var unorderedList = regexp.MustCompile(`(?m)^([^\\\w]*)[*+-] `)
1414
var horizontalDivider = regexp.MustCompile(`(?m)^([-*_] *){3,}$`)
1515
var blockquote = regexp.MustCompile(`(?m)^(\W* {0,3})> `)
16+
var link = regexp.MustCompile(`([\[\]])`)
1617

1718
var replacer = strings.NewReplacer(
1819
`*`, `\*`,
@@ -57,10 +58,8 @@ func MarkdownCharacters(text string) string {
5758
// Escape code _
5859
text = replacer.Replace(text)
5960

60-
// Escape link brackets
61-
// (disabled)
62-
// var link = regexp.MustCompile(`[\[\]]`)
63-
// text = link.ReplaceAllString(text, `\$&`)
61+
// Escape link & image brackets
62+
text = link.ReplaceAllString(text, `\$1`)
6463

6564
return text
6665
}

testdata/TestCommonmark/p_tag/output.default.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Some Text
66

77
Some Content
88

9-
jmap –histo[:live]
9+
jmap –histo\[:live\]
1010

1111
Sometimes a struct field, function, type, or even a whole package becomes
1212

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<p>first [literal] brackets</p>
22
<p>then [one] way to escape</p>
33
<p>then [another] one</p>
4+
<p>jmap –histo[:live]</p>
5+
<p>[this should be escaped](http://test)</p>
6+
<p>before: [this should be escaped](http://test) after</p>
7+
<p>image ![alt](/img.png)</p>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
<p>first [literal] brackets</p>
22
<p>then &#91;one&#93; way to escape</p>
33
<p>then &lbrack;another&rbrack; one</p>
4+
5+
<p>jmap –histo[:live]</p>
6+
7+
<p>[this should be escaped](http://test)</p>
8+
<p>before: [this should be escaped](http://test) after</p>
9+
<p>image ![alt](/img.png)</p>
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
first [literal] brackets
1+
first \[literal\] brackets
22

3-
then [one] way to escape
3+
then \[one\] way to escape
44

5-
then [another] one
5+
then \[another\] one
6+
7+
jmap –histo\[:live\]
8+
9+
\[this should be escaped\](http://test)
10+
11+
before: \[this should be escaped\](http://test) after
12+
13+
image !\[alt\](/img.png)

0 commit comments

Comments
 (0)