summaryrefslogtreecommitdiffstats
path: root/vendor/gitlab.com/golang-commonmark/markdown/state_inline.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-01-06 22:25:19 +0100
committerGitHub <noreply@github.com>2019-01-06 22:25:19 +0100
commit04567c765e92ad60c685c1b2fe7e77c46e065645 (patch)
tree34a587a6545c8e71e991e2a1551885faa0075738 /vendor/gitlab.com/golang-commonmark/markdown/state_inline.go
parent048158ad6db08cd714f39467fc0066ce41cfe6c5 (diff)
downloadmatterbridge-msglm-04567c765e92ad60c685c1b2fe7e77c46e065645.tar.gz
matterbridge-msglm-04567c765e92ad60c685c1b2fe7e77c46e065645.tar.bz2
matterbridge-msglm-04567c765e92ad60c685c1b2fe7e77c46e065645.zip
Add support for markdown to HTML conversion (matrix). Closes #663 (#670)
This uses our own gomatrix lib with the SendHTML function which adds HTML to formatted_body in matrix. golang-commonmark is used to convert markdown into valid HTML.
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
+}