forked from ego008/go-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr.go
57 lines (44 loc) · 821 Bytes
/
hr.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
// 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
var hr [256]bool
func init() {
hr['*'], hr['-'], hr['_'] = true, true, true
}
func ruleHR(s *StateBlock, startLine, endLine int, silent bool) (_ bool) {
shift := s.TShift[startLine]
if shift < 0 {
return
}
pos := s.BMarks[startLine] + shift
src := s.Src
marker := src[pos]
if !hr[marker] {
return
}
pos++
max := s.EMarks[startLine]
count := 1
for pos < max {
c := src[pos]
pos++
if c != marker && c != ' ' {
return
}
if c == marker {
count++
}
}
if count < 3 {
return
}
if silent {
return true
}
s.Line = startLine + 1
s.PushToken(&Hr{
Map: [2]int{startLine, s.Line},
})
return true
}