all repos — grayfriday @ ea8dfc488069987834e0db3ef4443398b0bb4934

blackfriday fork with a few changes

Move reference extraction to paragraph parser

Move reference and footnote extraction code from firstPass to a
paragraph block parser. This makes firstPass a little bit slimmer, ergo
closer to elimination.
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 29 Aug 2016 23:57:59 +0300
commit

ea8dfc488069987834e0db3ef4443398b0bb4934

parent

efa77da18b0fa3413ebafb99ef6afad578ad6593

2 files changed, 17 insertions(+), 6 deletions(-)

jump to
M block.goblock.go

@@ -1380,13 +1380,24 @@ // prev: index of 1st char of previous line

// line: index of 1st char of current line // i: index of cursor/end of current line var prev, line, i int - + tabSize := TabSizeDefault + if p.flags&TabSizeEight != 0 { + tabSize = TabSizeDouble + } // keep going until we find something to mark the end of the paragraph for i < len(data) { // mark the beginning of the current line prev = line current := data[i:] line = i + + // did we find a reference or a footnote? If so, end a paragraph + // preceding it and report that we have consumed up to the end of that + // reference: + if refEnd := isReference(p, current, tabSize); refEnd > 0 { + p.renderParagraph(data[:i]) + return i + refEnd + } // did we find a blank line marking the end of the paragraph? if n := p.isEmpty(current); n > 0 {
M markdown.gomarkdown.go

@@ -453,7 +453,6 @@ }

// first pass: // - normalize newlines -// - extract references (outside of fenced code blocks) // - expand tabs (outside of fenced code blocks) // - copy everything else func firstPass(p *parser, input []byte) []byte {

@@ -485,9 +484,6 @@ // add the line body if present

if end > beg { if end < lastFencedCodeBlockEnd { // Do not expand tabs while inside fenced code blocks. out.Write(input[beg:end]) - } else if refEnd := isReference(p, input[beg:], tabSize); refEnd > 0 { - beg += refEnd - continue } else { expandTabs(&out, input[beg:end], tabSize) }

@@ -593,7 +589,11 @@ if i >= len(data) || data[i] != ']' {

return 0 } idEnd := i - + // footnotes can have empty ID, like this: [^], but a reference can not be + // empty like this: []. Break early if it's not a footnote and there's no ID + if noteID == 0 && idOffset == idEnd { + return 0 + } // spacer: colon (space | tab)* newline? (space | tab)* i++ if i >= len(data) || data[i] != ':' {