summaryrefslogtreecommitdiffstats
path: root/vendor/gitlab.com/golang-commonmark/markdown/parser_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/parser_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/parser_inline.go')
-rw-r--r--vendor/gitlab.com/golang-commonmark/markdown/parser_inline.go106
1 files changed, 106 insertions, 0 deletions
diff --git a/vendor/gitlab.com/golang-commonmark/markdown/parser_inline.go b/vendor/gitlab.com/golang-commonmark/markdown/parser_inline.go
new file mode 100644
index 00000000..5e976ebd
--- /dev/null
+++ b/vendor/gitlab.com/golang-commonmark/markdown/parser_inline.go
@@ -0,0 +1,106 @@
+// 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 "unicode/utf8"
+
+type ParserInline struct {
+}
+
+type (
+ InlineRule func(*StateInline, bool) bool
+ PostprocessRule func(*StateInline)
+)
+
+var (
+ inlineRules []InlineRule
+ postprocessRules []PostprocessRule
+)
+
+func (i ParserInline) Parse(src string, md *Markdown, env *Environment) []Token {
+ if src == "" {
+ return nil
+ }
+
+ var s StateInline
+ s.Src = src
+ s.Md = md
+ s.Env = env
+ s.PosMax = len(src)
+ s.Tokens = s.bootstrap[:0]
+
+ i.Tokenize(&s)
+
+ for _, r := range postprocessRules {
+ r(&s)
+ }
+
+ return s.Tokens
+}
+
+func (ParserInline) Tokenize(s *StateInline) {
+ end := s.PosMax
+ src := s.Src
+ maxNesting := s.Md.MaxNesting
+ ok := false
+
+ for s.Pos < end {
+ if s.Level < maxNesting {
+ for _, rule := range inlineRules {
+ ok = rule(s, false)
+ if ok {
+ break
+ }
+ }
+ }
+
+ if ok {
+ if s.Pos >= end {
+ break
+ }
+ continue
+ }
+
+ r, size := utf8.DecodeRuneInString(src[s.Pos:])
+ s.Pending.WriteRune(r)
+ s.Pos += size
+ }
+
+ if s.Pending.Len() > 0 {
+ s.PushPending()
+ }
+}
+
+func (ParserInline) SkipToken(s *StateInline) {
+ pos := s.Pos
+ if s.Cache != nil {
+ if newPos, ok := s.Cache[pos]; ok {
+ s.Pos = newPos
+ return
+ }
+ } else {
+ s.Cache = make(map[int]int)
+ }
+
+ ok := false
+ if s.Level < s.Md.MaxNesting {
+ for _, r := range inlineRules {
+ s.Level++
+ ok = r(s, true)
+ s.Level--
+ if ok {
+ break
+ }
+ }
+ } else {
+ s.Pos = s.PosMax
+ }
+
+ if !ok {
+ _, size := utf8.DecodeRuneInString(s.Src[s.Pos:])
+ s.Pos += size
+ }
+ s.Cache[pos] = s.Pos
+}