From 7ec50399c3d71d9fddbafa5f0d7851602c37fa0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Sun, 1 Nov 2015 21:35:43 +0200 Subject: [PATCH] Remove 'out' parameter from parser funcs This only removes the parameter from declarations, everything is broken at the moment. --- block.go | 28 ++++++++++++++-------------- inline.go | 34 +++++++++++++++++----------------- markdown.go | 2 +- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/block.go b/block.go index a992f03..c2b4da7 100644 --- a/block.go +++ b/block.go @@ -22,7 +22,7 @@ import ( // Parse block-level data. // Note: this function and many that it calls assume that // the input buffer ends with a newline. -func (p *parser) block(out *bytes.Buffer, data []byte) { +func (p *parser) block(data []byte) { if len(data) == 0 || data[len(data)-1] != '\n' { panic("block input is missing terminating newline") } @@ -206,7 +206,7 @@ func (p *parser) isPrefixHeader(data []byte) bool { return true } -func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int { +func (p *parser) prefixHeader(data []byte) int { level := 0 for level < 6 && data[level] == '#' { level++ @@ -278,7 +278,7 @@ func (p *parser) isUnderlinedHeader(data []byte) int { return 0 } -func (p *parser) titleBlock(out *bytes.Buffer, data []byte, doRender bool) int { +func (p *parser) titleBlock(data []byte, doRender bool) int { if data[0] != '%' { return 0 } @@ -297,7 +297,7 @@ func (p *parser) titleBlock(out *bytes.Buffer, data []byte, doRender bool) int { return len(data) } -func (p *parser) html(out *bytes.Buffer, data []byte, doRender bool) int { +func (p *parser) html(data []byte, doRender bool) int { var i, j int // identify the opening tag @@ -396,7 +396,7 @@ func (p *parser) html(out *bytes.Buffer, data []byte, doRender bool) int { } // HTML comment, lax form -func (p *parser) htmlComment(out *bytes.Buffer, data []byte, doRender bool) int { +func (p *parser) htmlComment(data []byte, doRender bool) int { i := p.inlineHtmlComment(out, data) // needs to end with a blank line if j := p.isEmpty(data[i:]); j > 0 { @@ -415,7 +415,7 @@ func (p *parser) htmlComment(out *bytes.Buffer, data []byte, doRender bool) int } // HR, which is the only self-closing block tag considered -func (p *parser) htmlHr(out *bytes.Buffer, data []byte, doRender bool) int { +func (p *parser) htmlHr(data []byte, doRender bool) int { if data[0] != '<' || (data[1] != 'h' && data[1] != 'H') || (data[2] != 'r' && data[2] != 'R') { return 0 } @@ -632,7 +632,7 @@ func (p *parser) isFencedCode(data []byte, syntax **string, oldmarker string) (s return } -func (p *parser) fencedCode(out *bytes.Buffer, data []byte, doRender bool) int { +func (p *parser) fencedCode(data []byte, doRender bool) int { var lang *string beg, marker := p.isFencedCode(data, &lang, "") if beg == 0 || beg >= len(data) { @@ -678,7 +678,7 @@ func (p *parser) fencedCode(out *bytes.Buffer, data []byte, doRender bool) int { return beg } -func (p *parser) table(out *bytes.Buffer, data []byte) int { +func (p *parser) table(data []byte) int { var header bytes.Buffer i, columns := p.tableHeader(&header, data) if i == 0 { @@ -902,7 +902,7 @@ func (p *parser) terminateBlockquote(data []byte, beg, end int) bool { } // parse a blockquote fragment -func (p *parser) quote(out *bytes.Buffer, data []byte) int { +func (p *parser) quote(data []byte) int { var raw bytes.Buffer beg, end := 0, 0 for beg < len(data) { @@ -948,7 +948,7 @@ func (p *parser) codePrefix(data []byte) int { return 0 } -func (p *parser) code(out *bytes.Buffer, data []byte) int { +func (p *parser) code(data []byte) int { var work bytes.Buffer i := 0 @@ -1047,7 +1047,7 @@ func (p *parser) dliPrefix(data []byte) int { } // parse ordered or unordered list block -func (p *parser) list(out *bytes.Buffer, data []byte, flags ListType) int { +func (p *parser) list(data []byte, flags ListType) int { i := 0 flags |= ListItemBeginningOfList p.r.BeginList(out, flags) @@ -1067,7 +1067,7 @@ func (p *parser) list(out *bytes.Buffer, data []byte, flags ListType) int { // Parse a single list item. // Assumes initial prefix is already removed if this is a sublist. -func (p *parser) listItem(out *bytes.Buffer, data []byte, flags *ListType) int { +func (p *parser) listItem(data []byte, flags *ListType) int { // keep track of the indentation of the first line itemIndent := 0 for itemIndent < 3 && data[itemIndent] == ' ' { @@ -1250,7 +1250,7 @@ gatherlines: } // render a single paragraph that has already been parsed out -func (p *parser) renderParagraph(out *bytes.Buffer, data []byte) { +func (p *parser) renderParagraph(data []byte) { if len(data) == 0 { return } @@ -1274,7 +1274,7 @@ func (p *parser) renderParagraph(out *bytes.Buffer, data []byte) { p.r.EndParagraph(out) } -func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { +func (p *parser) paragraph(data []byte) int { // prev: index of 1st char of previous line // line: index of 1st char of current line // i: index of cursor/end of current line diff --git a/inline.go b/inline.go index 08b0d71..043ceb5 100644 --- a/inline.go +++ b/inline.go @@ -29,7 +29,7 @@ var ( // data is the complete block being rendered // offset is the number of valid chars before the current cursor -func (p *parser) inline(out *bytes.Buffer, data []byte) { +func (p *parser) inline(data []byte) { // this is called recursively: enforce a maximum depth if p.nesting >= p.maxNesting { return @@ -99,7 +99,7 @@ func (p *parser) inline(out *bytes.Buffer, data []byte) { } // single and double emphasis parsing -func emphasis(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func emphasis(p *parser, data []byte, offset int) int { data = data[offset:] c := data[0] ret := 0 @@ -142,7 +142,7 @@ func emphasis(p *parser, out *bytes.Buffer, data []byte, offset int) int { return 0 } -func codeSpan(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func codeSpan(p *parser, data []byte, offset int) int { data = data[offset:] nb := 0 @@ -188,7 +188,7 @@ func codeSpan(p *parser, out *bytes.Buffer, data []byte, offset int) int { } // newline preceded by two spaces becomes
-func maybeLineBreak(p *parser, out *bytes.Buffer, data []byte, offset int) (int, bool) { +func maybeLineBreak(p *parser, data []byte, offset int) (int, bool) { origOffset := offset for offset < len(data) && data[offset] == ' ' { offset++ @@ -203,7 +203,7 @@ func maybeLineBreak(p *parser, out *bytes.Buffer, data []byte, offset int) (int, } // newline without two spaces works when HardLineBreak is enabled -func lineBreak(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func lineBreak(p *parser, data []byte, offset int) int { if p.flags&HardLineBreak != 0 { p.r.LineBreak(out) return 1 @@ -227,14 +227,14 @@ func isReferenceStyleLink(data []byte, pos int, t linkType) bool { return pos < len(data)-1 && data[pos] == '[' && data[pos+1] != '^' } -func maybeImage(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func maybeImage(p *parser, data []byte, offset int) int { if offset < len(data)-1 && data[offset+1] == '[' { return link(p, out, data, offset) } return 0 } -func maybeInlineFootnote(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func maybeInlineFootnote(p *parser, data []byte, offset int) int { if offset < len(data)-1 && data[offset+1] == '[' { return link(p, out, data, offset) } @@ -242,7 +242,7 @@ func maybeInlineFootnote(p *parser, out *bytes.Buffer, data []byte, offset int) } // '[': parse a link or an image or a footnote -func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func link(p *parser, data []byte, offset int) int { // no links allowed inside regular links, footnote, and deferred footnotes if p.insideLink && (offset > 0 && data[offset-1] == '[' || len(data)-1 > offset && data[offset+1] == '^') { return 0 @@ -595,7 +595,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { return i } -func (p *parser) inlineHtmlComment(out *bytes.Buffer, data []byte) int { +func (p *parser) inlineHtmlComment(data []byte) int { if len(data) < 5 { return 0 } @@ -615,7 +615,7 @@ func (p *parser) inlineHtmlComment(out *bytes.Buffer, data []byte) int { } // '<' when tags or autolinks are allowed -func leftAngle(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func leftAngle(p *parser, data []byte, offset int) int { data = data[offset:] altype := LinkTypeNotAutolink end := tagLength(data, &altype) @@ -640,7 +640,7 @@ func leftAngle(p *parser, out *bytes.Buffer, data []byte, offset int) int { // '\\' backslash escape var escapeChars = []byte("\\`*_{}[]()#+-.!:|&<>~") -func escape(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func escape(p *parser, data []byte, offset int) int { data = data[offset:] if len(data) > 1 { @@ -681,7 +681,7 @@ func unescapeText(ob *bytes.Buffer, src []byte) { // '&' escaped when it doesn't belong to an entity // valid entities are assumed to be anything matching &#?[A-Za-z0-9]+; -func entity(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func entity(p *parser, data []byte, offset int) int { data = data[offset:] end := 1 @@ -710,7 +710,7 @@ func linkEndsWithEntity(data []byte, linkEnd int) bool { return entityRanges != nil && entityRanges[len(entityRanges)-1][1] == linkEnd } -func maybeAutoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func maybeAutoLink(p *parser, data []byte, offset int) int { // quick check to rule out most false hits if p.insideLink || len(data) < offset+6 { // 6 is the len() of the shortest prefix below return 0 @@ -735,7 +735,7 @@ func maybeAutoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int { return 0 } -func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int { +func autoLink(p *parser, data []byte, offset int) int { // Now a more expensive check to see if we're not inside an anchor element anchorStart := offset offsetFromAnchor := 0 @@ -1068,7 +1068,7 @@ func helperFindEmphChar(data []byte, c byte) int { return 0 } -func helperEmphasis(p *parser, out *bytes.Buffer, data []byte, c byte) int { +func helperEmphasis(p *parser, data []byte, c byte) int { i := 0 // skip one symbol if coming from emph3 @@ -1109,7 +1109,7 @@ func helperEmphasis(p *parser, out *bytes.Buffer, data []byte, c byte) int { return 0 } -func helperDoubleEmphasis(p *parser, out *bytes.Buffer, data []byte, c byte) int { +func helperDoubleEmphasis(p *parser, data []byte, c byte) int { i := 0 for i < len(data) { @@ -1138,7 +1138,7 @@ func helperDoubleEmphasis(p *parser, out *bytes.Buffer, data []byte, c byte) int return 0 } -func helperTripleEmphasis(p *parser, out *bytes.Buffer, data []byte, offset int, c byte) int { +func helperTripleEmphasis(p *parser, data []byte, offset int, c byte) int { i := 0 origData := data data = data[offset:] diff --git a/markdown.go b/markdown.go index 4ad3f3a..fdffd54 100644 --- a/markdown.go +++ b/markdown.go @@ -206,7 +206,7 @@ type Renderer interface { // Callback functions for inline parsing. One such function is defined // for each character that triggers a response when parsing inline data. -type inlineParser func(p *parser, out *bytes.Buffer, data []byte, offset int) int +type inlineParser func(p *parser, data []byte, offset int) int // Parser holds runtime state used by the parser. // This is constructed by the Markdown function.