forked from ego008/go-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backticks.go
58 lines (45 loc) · 885 Bytes
/
backticks.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
46
47
48
49
50
51
52
53
54
55
56
57
58
// 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
func ruleBackticks(s *StateInline, silent bool) (_ bool) {
pos := s.Pos
src := s.Src
if src[pos] != '`' {
return
}
start := pos
pos++
max := s.PosMax
for pos < max && src[pos] == '`' {
pos++
}
marker := src[start:pos]
end := pos
for {
for start = end; start < max && src[start] != '`'; start++ {
// do nothing
}
if start >= max {
break
}
end = start + 1
for end < max && src[end] == '`' {
end++
}
if end-start == len(marker) {
if !silent {
s.PushToken(&CodeInline{
Content: normalizeInlineCode(src[pos:start]),
})
}
s.Pos = end
return true
}
}
if !silent {
s.Pending.WriteString(marker)
}
s.Pos += len(marker)
return true
}