summaryrefslogtreecommitdiffstats
path: root/vendor/gitlab.com/golang-commonmark/markdown/state_inline.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gitlab.com/golang-commonmark/markdown/state_inline.go')
-rw-r--r--vendor/gitlab.com/golang-commonmark/markdown/state_inline.go116
1 files changed, 116 insertions, 0 deletions
diff --git a/vendor/gitlab.com/golang-commonmark/markdown/state_inline.go b/vendor/gitlab.com/golang-commonmark/markdown/state_inline.go
new file mode 100644
index 00000000..4bc08cf5
--- /dev/null
+++ b/vendor/gitlab.com/golang-commonmark/markdown/state_inline.go
@@ -0,0 +1,116 @@
+// Copyright 2015 The Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package markdown
+
+import (
+ "bytes"
+ "unicode"
+ "unicode/utf8"
+)
+
+type StateInline struct {
+ StateCore
+
+ Pos int
+ PosMax int
+ Level int
+ Pending bytes.Buffer
+ PendingLevel int
+ Delimiters []Delimiter
+
+ Cache map[int]int
+}
+
+func (s *StateInline) PushToken(tok Token) {
+ if s.Pending.Len() > 0 {
+ s.PushPending()
+ }
+ tok.SetLevel(s.Level)
+ s.PendingLevel = s.Level
+ s.Tokens = append(s.Tokens, tok)
+}
+
+func (s *StateInline) PushOpeningToken(tok Token) {
+ if s.Pending.Len() > 0 {
+ s.PushPending()
+ }
+ tok.SetLevel(s.Level)
+ s.Level++
+ s.PendingLevel = s.Level
+ s.Tokens = append(s.Tokens, tok)
+}
+
+func (s *StateInline) PushClosingToken(tok Token) {
+ if s.Pending.Len() > 0 {
+ s.PushPending()
+ }
+ s.Level--
+ tok.SetLevel(s.Level)
+ s.PendingLevel = s.Level
+ s.Tokens = append(s.Tokens, tok)
+}
+
+func (s *StateInline) PushPending() {
+ s.Tokens = append(s.Tokens, &Text{
+ Content: s.Pending.String(),
+ Lvl: s.PendingLevel,
+ })
+ s.Pending.Reset()
+}
+
+func (s *StateInline) scanDelims(start int, canSplitWord bool) (canOpen bool, canClose bool, length int) {
+ pos := start
+ max := s.PosMax
+ src := s.Src
+ marker := src[start]
+ leftFlanking, rightFlanking := true, true
+
+ lastChar := ' '
+ if start > 0 {
+ lastChar, _ = utf8.DecodeLastRuneInString(src[:start])
+ }
+
+ for pos < max && src[pos] == marker {
+ pos++
+ }
+ length = pos - start
+
+ nextChar := ' '
+ if pos < max {
+ nextChar, _ = utf8.DecodeRuneInString(src[pos:])
+ }
+
+ isLastPunct := isMdAsciiPunct(lastChar) || unicode.IsPunct(lastChar)
+ isNextPunct := isMdAsciiPunct(nextChar) || unicode.IsPunct(nextChar)
+
+ isLastWhiteSpace := unicode.IsSpace(lastChar)
+ isNextWhiteSpace := unicode.IsSpace(nextChar)
+
+ if isNextWhiteSpace {
+ leftFlanking = false
+ } else if isNextPunct {
+ if !(isLastWhiteSpace || isLastPunct) {
+ leftFlanking = false
+ }
+ }
+
+ if isLastWhiteSpace {
+ rightFlanking = false
+ } else if isLastPunct {
+ if !(isNextWhiteSpace || isNextPunct) {
+ rightFlanking = false
+ }
+ }
+
+ if !canSplitWord {
+ canOpen = leftFlanking && (!rightFlanking || isLastPunct)
+ canClose = rightFlanking && (!leftFlanking || isNextPunct)
+ } else {
+ canOpen = leftFlanking
+ canClose = rightFlanking
+ }
+
+ return
+}