Functions to parse text within a block Each function returns the number of chars taken care of data is the complete block being rendered offset is the number of valid chars before the current cursor
(currBlock *Node, data []byte)
| 47 | // offset is the number of valid chars before the current cursor |
| 48 | |
| 49 | func (p *Markdown) inline(currBlock *Node, data []byte) { |
| 50 | // handlers might call us recursively: enforce a maximum depth |
| 51 | if p.nesting >= p.maxNesting || len(data) == 0 { |
| 52 | return |
| 53 | } |
| 54 | p.nesting++ |
| 55 | beg, end := 0, 0 |
| 56 | for end < len(data) { |
| 57 | handler := p.inlineCallback[data[end]] |
| 58 | if handler != nil { |
| 59 | if consumed, node := handler(p, data, end); consumed == 0 { |
| 60 | // No action from the callback. |
| 61 | end++ |
| 62 | } else { |
| 63 | // Copy inactive chars into the output. |
| 64 | currBlock.AppendChild(text(data[beg:end])) |
| 65 | if node != nil { |
| 66 | currBlock.AppendChild(node) |
| 67 | } |
| 68 | // Skip past whatever the callback used. |
| 69 | beg = end + consumed |
| 70 | end = beg |
| 71 | } |
| 72 | } else { |
| 73 | end++ |
| 74 | } |
| 75 | } |
| 76 | if beg < len(data) { |
| 77 | if data[end-1] == '\n' { |
| 78 | end-- |
| 79 | } |
| 80 | currBlock.AppendChild(text(data[beg:end])) |
| 81 | } |
| 82 | p.nesting-- |
| 83 | } |
| 84 | |
| 85 | // single and double emphasis parsing |
| 86 | func emphasis(p *Markdown, data []byte, offset int) (int, *Node) { |
no test coverage detected