forked from mmarkdown/mmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
include.go
45 lines (38 loc) · 805 Bytes
/
include.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package markdown
import "github.com/mmarkdown/mmark/mparser"
// Almost wholesale copy of parser/include.go - might make sense to make some of that public.
func isInclude(data []byte) bool {
i := 0
if data[i] != '{' || data[i+1] != '{' {
return false
}
// find the end delimiter
i = mparser.SkipUntilChar(data, i, '}')
if i+1 >= len(data) {
return false
}
end := i
i++
if data[i] != '}' {
return false
}
if i+1 < len(data) && data[i+1] == '[' { // potential address specification
start := i + 2
end = mparser.SkipUntilChar(data, start, ']')
if end >= len(data) {
return false
}
return true
}
return true
}
func isCodeInclude(data []byte) bool {
i := 0
if len(data[i:]) < 3 {
return false
}
if data[i] != '<' {
return false
}
return isInclude(data[i+1:])
}