summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gomarkdown/markdown/parser/ref.go
diff options
context:
space:
mode:
authorBenjamin <b.mpickford@outlook.com>2019-11-18 06:18:01 +1000
committerWim <wim@42.be>2019-11-17 21:18:01 +0100
commit0917dc876613fd71c9726a34bf0138b4f5121be9 (patch)
tree1eacaadaa4869e8f74ccf65c684c2a80f90787f9 /vendor/github.com/gomarkdown/markdown/parser/ref.go
parentaba86855b5f71c9809d892a7eebc6b69872fcd5b (diff)
downloadmatterbridge-msglm-0917dc876613fd71c9726a34bf0138b4f5121be9.tar.gz
matterbridge-msglm-0917dc876613fd71c9726a34bf0138b4f5121be9.tar.bz2
matterbridge-msglm-0917dc876613fd71c9726a34bf0138b4f5121be9.zip
Update markdown parsing library to github.com/gomarkdown/markdown (#944)
Diffstat (limited to 'vendor/github.com/gomarkdown/markdown/parser/ref.go')
-rw-r--r--vendor/github.com/gomarkdown/markdown/parser/ref.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/github.com/gomarkdown/markdown/parser/ref.go b/vendor/github.com/gomarkdown/markdown/parser/ref.go
new file mode 100644
index 00000000..0b59a196
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/parser/ref.go
@@ -0,0 +1,89 @@
+package parser
+
+import (
+ "bytes"
+ "fmt"
+
+ "github.com/gomarkdown/markdown/ast"
+)
+
+// parse '(#r)', where r does not contain spaces. Or.
+// (!item) (!item, subitem), for an index, (!!item) signals primary.
+func maybeShortRefOrIndex(p *Parser, data []byte, offset int) (int, ast.Node) {
+ if len(data[offset:]) < 4 {
+ return 0, nil
+ }
+ // short ref first
+ data = data[offset:]
+ i := 1
+ switch data[i] {
+ case '#': // cross ref
+ i++
+ Loop:
+ for i < len(data) {
+ c := data[i]
+ switch {
+ case c == ')':
+ break Loop
+ case !isAlnum(c):
+ if c == '_' || c == '-' || c == ':' {
+ i++
+ continue
+ }
+ i = 0
+ break Loop
+ }
+ i++
+ }
+ if i >= len(data) {
+ return 0, nil
+ }
+ if data[i] != ')' {
+ return 0, nil
+ }
+
+ id := data[2:i]
+ node := &ast.CrossReference{}
+ node.Destination = id
+
+ return i + 1, node
+
+ case '!': // index
+ i++
+ start := i
+ i = skipUntilChar(data, start, ')')
+
+ // did we reach the end of the buffer without a closing marker?
+ if i >= len(data) {
+ return 0, nil
+ }
+
+ if len(data[start:i]) < 1 {
+ return 0, nil
+ }
+
+ idx := &ast.Index{}
+
+ idx.ID = fmt.Sprintf("idxref:%d", p.indexCnt)
+ p.indexCnt++
+
+ idx.Primary = data[start] == '!'
+ buf := data[start:i]
+
+ if idx.Primary {
+ buf = buf[1:]
+ }
+ items := bytes.Split(buf, []byte(","))
+ switch len(items) {
+ case 1:
+ idx.Item = bytes.TrimSpace(items[0])
+ return i + 1, idx
+ case 2:
+ idx.Item = bytes.TrimSpace(items[0])
+ idx.Subitem = bytes.TrimSpace(items[1])
+ return i + 1, idx
+ }
+ }
+
+ return 0, nil
+}