Remove 'out' parameter from parser funcs
This only removes the parameter from declarations, everything is broken at the moment.
This commit is contained in:
parent
6e42506fcc
commit
7ec50399c3
28
block.go
28
block.go
|
@ -22,7 +22,7 @@ import (
|
||||||
// Parse block-level data.
|
// Parse block-level data.
|
||||||
// Note: this function and many that it calls assume that
|
// Note: this function and many that it calls assume that
|
||||||
// the input buffer ends with a newline.
|
// 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' {
|
if len(data) == 0 || data[len(data)-1] != '\n' {
|
||||||
panic("block input is missing terminating newline")
|
panic("block input is missing terminating newline")
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ func (p *parser) isPrefixHeader(data []byte) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int {
|
func (p *parser) prefixHeader(data []byte) int {
|
||||||
level := 0
|
level := 0
|
||||||
for level < 6 && data[level] == '#' {
|
for level < 6 && data[level] == '#' {
|
||||||
level++
|
level++
|
||||||
|
@ -278,7 +278,7 @@ func (p *parser) isUnderlinedHeader(data []byte) int {
|
||||||
return 0
|
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] != '%' {
|
if data[0] != '%' {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ func (p *parser) titleBlock(out *bytes.Buffer, data []byte, doRender bool) int {
|
||||||
return len(data)
|
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
|
var i, j int
|
||||||
|
|
||||||
// identify the opening tag
|
// identify the opening tag
|
||||||
|
@ -396,7 +396,7 @@ func (p *parser) html(out *bytes.Buffer, data []byte, doRender bool) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTML comment, lax form
|
// 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)
|
i := p.inlineHtmlComment(out, data)
|
||||||
// needs to end with a blank line
|
// needs to end with a blank line
|
||||||
if j := p.isEmpty(data[i:]); j > 0 {
|
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
|
// 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') {
|
if data[0] != '<' || (data[1] != 'h' && data[1] != 'H') || (data[2] != 'r' && data[2] != 'R') {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -632,7 +632,7 @@ func (p *parser) isFencedCode(data []byte, syntax **string, oldmarker string) (s
|
||||||
return
|
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
|
var lang *string
|
||||||
beg, marker := p.isFencedCode(data, &lang, "")
|
beg, marker := p.isFencedCode(data, &lang, "")
|
||||||
if beg == 0 || beg >= len(data) {
|
if beg == 0 || beg >= len(data) {
|
||||||
|
@ -678,7 +678,7 @@ func (p *parser) fencedCode(out *bytes.Buffer, data []byte, doRender bool) int {
|
||||||
return beg
|
return beg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) table(out *bytes.Buffer, data []byte) int {
|
func (p *parser) table(data []byte) int {
|
||||||
var header bytes.Buffer
|
var header bytes.Buffer
|
||||||
i, columns := p.tableHeader(&header, data)
|
i, columns := p.tableHeader(&header, data)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
@ -902,7 +902,7 @@ func (p *parser) terminateBlockquote(data []byte, beg, end int) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse a blockquote fragment
|
// 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
|
var raw bytes.Buffer
|
||||||
beg, end := 0, 0
|
beg, end := 0, 0
|
||||||
for beg < len(data) {
|
for beg < len(data) {
|
||||||
|
@ -948,7 +948,7 @@ func (p *parser) codePrefix(data []byte) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) code(out *bytes.Buffer, data []byte) int {
|
func (p *parser) code(data []byte) int {
|
||||||
var work bytes.Buffer
|
var work bytes.Buffer
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
|
@ -1047,7 +1047,7 @@ func (p *parser) dliPrefix(data []byte) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse ordered or unordered list block
|
// 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
|
i := 0
|
||||||
flags |= ListItemBeginningOfList
|
flags |= ListItemBeginningOfList
|
||||||
p.r.BeginList(out, flags)
|
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.
|
// Parse a single list item.
|
||||||
// Assumes initial prefix is already removed if this is a sublist.
|
// 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
|
// keep track of the indentation of the first line
|
||||||
itemIndent := 0
|
itemIndent := 0
|
||||||
for itemIndent < 3 && data[itemIndent] == ' ' {
|
for itemIndent < 3 && data[itemIndent] == ' ' {
|
||||||
|
@ -1250,7 +1250,7 @@ gatherlines:
|
||||||
}
|
}
|
||||||
|
|
||||||
// render a single paragraph that has already been parsed out
|
// 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 {
|
if len(data) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1274,7 +1274,7 @@ func (p *parser) renderParagraph(out *bytes.Buffer, data []byte) {
|
||||||
p.r.EndParagraph(out)
|
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
|
// prev: index of 1st char of previous line
|
||||||
// line: index of 1st char of current line
|
// line: index of 1st char of current line
|
||||||
// i: index of cursor/end of current line
|
// i: index of cursor/end of current line
|
||||||
|
|
34
inline.go
34
inline.go
|
@ -29,7 +29,7 @@ var (
|
||||||
// data is the complete block being rendered
|
// data is the complete block being rendered
|
||||||
// offset is the number of valid chars before the current cursor
|
// 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
|
// this is called recursively: enforce a maximum depth
|
||||||
if p.nesting >= p.maxNesting {
|
if p.nesting >= p.maxNesting {
|
||||||
return
|
return
|
||||||
|
@ -99,7 +99,7 @@ func (p *parser) inline(out *bytes.Buffer, data []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// single and double emphasis parsing
|
// 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:]
|
data = data[offset:]
|
||||||
c := data[0]
|
c := data[0]
|
||||||
ret := 0
|
ret := 0
|
||||||
|
@ -142,7 +142,7 @@ func emphasis(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
||||||
return 0
|
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:]
|
data = data[offset:]
|
||||||
|
|
||||||
nb := 0
|
nb := 0
|
||||||
|
@ -188,7 +188,7 @@ func codeSpan(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newline preceded by two spaces becomes <br>
|
// newline preceded by two spaces becomes <br>
|
||||||
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
|
origOffset := offset
|
||||||
for offset < len(data) && data[offset] == ' ' {
|
for offset < len(data) && data[offset] == ' ' {
|
||||||
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
|
// 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 {
|
if p.flags&HardLineBreak != 0 {
|
||||||
p.r.LineBreak(out)
|
p.r.LineBreak(out)
|
||||||
return 1
|
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] != '^'
|
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] == '[' {
|
if offset < len(data)-1 && data[offset+1] == '[' {
|
||||||
return link(p, out, data, offset)
|
return link(p, out, data, offset)
|
||||||
}
|
}
|
||||||
return 0
|
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] == '[' {
|
if offset < len(data)-1 && data[offset+1] == '[' {
|
||||||
return link(p, out, data, offset)
|
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
|
// '[': 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
|
// 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] == '^') {
|
if p.insideLink && (offset > 0 && data[offset-1] == '[' || len(data)-1 > offset && data[offset+1] == '^') {
|
||||||
return 0
|
return 0
|
||||||
|
@ -595,7 +595,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) inlineHtmlComment(out *bytes.Buffer, data []byte) int {
|
func (p *parser) inlineHtmlComment(data []byte) int {
|
||||||
if len(data) < 5 {
|
if len(data) < 5 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -615,7 +615,7 @@ func (p *parser) inlineHtmlComment(out *bytes.Buffer, data []byte) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// '<' when tags or autolinks are allowed
|
// '<' 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:]
|
data = data[offset:]
|
||||||
altype := LinkTypeNotAutolink
|
altype := LinkTypeNotAutolink
|
||||||
end := tagLength(data, &altype)
|
end := tagLength(data, &altype)
|
||||||
|
@ -640,7 +640,7 @@ func leftAngle(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
||||||
// '\\' backslash escape
|
// '\\' backslash escape
|
||||||
var escapeChars = []byte("\\`*_{}[]()#+-.!:|&<>~")
|
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:]
|
data = data[offset:]
|
||||||
|
|
||||||
if len(data) > 1 {
|
if len(data) > 1 {
|
||||||
|
@ -681,7 +681,7 @@ func unescapeText(ob *bytes.Buffer, src []byte) {
|
||||||
|
|
||||||
// '&' escaped when it doesn't belong to an entity
|
// '&' escaped when it doesn't belong to an entity
|
||||||
// valid entities are assumed to be anything matching &#?[A-Za-z0-9]+;
|
// 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:]
|
data = data[offset:]
|
||||||
|
|
||||||
end := 1
|
end := 1
|
||||||
|
@ -710,7 +710,7 @@ func linkEndsWithEntity(data []byte, linkEnd int) bool {
|
||||||
return entityRanges != nil && entityRanges[len(entityRanges)-1][1] == linkEnd
|
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
|
// quick check to rule out most false hits
|
||||||
if p.insideLink || len(data) < offset+6 { // 6 is the len() of the shortest prefix below
|
if p.insideLink || len(data) < offset+6 { // 6 is the len() of the shortest prefix below
|
||||||
return 0
|
return 0
|
||||||
|
@ -735,7 +735,7 @@ func maybeAutoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
||||||
return 0
|
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
|
// Now a more expensive check to see if we're not inside an anchor element
|
||||||
anchorStart := offset
|
anchorStart := offset
|
||||||
offsetFromAnchor := 0
|
offsetFromAnchor := 0
|
||||||
|
@ -1068,7 +1068,7 @@ func helperFindEmphChar(data []byte, c byte) int {
|
||||||
return 0
|
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
|
i := 0
|
||||||
|
|
||||||
// skip one symbol if coming from emph3
|
// 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
|
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
|
i := 0
|
||||||
|
|
||||||
for i < len(data) {
|
for i < len(data) {
|
||||||
|
@ -1138,7 +1138,7 @@ func helperDoubleEmphasis(p *parser, out *bytes.Buffer, data []byte, c byte) int
|
||||||
return 0
|
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
|
i := 0
|
||||||
origData := data
|
origData := data
|
||||||
data = data[offset:]
|
data = data[offset:]
|
||||||
|
|
|
@ -206,7 +206,7 @@ type Renderer interface {
|
||||||
|
|
||||||
// Callback functions for inline parsing. One such function is defined
|
// Callback functions for inline parsing. One such function is defined
|
||||||
// for each character that triggers a response when parsing inline data.
|
// 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.
|
// Parser holds runtime state used by the parser.
|
||||||
// This is constructed by the Markdown function.
|
// This is constructed by the Markdown function.
|
||||||
|
|
Loading…
Reference in New Issue