From 9fbcab210ab4586fac869d9ecb3391cefeff42a3 Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Sun, 31 Jan 2021 21:50:44 +0500 Subject: [PATCH] Make autolinks ignore several characters --- markup/paragraph.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/markup/paragraph.go b/markup/paragraph.go index 4bef250..a576fee 100644 --- a/markup/paragraph.go +++ b/markup/paragraph.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "html" - "regexp" "strings" "unicode" ) @@ -56,7 +55,8 @@ func getLinkNode(input *bytes.Buffer, hyphaName string, isBracketedLink bool) st } else if isBracketedLink && b == ']' && bytes.HasPrefix(input.Bytes(), []byte{']'}) { input.Next(1) break - } else if !isBracketedLink && unicode.IsSpace(rune(b)) { + } else if !isBracketedLink && (unicode.IsSpace(rune(b)) || strings.ContainsRune("<>{}|\\^[]`,()", rune(b))) { + input.UnreadByte() break } else { currBuf.WriteByte(b) @@ -104,17 +104,6 @@ func getTextNode(input *bytes.Buffer) string { return textNodeBuffer.String() } -var ( - dangerousSymbols = "<>{}|\\^[]`,()" - reLink = regexp.MustCompile(fmt.Sprintf(`[^[]{0,2}((https|http|gemini|gopher)://[^%[1]s]+)|(mailto:[^%[1]s]+)[^]]{0,2}`, dangerousSymbols)) -) - -// TODO: -func doRegexpStuff(input string) string { - reLink.ReplaceAllString(input, "[[$1]]") - return "" -} - func ParagraphToHtml(hyphaName, input string) string { var ( p = bytes.NewBufferString(input)