diff options
author | Chris <ccbrown112@gmail.com> | 2018-01-22 15:32:50 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-22 15:32:50 -0600 |
commit | 599991ea731953f772824ce3ed1e591246aa004f (patch) | |
tree | fca0f556f12e56bdcefa74ac6794dec64e04e3fc /utils/markdown/paragraph.go | |
parent | a8445775351c32f8a12081f60bda2099571b2758 (diff) | |
download | chat-599991ea731953f772824ce3ed1e591246aa004f.tar.gz chat-599991ea731953f772824ce3ed1e591246aa004f.tar.bz2 chat-599991ea731953f772824ce3ed1e591246aa004f.zip |
PLT-3383: image proxy support (#7991)
* image proxy support
* go vet fix, remove mistakenly added coverage file
* fix test compile error
* add validation to config settings and documentation to model functions
* add message_source field to post
Diffstat (limited to 'utils/markdown/paragraph.go')
-rw-r--r-- | utils/markdown/paragraph.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/utils/markdown/paragraph.go b/utils/markdown/paragraph.go new file mode 100644 index 000000000..6a40fdf89 --- /dev/null +++ b/utils/markdown/paragraph.go @@ -0,0 +1,71 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package markdown + +import ( + "strings" +) + +type Paragraph struct { + blockBase + markdown string + + Text []Range + ReferenceDefinitions []*ReferenceDefinition +} + +func (b *Paragraph) ParseInlines(referenceDefinitions []*ReferenceDefinition) []Inline { + return ParseInlines(b.markdown, b.Text, referenceDefinitions) +} + +func (b *Paragraph) Continuation(indentation int, r Range) *continuation { + s := b.markdown[r.Position:r.End] + if strings.TrimSpace(s) == "" { + return nil + } + return &continuation{ + Indentation: indentation, + Remaining: r, + } +} + +func (b *Paragraph) Close() { + for { + for i := 0; i < len(b.Text); i++ { + b.Text[i] = trimLeftSpace(b.markdown, b.Text[i]) + if b.Text[i].Position < b.Text[i].End { + break + } + } + + if len(b.Text) == 0 || b.Text[0].Position < b.Text[0].End && b.markdown[b.Text[0].Position] != '[' { + break + } + + definition, remaining := parseReferenceDefinition(b.markdown, b.Text) + if definition == nil { + break + } + b.ReferenceDefinitions = append(b.ReferenceDefinitions, definition) + b.Text = remaining + } + + for i := len(b.Text) - 1; i >= 0; i-- { + b.Text[i] = trimRightSpace(b.markdown, b.Text[i]) + if b.Text[i].Position < b.Text[i].End { + break + } + } +} + +func newParagraph(markdown string, r Range) *Paragraph { + s := markdown[r.Position:r.End] + if strings.TrimSpace(s) == "" { + return nil + } + return &Paragraph{ + markdown: markdown, + Text: []Range{r}, + } +} |