all repos — grayfriday @ 352ffdefa470eb5221a71a951b5d1db436b3e862

blackfriday fork with a few changes

Remove a bunch of 'out' parameters from calls, WIP

Still not all of them, still broken.
Vytautas Ĺ altenis vytas@rtfb.lt
Sun, 01 Nov 2015 21:57:30 +0200
commit

352ffdefa470eb5221a71a951b5d1db436b3e862

parent

7ec50399c3d71d9fddbafa5f0d7851602c37fa0f

3 files changed, 78 insertions(+), 78 deletions(-)

jump to
M block.goblock.go

@@ -42,7 +42,7 @@ // ## Header 2

// ... // ###### Header 6 if p.isPrefixHeader(data) { - data = data[p.prefixHeader(out, data):] + data = data[p.prefixHeader(data):] continue }

@@ -52,7 +52,7 @@ // <div>

// ... // </div> if data[0] == '<' { - if i := p.html(out, data, true); i > 0 { + if i := p.html(data, true); i > 0 { data = data[i:] continue }

@@ -65,7 +65,7 @@ // % more stuff

// % even more stuff if p.flags&Titleblock != 0 { if data[0] == '%' { - if i := p.titleBlock(out, data, true); i > 0 { + if i := p.titleBlock(data, true); i > 0 { data = data[i:] continue }

@@ -87,7 +87,7 @@ // }

// return b // } if p.codePrefix(data) > 0 { - data = data[p.code(out, data):] + data = data[p.code(data):] continue }

@@ -102,7 +102,7 @@ // return n * fact(n-1)

// } // ``` if p.flags&FencedCode != 0 { - if i := p.fencedCode(out, data, true); i > 0 { + if i := p.fencedCode(data, true); i > 0 { data = data[i:] continue }

@@ -116,7 +116,7 @@ // ******

// or // ______ if p.isHRule(data) { - p.r.HRule(out) + p.r.HRule() var i int for i = 0; data[i] != '\n'; i++ { }

@@ -129,7 +129,7 @@ //

// > A big quote I found somewhere // > on the web if p.quotePrefix(data) > 0 { - data = data[p.quote(out, data):] + data = data[p.quote(data):] continue }

@@ -140,7 +140,7 @@ // ------|-----|---------

// Bob | 31 | 555-1234 // Alice | 27 | 555-4321 if p.flags&Tables != 0 { - if i := p.table(out, data); i > 0 { + if i := p.table(data); i > 0 { data = data[i:] continue }

@@ -153,7 +153,7 @@ // * Item 2

// // also works with + or - if p.uliPrefix(data) > 0 { - data = data[p.list(out, data, 0):] + data = data[p.list(data, 0):] continue }

@@ -162,7 +162,7 @@ //

// 1. Item 1 // 2. Item 2 if p.oliPrefix(data) > 0 { - data = data[p.list(out, data, ListTypeOrdered):] + data = data[p.list(data, ListTypeOrdered):] continue }

@@ -176,14 +176,14 @@ // Term 2

// : Definition c if p.flags&DefinitionLists != 0 { if p.dliPrefix(data) > 0 { - data = data[p.list(out, data, ListTypeDefinition):] + data = data[p.list(data, ListTypeDefinition):] continue } } // anything else must look like a normal paragraph // note: this finds underlined headers, too - data = data[p.paragraph(out, data):] + data = data[p.paragraph(data):] } p.nesting--

@@ -292,7 +292,7 @@ }

} data = bytes.Join(splitData[0:i], []byte("\n")) - p.r.TitleBlock(out, data) + p.r.TitleBlock(data) return len(data) }

@@ -309,12 +309,12 @@

// handle special cases if !tagfound { // check for an HTML comment - if size := p.htmlComment(out, data, doRender); size > 0 { + if size := p.htmlComment(data, doRender); size > 0 { return size } // check for an <hr> tag - if size := p.htmlHr(out, data, doRender); size > 0 { + if size := p.htmlHr(data, doRender); size > 0 { return size }

@@ -389,7 +389,7 @@ end := i

for end > 0 && data[end-1] == '\n' { end-- } - p.r.BlockHtml(out, data[:end]) + p.r.BlockHtml(data[:end]) } return i

@@ -397,7 +397,7 @@ }

// HTML comment, lax form func (p *parser) htmlComment(data []byte, doRender bool) int { - i := p.inlineHtmlComment(out, data) + i := p.inlineHtmlComment(data) // needs to end with a blank line if j := p.isEmpty(data[i:]); j > 0 { size := i + j

@@ -407,7 +407,7 @@ end := size

for end > 0 && data[end-1] == '\n' { end-- } - p.r.BlockHtml(out, data[:end]) + p.r.BlockHtml(data[:end]) } return size }

@@ -439,7 +439,7 @@ end := size

for end > 0 && data[end-1] == '\n' { end-- } - p.r.BlockHtml(out, data[:end]) + p.r.BlockHtml(data[:end]) } return size }

@@ -672,7 +672,7 @@ syntax = *lang

} if doRender { - p.r.BlockCode(out, work.Bytes(), syntax) + p.r.BlockCode(work.Bytes(), syntax) } return beg

@@ -705,7 +705,7 @@ i++

p.tableRow(&body, data[rowStart:i], columns, false) } - p.r.Table(out, header.Bytes(), body.Bytes(), columns) + p.r.Table(header.Bytes(), body.Bytes(), columns) return i }

@@ -871,7 +871,7 @@ }

// silently ignore rows with too many cells - p.r.TableRow(out, rowWork.Bytes()) + p.r.TableRow(rowWork.Bytes()) } // returns blockquote prefix length

@@ -912,7 +912,7 @@ // fenced code and if one's found, incorporate it altogether,

// irregardless of any contents inside it for data[end] != '\n' { if p.flags&FencedCode != 0 { - if i := p.fencedCode(out, data[end:], false); i > 0 { + if i := p.fencedCode(data[end:], false); i > 0 { // -1 to compensate for the extra end++ after the loop: end += i - 1 break

@@ -936,7 +936,7 @@ }

var cooked bytes.Buffer p.block(&cooked, raw.Bytes()) - p.r.BlockQuote(out, cooked.Bytes()) + p.r.BlockQuote(cooked.Bytes()) return end }

@@ -988,7 +988,7 @@ }

work.WriteByte('\n') - p.r.BlockCode(out, work.Bytes(), "") + p.r.BlockCode(work.Bytes(), "") return i }

@@ -1050,10 +1050,10 @@ // parse ordered or unordered list block

func (p *parser) list(data []byte, flags ListType) int { i := 0 flags |= ListItemBeginningOfList - p.r.BeginList(out, flags) + p.r.BeginList(flags) for i < len(data) { - skip := p.listItem(out, data[i:], &flags) + skip := p.listItem(data[i:], &flags) i += skip if skip == 0 || flags&ListItemEndOfList != 0 { break

@@ -1061,7 +1061,7 @@ }

flags &= ^ListItemBeginningOfList } - p.r.EndList(out, flags) + p.r.EndList(flags) return i }

@@ -1244,7 +1244,7 @@ // strip trailing newlines

for parsedEnd > 0 && cookedBytes[parsedEnd-1] == '\n' { parsedEnd-- } - p.r.ListItem(out, cookedBytes[:parsedEnd], *flags) + p.r.ListItem(cookedBytes[:parsedEnd], *flags) return line }

@@ -1269,9 +1269,9 @@ for end > beg && data[end-1] == ' ' {

end-- } - p.r.BeginParagraph(out) - p.inline(out, data[beg:end]) - p.r.EndParagraph(out) + p.r.BeginParagraph() + p.inline(data[beg:end]) + p.r.EndParagraph() } func (p *parser) paragraph(data []byte) int {

@@ -1292,11 +1292,11 @@ if n := p.isEmpty(current); n > 0 {

// did this blank line followed by a definition list item? if p.flags&DefinitionLists != 0 { if i < len(data)-1 && data[i+1] == ':' { - return p.list(out, data[prev:], ListTypeDefinition) + return p.list(data[prev:], ListTypeDefinition) } } - p.renderParagraph(out, data[:i]) + p.renderParagraph(data[:i]) return i + n }

@@ -1304,7 +1304,7 @@ // an underline under some text marks a header, so our paragraph ended on prev line

if i > 0 { if level := p.isUnderlinedHeader(current); level > 0 { // render the paragraph - p.renderParagraph(out, data[:prev]) + p.renderParagraph(data[:prev]) // ignore leading and trailing whitespace eol := i - 1

@@ -1334,23 +1334,23 @@ }

// if the next line starts a block of HTML, then the paragraph ends here if p.flags&LaxHTMLBlocks != 0 { - if data[i] == '<' && p.html(out, current, false) > 0 { + if data[i] == '<' && p.html(current, false) > 0 { // rewind to before the HTML block - p.renderParagraph(out, data[:i]) + p.renderParagraph(data[:i]) return i } } // if there's a prefixed header or a horizontal rule after this, paragraph is over if p.isPrefixHeader(current) || p.isHRule(current) { - p.renderParagraph(out, data[:i]) + p.renderParagraph(data[:i]) return i } // if there's a fenced code block, paragraph is over if p.flags&FencedCode != 0 { - if p.fencedCode(out, current, false) > 0 { - p.renderParagraph(out, data[:i]) + if p.fencedCode(current, false) > 0 { + p.renderParagraph(data[:i]) return i } }

@@ -1358,7 +1358,7 @@

// if there's a definition list item, prev line is a definition term if p.flags&DefinitionLists != 0 { if p.dliPrefix(current) != 0 { - return p.list(out, data[prev:], ListTypeDefinition) + return p.list(data[prev:], ListTypeDefinition) } }

@@ -1368,7 +1368,7 @@ if p.uliPrefix(current) != 0 ||

p.oliPrefix(current) != 0 || p.quotePrefix(current) != 0 || p.codePrefix(current) != 0 { - p.renderParagraph(out, data[:i]) + p.renderParagraph(data[:i]) return i } }

@@ -1380,6 +1380,6 @@ }

i++ } - p.renderParagraph(out, data[:i]) + p.renderParagraph(data[:i]) return i }
M html.gohtml.go

@@ -344,12 +344,12 @@ }

func (r *Html) BeginFootnotes() { out.WriteString("<div class=\"footnotes\">\n") - r.HRule(out) - r.BeginList(out, ListTypeOrdered) + r.HRule() + r.BeginList(ListTypeOrdered) } func (r *Html) EndFootnotes() { - r.EndList(out, ListTypeOrdered) + r.EndList(ListTypeOrdered) out.WriteString("</div>\n") }

@@ -685,7 +685,7 @@ out.WriteString("<html>\n")

} out.WriteString("<head>\n") out.WriteString(" <title>") - r.NormalText(out, []byte(r.title)) + r.NormalText([]byte(r.title)) out.WriteString("</title>\n") out.WriteString(" <meta name=\"GENERATOR\" content=\"Blackfriday Markdown Processor v") out.WriteString(VERSION)
M inline.goinline.go

@@ -51,11 +51,11 @@ // but smartDash processor relies on seeing context around the dashes.

// Fix this somehow. for end < len(data) { if data[end] == ' ' { - consumed, br := maybeLineBreak(p, out, data, end) + consumed, br := maybeLineBreak(p, data, end) if consumed > 0 { - p.r.NormalText(out, data[i:end]) + p.r.NormalText(data[i:end]) if br { - p.r.LineBreak(out) + p.r.LineBreak() } i = end i += consumed

@@ -76,7 +76,7 @@ end++

} } - p.r.NormalText(out, data[i:end]) + p.r.NormalText(data[i:end]) if end >= len(data) { break

@@ -85,7 +85,7 @@ i = end

// call the trigger handler := p.inlineCallback[data[end]] - if consumed := handler(p, out, data, i); consumed == 0 { + if consumed := handler(p, data, i); consumed == 0 { // no action from the callback; buffer the byte for later end = i + 1 } else {

@@ -110,7 +110,7 @@ // strikethrough only takes two characters '~~'

if c == '~' || isspace(data[1]) { return 0 } - if ret = helperEmphasis(p, out, data[1:], c); ret == 0 { + if ret = helperEmphasis(p, data[1:], c); ret == 0 { return 0 }

@@ -121,7 +121,7 @@ if len(data) > 3 && data[1] == c && data[2] != c {

if isspace(data[2]) { return 0 } - if ret = helperDoubleEmphasis(p, out, data[2:], c); ret == 0 { + if ret = helperDoubleEmphasis(p, data[2:], c); ret == 0 { return 0 }

@@ -132,7 +132,7 @@ if len(data) > 4 && data[1] == c && data[2] == c && data[3] != c {

if c == '~' || isspace(data[3]) { return 0 } - if ret = helperTripleEmphasis(p, out, data, 3, c); ret == 0 { + if ret = helperTripleEmphasis(p, data, 3, c); ret == 0 { return 0 }

@@ -180,7 +180,7 @@ }

// render the code span if fBegin != fEnd { - p.r.CodeSpan(out, data[fBegin:fEnd]) + p.r.CodeSpan(data[fBegin:fEnd]) } return end

@@ -205,7 +205,7 @@

// newline without two spaces works when HardLineBreak is enabled func lineBreak(p *parser, data []byte, offset int) int { if p.flags&HardLineBreak != 0 { - p.r.LineBreak(out) + p.r.LineBreak() return 1 } return 0

@@ -229,14 +229,14 @@ }

func maybeImage(p *parser, data []byte, offset int) int { if offset < len(data)-1 && data[offset+1] == '[' { - return link(p, out, data, offset) + return link(p, data, offset) } return 0 } func maybeInlineFootnote(p *parser, data []byte, offset int) int { if offset < len(data)-1 && data[offset+1] == '[' { - return link(p, out, data, offset) + return link(p, data, offset) } return 0 }

@@ -572,21 +572,21 @@ // call the relevant rendering function

switch t { case linkNormal: if len(altContent) > 0 { - p.r.Link(out, uLink, title, altContent) + p.r.Link(uLink, title, altContent) } else { - p.r.Link(out, uLink, title, content.Bytes()) + p.r.Link(uLink, title, content.Bytes()) } case linkImg: - p.r.Image(out, uLink, title, content.Bytes()) + p.r.Image(uLink, title, content.Bytes()) i += 1 case linkInlineFootnote: - p.r.FootnoteRef(out, link, noteId) + p.r.FootnoteRef(link, noteId) i += 1 case linkDeferredFootnote: - p.r.FootnoteRef(out, link, noteId) + p.r.FootnoteRef(link, noteId) default: return 0

@@ -619,7 +619,7 @@ func leftAngle(p *parser, data []byte, offset int) int {

data = data[offset:] altype := LinkTypeNotAutolink end := tagLength(data, &altype) - if size := p.inlineHtmlComment(out, data); size > 0 { + if size := p.inlineHtmlComment(data); size > 0 { end = size } if end > 2 {

@@ -627,10 +627,10 @@ if altype != LinkTypeNotAutolink {

var uLink bytes.Buffer unescapeText(&uLink, data[1:end+1-2]) if uLink.Len() > 0 { - p.r.AutoLink(out, uLink.Bytes(), altype) + p.r.AutoLink(uLink.Bytes(), altype) } } else { - p.r.RawHtmlTag(out, data[:end]) + p.r.RawHtmlTag(data[:end]) } }

@@ -645,14 +645,14 @@ data = data[offset:]

if len(data) > 1 { if p.flags&BackslashLineBreak != 0 && data[1] == '\n' { - p.r.LineBreak(out) + p.r.LineBreak() return 2 } if bytes.IndexByte(escapeChars, data[1]) < 0 { return 0 } - p.r.NormalText(out, data[1:2]) + p.r.NormalText(data[1:2]) } return 2

@@ -700,7 +700,7 @@ } else {

return 0 // lone '&' } - p.r.Entity(out, data[:end]) + p.r.Entity(data[:end]) return end }

@@ -729,7 +729,7 @@ endOfHead = len(data)

} head := bytes.ToLower(data[offset:endOfHead]) if bytes.HasPrefix(head, []byte(prefix)) { - return autoLink(p, out, data, offset) + return autoLink(p, data, offset) } } return 0

@@ -844,7 +844,7 @@ var uLink bytes.Buffer

unescapeText(&uLink, data[:linkEnd]) if uLink.Len() > 0 { - p.r.AutoLink(out, uLink.Bytes(), LinkTypeNormal) + p.r.AutoLink(uLink.Bytes(), LinkTypeNormal) } return linkEnd

@@ -1101,7 +1101,7 @@ }

var work bytes.Buffer p.inline(&work, data[:i]) - p.r.Emphasis(out, work.Bytes()) + p.r.Emphasis(work.Bytes()) return i + 1 } }

@@ -1126,9 +1126,9 @@

if work.Len() > 0 { // pick the right renderer if c == '~' { - p.r.StrikeThrough(out, work.Bytes()) + p.r.StrikeThrough(work.Bytes()) } else { - p.r.DoubleEmphasis(out, work.Bytes()) + p.r.DoubleEmphasis(work.Bytes()) } } return i + 2

@@ -1162,12 +1162,12 @@ var work bytes.Buffer

p.inline(&work, data[:i]) if work.Len() > 0 { - p.r.TripleEmphasis(out, work.Bytes()) + p.r.TripleEmphasis(work.Bytes()) } return i + 3 case (i+1 < len(data) && data[i+1] == c): // double symbol found, hand over to emph1 - length = helperEmphasis(p, out, origData[offset-2:], c) + length = helperEmphasis(p, origData[offset-2:], c) if length == 0 { return 0 } else {

@@ -1175,7 +1175,7 @@ return length - 2

} default: // single symbol found, hand over to emph2 - length = helperDoubleEmphasis(p, out, origData[offset-1:], c) + length = helperDoubleEmphasis(p, origData[offset-1:], c) if length == 0 { return 0 } else {