github.com/ashishbhate/mattermost-server@v5.11.1+incompatible/utils/markdown/paragraph.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package markdown 5 6 import ( 7 "strings" 8 ) 9 10 type Paragraph struct { 11 blockBase 12 markdown string 13 14 Text []Range 15 ReferenceDefinitions []*ReferenceDefinition 16 } 17 18 func (b *Paragraph) ParseInlines(referenceDefinitions []*ReferenceDefinition) []Inline { 19 return ParseInlines(b.markdown, b.Text, referenceDefinitions) 20 } 21 22 func (b *Paragraph) Continuation(indentation int, r Range) *continuation { 23 s := b.markdown[r.Position:r.End] 24 if strings.TrimSpace(s) == "" { 25 return nil 26 } 27 return &continuation{ 28 Indentation: indentation, 29 Remaining: r, 30 } 31 } 32 33 func (b *Paragraph) Close() { 34 for { 35 for i := 0; i < len(b.Text); i++ { 36 b.Text[i] = trimLeftSpace(b.markdown, b.Text[i]) 37 if b.Text[i].Position < b.Text[i].End { 38 break 39 } 40 } 41 42 if len(b.Text) == 0 || b.Text[0].Position < b.Text[0].End && b.markdown[b.Text[0].Position] != '[' { 43 break 44 } 45 46 definition, remaining := parseReferenceDefinition(b.markdown, b.Text) 47 if definition == nil { 48 break 49 } 50 b.ReferenceDefinitions = append(b.ReferenceDefinitions, definition) 51 b.Text = remaining 52 } 53 54 for i := len(b.Text) - 1; i >= 0; i-- { 55 b.Text[i] = trimRightSpace(b.markdown, b.Text[i]) 56 if b.Text[i].Position < b.Text[i].End { 57 break 58 } 59 } 60 } 61 62 func newParagraph(markdown string, r Range) *Paragraph { 63 s := markdown[r.Position:r.End] 64 if strings.TrimSpace(s) == "" { 65 return nil 66 } 67 return &Paragraph{ 68 markdown: markdown, 69 Text: []Range{r}, 70 } 71 }