diff options
author | Wim <wim@42.be> | 2022-06-11 23:07:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-11 23:07:42 +0200 |
commit | 8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d (patch) | |
tree | 601d2616b05b5b197bd2a3ae7cb245b1a0ea17e7 /vendor/github.com/gomarkdown/markdown/html | |
parent | 3819062574ac7e4af6a562bf40a425469a7752fb (diff) | |
download | matterbridge-msglm-8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d.tar.gz matterbridge-msglm-8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d.tar.bz2 matterbridge-msglm-8751fb4bb1eb7cd34ed63be9b3801b8aeac71a1d.zip |
Update dependencies (#1841)
Diffstat (limited to 'vendor/github.com/gomarkdown/markdown/html')
-rw-r--r-- | vendor/github.com/gomarkdown/markdown/html/renderer.go | 90 |
1 files changed, 3 insertions, 87 deletions
diff --git a/vendor/github.com/gomarkdown/markdown/html/renderer.go b/vendor/github.com/gomarkdown/markdown/html/renderer.go index 68868573..42b39f30 100644 --- a/vendor/github.com/gomarkdown/markdown/html/renderer.go +++ b/vendor/github.com/gomarkdown/markdown/html/renderer.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/gomarkdown/markdown/ast" + "github.com/gomarkdown/markdown/internal/valid" "github.com/gomarkdown/markdown/parser" ) @@ -211,70 +212,6 @@ func NewRenderer(opts RendererOptions) *Renderer { } } -func isHTMLTag(tag []byte, tagname string) bool { - found, _ := findHTMLTagPos(tag, tagname) - return found -} - -// Look for a character, but ignore it when it's in any kind of quotes, it -// might be JavaScript -func skipUntilCharIgnoreQuotes(html []byte, start int, char byte) int { - inSingleQuote := false - inDoubleQuote := false - inGraveQuote := false - i := start - for i < len(html) { - switch { - case html[i] == char && !inSingleQuote && !inDoubleQuote && !inGraveQuote: - return i - case html[i] == '\'': - inSingleQuote = !inSingleQuote - case html[i] == '"': - inDoubleQuote = !inDoubleQuote - case html[i] == '`': - inGraveQuote = !inGraveQuote - } - i++ - } - return start -} - -func findHTMLTagPos(tag []byte, tagname string) (bool, int) { - i := 0 - if i < len(tag) && tag[0] != '<' { - return false, -1 - } - i++ - i = skipSpace(tag, i) - - if i < len(tag) && tag[i] == '/' { - i++ - } - - i = skipSpace(tag, i) - j := 0 - for ; i < len(tag); i, j = i+1, j+1 { - if j >= len(tagname) { - break - } - - if strings.ToLower(string(tag[i]))[0] != tagname[j] { - return false, -1 - } - } - - if i == len(tag) { - return false, -1 - } - - rightAngle := skipUntilCharIgnoreQuotes(tag, i, '>') - if rightAngle >= i { - return true, rightAngle - } - - return false, -1 -} - func isRelativeLink(link []byte) (yes bool) { // a tag begin with '#' if link[0] == '#' { @@ -351,14 +288,6 @@ func needSkipLink(flags Flags, dest []byte) bool { return flags&Safelink != 0 && !isSafeLink(dest) && !isMailto(dest) } -func isSmartypantable(node ast.Node) bool { - switch node.GetParent().(type) { - case *ast.Link, *ast.CodeBlock, *ast.Code: - return false - } - return true -} - func appendLanguageAttr(attrs []string, info []byte) []string { if len(info) == 0 { return attrs @@ -1297,21 +1226,8 @@ func isListItemTerm(node ast.Node) bool { return ok && data.ListFlags&ast.ListTypeTerm != 0 } -// TODO: move to internal package -func skipSpace(data []byte, i int) int { - n := len(data) - for i < n && isSpace(data[i]) { - i++ - } - return i -} - -// TODO: move to internal package -var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://")} -var validPaths = [][]byte{[]byte("/"), []byte("./"), []byte("../")} - func isSafeLink(link []byte) bool { - for _, path := range validPaths { + for _, path := range valid.Paths { if len(link) >= len(path) && bytes.Equal(link[:len(path)], path) { if len(link) == len(path) { return true @@ -1321,7 +1237,7 @@ func isSafeLink(link []byte) bool { } } - for _, prefix := range validUris { + for _, prefix := range valid.URIs { // TODO: handle unicode here // case-insensitive prefix test if len(link) > len(prefix) && bytes.Equal(bytes.ToLower(link[:len(prefix)]), prefix) && isAlnum(link[len(prefix)]) { |