diff options
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/utils/markdown')
5 files changed, 19 insertions, 18 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/autolink.go b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/autolink.go index 14180836..d06ada66 100644 --- a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/autolink.go +++ b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/autolink.go @@ -14,6 +14,7 @@ import ( var ( DefaultUrlSchemes = []string{"http", "https", "ftp", "mailto", "tel"} + wwwAutoLinkRegex = regexp.MustCompile(`^www\d{0,3}\.`) ) // Given a string with a w at the given position, tries to parse and return a range containing a www link. @@ -30,7 +31,7 @@ func parseWWWAutolink(data string, position int) (Range, bool) { } // Check that this starts with www - if len(data)-position < 4 || !regexp.MustCompile(`^www\d{0,3}\.`).MatchString(data[position:]) { + if len(data)-position < 4 || !wwwAutoLinkRegex.MatchString(data[position:]) { return Range{}, false } @@ -59,9 +60,8 @@ func isAllowedBeforeWWWLink(c byte) bool { switch c { case '*', '_', '~', ')': return true - default: - return false } + return false } // Given a string with a : at the given position, tried to parse and return a range containing a URL scheme @@ -153,9 +153,8 @@ func checkDomain(data string, allowShort bool) int { // this is called from parseWWWAutolink if foundPeriod { return i - } else { - return 0 } + return 0 } // Returns true if the provided link starts with a valid character for a domain name. Equivalent to @@ -251,7 +250,6 @@ func canEndAutolink(c rune) bool { switch c { case '?', '!', '.', ',', ':', '*', '_', '~', '\'', '"': return false - default: - return true } + return true } diff --git a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/blocks.go b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/blocks.go index 44ee178d..607356e0 100644 --- a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/blocks.go +++ b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/blocks.go @@ -37,13 +37,14 @@ type Range struct { End int } -func closeBlocks(blocks []Block, referenceDefinitions *[]*ReferenceDefinition) { +func closeBlocks(blocks []Block, referenceDefinitions []*ReferenceDefinition) []*ReferenceDefinition { for _, block := range blocks { block.Close() if p, ok := block.(*Paragraph); ok && len(p.ReferenceDefinitions) > 0 { - *referenceDefinitions = append(*referenceDefinitions, p.ReferenceDefinitions...) + referenceDefinitions = append(referenceDefinitions, p.ReferenceDefinitions...) } } + return referenceDefinitions } func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefinition) { @@ -78,7 +79,7 @@ func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefiniti for i := lastMatchIndex; i >= 0; i-- { if container, ok := openBlocks[i].(ContainerBlock); ok { if addedBlocks := container.AddChild(newBlocks); addedBlocks != nil { - closeBlocks(openBlocks[i+1:], &referenceDefinitions) + referenceDefinitions = closeBlocks(openBlocks[i+1:], referenceDefinitions) openBlocks = openBlocks[:i+1] openBlocks = append(openBlocks, addedBlocks...) didAdd = true @@ -98,7 +99,7 @@ func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefiniti continue } - closeBlocks(openBlocks[lastMatchIndex+1:], &referenceDefinitions) + referenceDefinitions = closeBlocks(openBlocks[lastMatchIndex+1:], referenceDefinitions) openBlocks = openBlocks[:lastMatchIndex+1] if openBlocks[lastMatchIndex].AddLine(indentation, r) { @@ -109,7 +110,7 @@ func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefiniti for i := lastMatchIndex; i >= 0; i-- { if container, ok := openBlocks[i].(ContainerBlock); ok { if newBlocks := container.AddChild([]Block{paragraph}); newBlocks != nil { - closeBlocks(openBlocks[i+1:], &referenceDefinitions) + referenceDefinitions = closeBlocks(openBlocks[i+1:], referenceDefinitions) openBlocks = openBlocks[:i+1] openBlocks = append(openBlocks, newBlocks...) break @@ -119,7 +120,7 @@ func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefiniti } } - closeBlocks(openBlocks, &referenceDefinitions) + referenceDefinitions = closeBlocks(openBlocks, referenceDefinitions) return document, referenceDefinitions } diff --git a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/inlines.go b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/inlines.go index 4303607f..a67f2f04 100644 --- a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/inlines.go +++ b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/inlines.go @@ -595,7 +595,7 @@ func ParseInlines(markdown string, ranges []Range, referenceDefinitions []*Refer } func MergeInlineText(inlines []Inline) []Inline { - var ret []Inline + ret := inlines[:0] for i, v := range inlines { // always add first node if i == 0 { diff --git a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/lines.go b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/lines.go index a0a64491..a67ec976 100644 --- a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/lines.go +++ b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/lines.go @@ -3,13 +3,16 @@ package markdown +import "strings" + type Line struct { Range } -func ParseLines(markdown string) (lines []Line) { +func ParseLines(markdown string) []Line { lineStartPosition := 0 isAfterCarriageReturn := false + lines := make([]Line, 0, strings.Count(markdown, "\n")) for position, r := range markdown { if r == '\n' { lines = append(lines, Line{Range{lineStartPosition, position + 1}}) @@ -23,5 +26,5 @@ func ParseLines(markdown string) (lines []Line) { if lineStartPosition < len(markdown) { lines = append(lines, Line{Range{lineStartPosition, len(markdown)}}) } - return + return lines } diff --git a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/markdown.go b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/markdown.go index a9879cee..5ccdad8c 100644 --- a/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/markdown.go +++ b/vendor/github.com/mattermost/mattermost-server/v5/utils/markdown/markdown.go @@ -23,9 +23,8 @@ func isWhitespace(c rune) bool { switch c { case ' ', '\t', '\n', '\u000b', '\u000c', '\r': return true - default: - return false } + return false } func isWhitespaceByte(c byte) bool { |