Redirect output to a capture buffer where necessary Use CaptureWrites where output should go to a temp buffer instead of the final output.
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 04 Nov 2015 22:18:46 +0200
M
block.go
→
block.go
@@ -852,13 +852,14 @@ for cellEnd > cellStart && data[cellEnd-1] == ' ' {
cellEnd-- } - var cellWork bytes.Buffer - p.inline(&cellWork, data[cellStart:cellEnd]) + cellWork := p.r.CaptureWrites(func() { + p.inline(data[cellStart:cellEnd]) + }) if header { - p.r.TableHeaderCell(&rowWork, cellWork.Bytes(), columns[col]) + p.r.TableHeaderCell(&rowWork, cellWork, columns[col]) } else { - p.r.TableCell(&rowWork, cellWork.Bytes(), columns[col]) + p.r.TableCell(&rowWork, cellWork, columns[col]) } }@@ -936,9 +937,9 @@ raw.Write(data[beg:end])
beg = end } - var cooked bytes.Buffer - p.block(&cooked, raw.Bytes()) - p.r.BlockQuote(cooked.Bytes()) + p.r.BlockQuote(p.r.CaptureWrites(func() { + p.block(raw.Bytes()) + })) return end }@@ -1223,18 +1224,26 @@ var cooked bytes.Buffer
if *flags&ListItemContainsBlock != 0 && *flags&ListTypeTerm == 0 { // intermediate render of block item, except for definition term if sublist > 0 { - p.block(&cooked, rawBytes[:sublist]) - p.block(&cooked, rawBytes[sublist:]) + cooked.Write(p.r.CaptureWrites(func() { + p.block(rawBytes[:sublist]) + p.block(rawBytes[sublist:]) + })) } else { - p.block(&cooked, rawBytes) + cooked.Write(p.r.CaptureWrites(func() { + p.block(rawBytes) + })) } } else { // intermediate render of inline item if sublist > 0 { - p.inline(&cooked, rawBytes[:sublist]) - p.block(&cooked, rawBytes[sublist:]) + cooked.Write(p.r.CaptureWrites(func() { + p.inline(rawBytes[:sublist]) + p.block(rawBytes[sublist:]) + })) } else { - p.inline(&cooked, rawBytes) + cooked.Write(p.r.CaptureWrites(func() { + p.inline(rawBytes) + })) } }
M
inline.go
→
inline.go
@@ -549,7 +549,9 @@ } else {
// links cannot contain other links, so turn off link parsing temporarily insideLink := p.insideLink p.insideLink = true - p.inline(&content, data[1:txtE]) + content.Write(p.r.CaptureWrites(func() { + p.inline(data[1:txtE]) + })) p.insideLink = insideLink } }@@ -1099,9 +1101,10 @@ continue
} } - var work bytes.Buffer - p.inline(&work, data[:i]) - p.r.Emphasis(work.Bytes()) + work := p.r.CaptureWrites(func() { + p.inline(data[:i]) + }) + p.r.Emphasis(work) return i + 1 } }@@ -1121,7 +1124,9 @@ i += length
if i+1 < len(data) && data[i] == c && data[i+1] == c && i > 0 && !isspace(data[i-1]) { var work bytes.Buffer - p.inline(&work, data[:i]) + work.Write(p.r.CaptureWrites(func() { + p.inline(data[:i]) + })) if work.Len() > 0 { // pick the right renderer@@ -1159,8 +1164,9 @@ switch {
case i+2 < len(data) && data[i+1] == c && data[i+2] == c: // triple symbol found var work bytes.Buffer - - p.inline(&work, data[:i]) + work.Write(p.r.CaptureWrites(func() { + p.inline(data[:i]) + })) if work.Len() > 0 { p.r.TripleEmphasis(work.Bytes()) }