1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00

Make autolinks ignore several characters

This commit is contained in:
bouncepaw 2021-01-31 21:50:44 +05:00
parent b4e866446e
commit 9fbcab210a

View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"html" "html"
"regexp"
"strings" "strings"
"unicode" "unicode"
) )
@ -56,7 +55,8 @@ func getLinkNode(input *bytes.Buffer, hyphaName string, isBracketedLink bool) st
} else if isBracketedLink && b == ']' && bytes.HasPrefix(input.Bytes(), []byte{']'}) { } else if isBracketedLink && b == ']' && bytes.HasPrefix(input.Bytes(), []byte{']'}) {
input.Next(1) input.Next(1)
break break
} else if !isBracketedLink && unicode.IsSpace(rune(b)) { } else if !isBracketedLink && (unicode.IsSpace(rune(b)) || strings.ContainsRune("<>{}|\\^[]`,()", rune(b))) {
input.UnreadByte()
break break
} else { } else {
currBuf.WriteByte(b) currBuf.WriteByte(b)
@ -104,17 +104,6 @@ func getTextNode(input *bytes.Buffer) string {
return textNodeBuffer.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 { func ParagraphToHtml(hyphaName, input string) string {
var ( var (
p = bytes.NewBufferString(input) p = bytes.NewBufferString(input)