summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/gomarkdown/markdown/parser/aside.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/aside.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/aside.go')
-rw-r--r--vendor/github.com/gomarkdown/markdown/parser/aside.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/vendor/github.com/gomarkdown/markdown/parser/aside.go b/vendor/github.com/gomarkdown/markdown/parser/aside.go
new file mode 100644
index 00000000..96e25fe0
--- /dev/null
+++ b/vendor/github.com/gomarkdown/markdown/parser/aside.go
@@ -0,0 +1,73 @@
+package parser
+
+import (
+ "bytes"
+
+ "github.com/gomarkdown/markdown/ast"
+)
+
+// returns aisde prefix length
+func (p *Parser) asidePrefix(data []byte) int {
+ i := 0
+ n := len(data)
+ for i < 3 && i < n && data[i] == ' ' {
+ i++
+ }
+ if i+1 < n && data[i] == 'A' && data[i+1] == '>' {
+ if i+2 < n && data[i+2] == ' ' {
+ return i + 3
+ }
+ return i + 2
+ }
+ return 0
+}
+
+// aside ends with at least one blank line
+// followed by something without a aside prefix
+func (p *Parser) terminateAside(data []byte, beg, end int) bool {
+ if p.isEmpty(data[beg:]) <= 0 {
+ return false
+ }
+ if end >= len(data) {
+ return true
+ }
+ return p.asidePrefix(data[end:]) == 0 && p.isEmpty(data[end:]) == 0
+}
+
+// parse a aside fragment
+func (p *Parser) aside(data []byte) int {
+ var raw bytes.Buffer
+ beg, end := 0, 0
+ // identical to quote
+ for beg < len(data) {
+ end = beg
+ // Step over whole lines, collecting them. While doing that, check for
+ // fenced code and if one's found, incorporate it altogether,
+ // irregardless of any contents inside it
+ for end < len(data) && data[end] != '\n' {
+ if p.extensions&FencedCode != 0 {
+ if i := p.fencedCodeBlock(data[end:], false); i > 0 {
+ // -1 to compensate for the extra end++ after the loop:
+ end += i - 1
+ break
+ }
+ }
+ end++
+ }
+ end = skipCharN(data, end, '\n', 1)
+ if pre := p.asidePrefix(data[beg:]); pre > 0 {
+ // skip the prefix
+ beg += pre
+ } else if p.terminateAside(data, beg, end) {
+ break
+ }
+ // this line is part of the aside
+ raw.Write(data[beg:end])
+ beg = end
+ }
+
+ block := p.addBlock(&ast.Aside{})
+ p.block(raw.Bytes())
+ p.finalize(block)
+ return end
+}