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

Still not all of them, still broken.
This commit is contained in:
Vytautas Šaltenis 2015-11-01 21:57:30 +02:00
parent 7ec50399c3
commit 352ffdefa4
3 changed files with 78 additions and 78 deletions

View File

@ -42,7 +42,7 @@ func (p *parser) block(data []byte) {
// ...
// ###### Header 6
if p.isPrefixHeader(data) {
data = data[p.prefixHeader(out, data):]
data = data[p.prefixHeader(data):]
continue
}
@ -52,7 +52,7 @@ func (p *parser) block(data []byte) {
// ...
// </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 @@ func (p *parser) block(data []byte) {
// % 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 @@ func (p *parser) block(data []byte) {
// return b
// }
if p.codePrefix(data) > 0 {
data = data[p.code(out, data):]
data = data[p.code(data):]
continue
}
@ -102,7 +102,7 @@ func (p *parser) block(data []byte) {
// }
// ```
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 @@ func (p *parser) block(data []byte) {
// 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 @@ func (p *parser) block(data []byte) {
// > 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 @@ func (p *parser) block(data []byte) {
// 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 @@ func (p *parser) block(data []byte) {
//
// 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 @@ func (p *parser) block(data []byte) {
// 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 @@ func (p *parser) block(data []byte) {
// : 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 @@ func (p *parser) titleBlock(data []byte, doRender bool) int {
}
data = bytes.Join(splitData[0:i], []byte("\n"))
p.r.TitleBlock(out, data)
p.r.TitleBlock(data)
return len(data)
}
@ -309,12 +309,12 @@ func (p *parser) html(data []byte, doRender bool) int {
// 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 @@ func (p *parser) html(data []byte, doRender bool) int {
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 @@ func (p *parser) html(data []byte, doRender bool) int {
// 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 @@ func (p *parser) htmlComment(data []byte, doRender bool) int {
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 @@ func (p *parser) htmlHr(data []byte, doRender bool) int {
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 @@ func (p *parser) fencedCode(data []byte, doRender bool) int {
}
if doRender {
p.r.BlockCode(out, work.Bytes(), syntax)
p.r.BlockCode(work.Bytes(), syntax)
}
return beg
@ -705,7 +705,7 @@ func (p *parser) table(data []byte) int {
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 @@ func (p *parser) tableRow(out *bytes.Buffer, data []byte, columns []int, header
// 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 @@ func (p *parser) quote(data []byte) int {
// 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 @@ func (p *parser) quote(data []byte) int {
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 @@ func (p *parser) code(data []byte) int {
work.WriteByte('\n')
p.r.BlockCode(out, work.Bytes(), "")
p.r.BlockCode(work.Bytes(), "")
return i
}
@ -1050,10 +1050,10 @@ func (p *parser) dliPrefix(data []byte) int {
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 @@ func (p *parser) list(data []byte, flags ListType) int {
flags &= ^ListItemBeginningOfList
}
p.r.EndList(out, flags)
p.r.EndList(flags)
return i
}
@ -1244,7 +1244,7 @@ gatherlines:
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 @@ func (p *parser) renderParagraph(data []byte) {
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 @@ func (p *parser) paragraph(data []byte) int {
// 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 @@ func (p *parser) paragraph(data []byte) int {
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 @@ func (p *parser) paragraph(data []byte) int {
// 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 @@ func (p *parser) paragraph(data []byte) int {
// 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 @@ func (p *parser) paragraph(data []byte) int {
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 @@ func (p *parser) paragraph(data []byte) int {
i++
}
p.renderParagraph(out, data[:i])
p.renderParagraph(data[:i])
return i
}

View File

@ -344,12 +344,12 @@ func (r *Html) TableCell(out *bytes.Buffer, text []byte, align int) {
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 @@ func (r *Html) DocumentHeader() {
}
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)

View File

@ -51,11 +51,11 @@ func (p *parser) inline(data []byte) {
// 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 @@ func (p *parser) inline(data []byte) {
}
}
p.r.NormalText(out, data[i:end])
p.r.NormalText(data[i:end])
if end >= len(data) {
break
@ -85,7 +85,7 @@ func (p *parser) inline(data []byte) {
// 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 @@ func emphasis(p *parser, data []byte, offset int) int {
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 @@ func emphasis(p *parser, data []byte, offset int) int {
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 @@ func emphasis(p *parser, data []byte, offset int) int {
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 @@ func codeSpan(p *parser, data []byte, offset int) int {
// 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 @@ func maybeLineBreak(p *parser, data []byte, offset int) (int, bool) {
// 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 isReferenceStyleLink(data []byte, pos int, t linkType) bool {
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 @@ func link(p *parser, data []byte, offset int) int {
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 @@ func leftAngle(p *parser, data []byte, offset int) int {
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 @@ func escape(p *parser, data []byte, offset int) int {
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 @@ func entity(p *parser, data []byte, offset int) int {
return 0 // lone '&'
}
p.r.Entity(out, data[:end])
p.r.Entity(data[:end])
return end
}
@ -729,7 +729,7 @@ func maybeAutoLink(p *parser, data []byte, offset int) int {
}
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 @@ func autoLink(p *parser, data []byte, offset int) int {
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 @@ func helperEmphasis(p *parser, data []byte, c byte) int {
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 @@ func helperDoubleEmphasis(p *parser, data []byte, c byte) int {
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 @@ func helperTripleEmphasis(p *parser, data []byte, offset int, c byte) int {
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 @@ func helperTripleEmphasis(p *parser, data []byte, offset int, c byte) int {
}
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 {