Parse block-level data. Note: this function and many that it calls assume that the input buffer ends with a newline.
(data []byte)
| 35 | // Note: this function and many that it calls assume that |
| 36 | // the input buffer ends with a newline. |
| 37 | func (p *Markdown) block(data []byte) { |
| 38 | // this is called recursively: enforce a maximum depth |
| 39 | if p.nesting >= p.maxNesting { |
| 40 | return |
| 41 | } |
| 42 | p.nesting++ |
| 43 | |
| 44 | // parse out one block-level construct at a time |
| 45 | for len(data) > 0 { |
| 46 | // prefixed heading: |
| 47 | // |
| 48 | // # Heading 1 |
| 49 | // ## Heading 2 |
| 50 | // ... |
| 51 | // ###### Heading 6 |
| 52 | if p.isPrefixHeading(data) { |
| 53 | data = data[p.prefixHeading(data):] |
| 54 | continue |
| 55 | } |
| 56 | |
| 57 | // block of preformatted HTML: |
| 58 | // |
| 59 | // <div> |
| 60 | // ... |
| 61 | // </div> |
| 62 | if data[0] == '<' { |
| 63 | if i := p.html(data, true); i > 0 { |
| 64 | data = data[i:] |
| 65 | continue |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // title block |
| 70 | // |
| 71 | // % stuff |
| 72 | // % more stuff |
| 73 | // % even more stuff |
| 74 | if p.extensions&Titleblock != 0 { |
| 75 | if data[0] == '%' { |
| 76 | if i := p.titleBlock(data, true); i > 0 { |
| 77 | data = data[i:] |
| 78 | continue |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // blank lines. note: returns the # of bytes to skip |
| 84 | if i := p.isEmpty(data); i > 0 { |
| 85 | data = data[i:] |
| 86 | continue |
| 87 | } |
| 88 | |
| 89 | // indented code block: |
| 90 | // |
| 91 | // func max(a, b int) int { |
| 92 | // if a > b { |
| 93 | // return a |
| 94 | // } |
no test coverage detected