Skip to content

Commit

Permalink
enable link brackets escaper
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKaufmann committed Jan 14, 2022
1 parent 03131f3 commit c20436c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
7 changes: 3 additions & 4 deletions escape/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`*`, `\*`,
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion testdata/TestCommonmark/p_tag/output.default.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<p>first [literal] brackets</p>
<p>then [one] way to escape</p>
<p>then [another] one</p>
<p>jmap –histo[:live]</p>
<p>[this should be escaped](http://test)</p>
<p>before: [this should be escaped](http://test) after</p>
<p>image ![alt](/img.png)</p>
6 changes: 6 additions & 0 deletions testdata/TestRealWorld/snippets/square_brackets/input.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<p>first [literal] brackets</p>
<p>then &#91;one&#93; way to escape</p>
<p>then &lbrack;another&rbrack; one</p>

<p>jmap –histo[:live]</p>

<p>[this should be escaped](http://test)</p>
<p>before: [this should be escaped](http://test) after</p>
<p>image ![alt](/img.png)</p>
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
first [literal] brackets
first \[literal\] brackets

then [one] way to escape
then \[one\] way to escape

then [another] one
then \[another\] one

jmap –histo\[:live\]

\[this should be escaped\](http://test)

before: \[this should be escaped\](http://test) after

image !\[alt\](/img.png)

0 comments on commit c20436c

Please sign in to comment.