From 9d23b68fa51d84855bbfaff1d12a449a53a25268 Mon Sep 17 00:00:00 2001 From: Russ Ross Date: Mon, 30 May 2011 21:44:52 -0600 Subject: [PATCH] export all names from Renderer struct This enables new back-ends that are not part of the package Basically a big search-and-replace for this commit --- README.md | 4 +- block.go | 80 +++++++++++++++--------------- html.go | 138 ++++++++++++++++++++++++++-------------------------- inline.go | 66 ++++++++++++------------- latex.go | 64 ++++++++++++------------ markdown.go | 84 ++++++++++++++++---------------- 6 files changed, 218 insertions(+), 218 deletions(-) diff --git a/README.md b/README.md index 54851f9..0e91322 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ All features of upskirt are supported, including: errors that were present in the C code). * Good performance. I have not done rigorous benchmarking, but - informal testing suggests it is around 8x slower than upskirt. - This is still an ugly, direct translation from the C code, so + informal testing suggests it is around 3.5x slower than upskirt. + This is an ugly, direct translation from the C code, so the difference is unlikely to be related to differences in coding style. There is a lot of bounds checking that is duplicated (by user code for the application and again by code diff --git a/block.go b/block.go index e78c0ce..f1eef15 100644 --- a/block.go +++ b/block.go @@ -26,7 +26,7 @@ func parseBlock(out *bytes.Buffer, rndr *render, data []byte) { data = data[blockPrefixHeader(out, rndr, data):] continue } - if data[0] == '<' && rndr.mk.blockhtml != nil { + if data[0] == '<' && rndr.mk.BlockHtml != nil { if i := blockHtml(out, rndr, data, true); i > 0 { data = data[i:] continue @@ -36,9 +36,9 @@ func parseBlock(out *bytes.Buffer, rndr *render, data []byte) { data = data[i:] continue } - if isHrule(data) { - if rndr.mk.hrule != nil { - rndr.mk.hrule(out, rndr.mk.opaque) + if isHRule(data) { + if rndr.mk.HRule != nil { + rndr.mk.HRule(out, rndr.mk.Opaque) } var i int for i = 0; i < len(data) && data[i] != '\n'; i++ { @@ -118,8 +118,8 @@ func blockPrefixHeader(out *bytes.Buffer, rndr *render, data []byte) int { if end > i { work := bytes.NewBuffer(nil) parseInline(work, rndr, data[i:end]) - if rndr.mk.header != nil { - rndr.mk.header(out, work.Bytes(), level, rndr.mk.opaque) + if rndr.mk.Header != nil { + rndr.mk.Header(out, work.Bytes(), level, rndr.mk.Opaque) } } return skip @@ -186,8 +186,8 @@ func blockHtml(out *bytes.Buffer, rndr *render, data []byte, do_render bool) int if j > 0 { size := i + j - if do_render && rndr.mk.blockhtml != nil { - rndr.mk.blockhtml(out, data[:size], rndr.mk.opaque) + if do_render && rndr.mk.BlockHtml != nil { + rndr.mk.BlockHtml(out, data[:size], rndr.mk.Opaque) } return size } @@ -205,8 +205,8 @@ func blockHtml(out *bytes.Buffer, rndr *render, data []byte, do_render bool) int j = isEmpty(data[i:]) if j > 0 { size := i + j - if do_render && rndr.mk.blockhtml != nil { - rndr.mk.blockhtml(out, data[:size], rndr.mk.opaque) + if do_render && rndr.mk.BlockHtml != nil { + rndr.mk.BlockHtml(out, data[:size], rndr.mk.Opaque) } return size } @@ -251,8 +251,8 @@ func blockHtml(out *bytes.Buffer, rndr *render, data []byte, do_render bool) int } // the end of the block has been found - if do_render && rndr.mk.blockhtml != nil { - rndr.mk.blockhtml(out, data[:i], rndr.mk.opaque) + if do_render && rndr.mk.BlockHtml != nil { + rndr.mk.BlockHtml(out, data[:i], rndr.mk.Opaque) } return i @@ -317,7 +317,7 @@ func isEmpty(data []byte) int { return i + 1 } -func isHrule(data []byte) bool { +func isHRule(data []byte) bool { // skip initial spaces if len(data) < 3 { return false @@ -478,13 +478,13 @@ func blockFencedCode(out *bytes.Buffer, rndr *render, data []byte) int { work.WriteByte('\n') } - if rndr.mk.blockcode != nil { + if rndr.mk.BlockCode != nil { syntax := "" if lang != nil { syntax = *lang } - rndr.mk.blockcode(out, work.Bytes(), syntax, rndr.mk.opaque) + rndr.mk.BlockCode(out, work.Bytes(), syntax, rndr.mk.Opaque) } return beg @@ -513,8 +513,8 @@ func blockTable(out *bytes.Buffer, rndr *render, data []byte) int { i++ } - if rndr.mk.table != nil { - rndr.mk.table(out, header_work.Bytes(), body_work.Bytes(), col_data, rndr.mk.opaque) + if rndr.mk.Table != nil { + rndr.mk.Table(out, header_work.Bytes(), body_work.Bytes(), col_data, rndr.mk.Opaque) } } @@ -635,12 +635,12 @@ func blockTableRow(out *bytes.Buffer, rndr *render, data []byte, columns int, co cell_work := bytes.NewBuffer(nil) parseInline(cell_work, rndr, data[cell_start:cell_end+1]) - if rndr.mk.tableCell != nil { + if rndr.mk.TableCell != nil { cdata := 0 if col < len(col_data) { cdata = col_data[col] } - rndr.mk.tableCell(row_work, cell_work.Bytes(), cdata, rndr.mk.opaque) + rndr.mk.TableCell(row_work, cell_work.Bytes(), cdata, rndr.mk.Opaque) } i++ @@ -648,17 +648,17 @@ func blockTableRow(out *bytes.Buffer, rndr *render, data []byte, columns int, co for ; col < columns; col++ { empty_cell := []byte{} - if rndr.mk.tableCell != nil { + if rndr.mk.TableCell != nil { cdata := 0 if col < len(col_data) { cdata = col_data[col] } - rndr.mk.tableCell(row_work, empty_cell, cdata, rndr.mk.opaque) + rndr.mk.TableCell(row_work, empty_cell, cdata, rndr.mk.Opaque) } } - if rndr.mk.tableRow != nil { - rndr.mk.tableRow(out, row_work.Bytes(), rndr.mk.opaque) + if rndr.mk.TableRow != nil { + rndr.mk.TableRow(out, row_work.Bytes(), rndr.mk.Opaque) } } @@ -702,8 +702,8 @@ func blockQuote(out *bytes.Buffer, rndr *render, data []byte) int { } parseBlock(block, rndr, work.Bytes()) - if rndr.mk.blockquote != nil { - rndr.mk.blockquote(out, block.Bytes(), rndr.mk.opaque) + if rndr.mk.BlockQuote != nil { + rndr.mk.BlockQuote(out, block.Bytes(), rndr.mk.Opaque) } return end } @@ -759,8 +759,8 @@ func blockCode(out *bytes.Buffer, rndr *render, data []byte) int { work.WriteByte('\n') - if rndr.mk.blockcode != nil { - rndr.mk.blockcode(out, work.Bytes(), "", rndr.mk.opaque) + if rndr.mk.BlockCode != nil { + rndr.mk.BlockCode(out, work.Bytes(), "", rndr.mk.Opaque) } return beg @@ -810,8 +810,8 @@ func blockList(out *bytes.Buffer, rndr *render, data []byte, flags int) int { } } - if rndr.mk.list != nil { - rndr.mk.list(out, work.Bytes(), flags, rndr.mk.opaque) + if rndr.mk.List != nil { + rndr.mk.List(out, work.Bytes(), flags, rndr.mk.Opaque) } return i } @@ -883,7 +883,7 @@ func blockListItem(out *bytes.Buffer, rndr *render, data []byte, flags *int) int // check for a new item chunk := data[beg+i : end] - if (blockUliPrefix(chunk) > 0 && !isHrule(chunk)) || blockOliPrefix(chunk) > 0 { + if (blockUliPrefix(chunk) > 0 && !isHRule(chunk)) || blockOliPrefix(chunk) > 0 { if in_empty { has_inside_empty = true } @@ -940,8 +940,8 @@ func blockListItem(out *bytes.Buffer, rndr *render, data []byte, flags *int) int } // render li itself - if rndr.mk.listitem != nil { - rndr.mk.listitem(out, inter.Bytes(), *flags, rndr.mk.opaque) + if rndr.mk.ListItem != nil { + rndr.mk.ListItem(out, inter.Bytes(), *flags, rndr.mk.Opaque) } return beg @@ -962,13 +962,13 @@ func blockParagraph(out *bytes.Buffer, rndr *render, data []byte) int { } if rndr.flags&EXTENSION_LAX_HTML_BLOCKS != 0 { - if data[i] == '<' && rndr.mk.blockhtml != nil && blockHtml(out, rndr, data[i:], false) > 0 { + if data[i] == '<' && rndr.mk.BlockHtml != nil && blockHtml(out, rndr, data[i:], false) > 0 { end = i break } } - if isPrefixHeader(rndr, data[i:]) || isHrule(data[i:]) { + if isPrefixHeader(rndr, data[i:]) || isHRule(data[i:]) { end = i break } @@ -985,8 +985,8 @@ func blockParagraph(out *bytes.Buffer, rndr *render, data []byte) int { if level == 0 { tmp := bytes.NewBuffer(nil) parseInline(tmp, rndr, work[:size]) - if rndr.mk.paragraph != nil { - rndr.mk.paragraph(out, tmp.Bytes(), rndr.mk.opaque) + if rndr.mk.Paragraph != nil { + rndr.mk.Paragraph(out, tmp.Bytes(), rndr.mk.Opaque) } } else { if size > 0 { @@ -1006,8 +1006,8 @@ func blockParagraph(out *bytes.Buffer, rndr *render, data []byte) int { if size > 0 { tmp := bytes.NewBuffer(nil) parseInline(tmp, rndr, work[:size]) - if rndr.mk.paragraph != nil { - rndr.mk.paragraph(out, tmp.Bytes(), rndr.mk.opaque) + if rndr.mk.Paragraph != nil { + rndr.mk.Paragraph(out, tmp.Bytes(), rndr.mk.Opaque) } work = work[beg:] @@ -1020,8 +1020,8 @@ func blockParagraph(out *bytes.Buffer, rndr *render, data []byte) int { header_work := bytes.NewBuffer(nil) parseInline(header_work, rndr, work[:size]) - if rndr.mk.header != nil { - rndr.mk.header(out, header_work.Bytes(), level, rndr.mk.opaque) + if rndr.mk.Header != nil { + rndr.mk.Header(out, header_work.Bytes(), level, rndr.mk.Opaque) } } diff --git a/html.go b/html.go index 7b185b8..8ad41ce 100644 --- a/html.go +++ b/html.go @@ -36,87 +36,87 @@ const ( type htmlOptions struct { flags int - close_tag string // how to end singleton tags: usually " />\n", possibly ">\n" - toc_data struct { - header_count int - current_level int + closeTag string // how to end singleton tags: usually " />\n", possibly ">\n" + tocData struct { + headerCount int + currentLevel int } smartypants *SmartypantsRenderer } -var xhtml_close = " />\n" -var html_close = ">\n" +var xhtmlClose = " />\n" +var htmlClose = ">\n" func HtmlRenderer(flags int) *Renderer { // configure the rendering engine r := new(Renderer) if flags&HTML_GITHUB_BLOCKCODE == 0 { - r.blockcode = htmlBlockcode + r.BlockCode = htmlBlockCode } else { - r.blockcode = htmlBlockcodeGithub + r.BlockCode = htmlBlockCodeGithub } - r.blockquote = htmlBlockquote + r.BlockQuote = htmlBlockQuote if flags&HTML_SKIP_HTML == 0 { - r.blockhtml = htmlRawBlock + r.BlockHtml = htmlRawBlock } - r.header = htmlHeader - r.hrule = htmlHrule - r.list = htmlList - r.listitem = htmlListitem - r.paragraph = htmlParagraph - r.table = htmlTable - r.tableRow = htmlTableRow - r.tableCell = htmlTableCell + r.Header = htmlHeader + r.HRule = htmlHRule + r.List = htmlList + r.ListItem = htmlListItem + r.Paragraph = htmlParagraph + r.Table = htmlTable + r.TableRow = htmlTableRow + r.TableCell = htmlTableCell - r.autolink = htmlAutolink - r.codespan = htmlCodespan - r.doubleEmphasis = htmlDoubleEmphasis - r.emphasis = htmlEmphasis + r.AutoLink = htmlAutoLink + r.CodeSpan = htmlCodeSpan + r.DoubleEmphasis = htmlDoubleEmphasis + r.Emphasis = htmlEmphasis if flags&HTML_SKIP_IMAGES == 0 { - r.image = htmlImage + r.Image = htmlImage } - r.linebreak = htmlLinebreak + r.LineBreak = htmlLineBreak if flags&HTML_SKIP_LINKS == 0 { - r.link = htmlLink + r.Link = htmlLink } - r.rawHtmlTag = htmlRawTag - r.tripleEmphasis = htmlTripleEmphasis - r.strikethrough = htmlStrikethrough + r.RawHtmlTag = htmlRawTag + r.TripleEmphasis = htmlTripleEmphasis + r.StrikeThrough = htmlStrikeThrough var cb *SmartypantsRenderer if flags&HTML_USE_SMARTYPANTS == 0 { - r.normalText = htmlNormalText + r.NormalText = htmlNormalText } else { cb = Smartypants(flags) - r.normalText = htmlSmartypants + r.NormalText = htmlSmartypants } - close_tag := html_close + closeTag := htmlClose if flags&HTML_USE_XHTML != 0 { - close_tag = xhtml_close + closeTag = xhtmlClose } - r.opaque = &htmlOptions{flags: flags, close_tag: close_tag, smartypants: cb} + r.Opaque = &htmlOptions{flags: flags, closeTag: closeTag, smartypants: cb} return r } func HtmlTocRenderer(flags int) *Renderer { // configure the rendering engine r := new(Renderer) - r.header = htmlTocHeader + r.Header = htmlTocHeader - r.codespan = htmlCodespan - r.doubleEmphasis = htmlDoubleEmphasis - r.emphasis = htmlEmphasis - r.tripleEmphasis = htmlTripleEmphasis - r.strikethrough = htmlStrikethrough + r.CodeSpan = htmlCodeSpan + r.DoubleEmphasis = htmlDoubleEmphasis + r.Emphasis = htmlEmphasis + r.TripleEmphasis = htmlTripleEmphasis + r.StrikeThrough = htmlStrikeThrough - r.documentFooter = htmlTocFinalize + r.DocumentFooter = htmlTocFinalize - close_tag := ">\n" + closeTag := ">\n" if flags&HTML_USE_XHTML != 0 { - close_tag = " />\n" + closeTag = " />\n" } - r.opaque = &htmlOptions{flags: flags | HTML_TOC, close_tag: close_tag} + r.Opaque = &htmlOptions{flags: flags | HTML_TOC, closeTag: closeTag} return r } @@ -156,8 +156,8 @@ func htmlHeader(out *bytes.Buffer, text []byte, level int, opaque interface{}) { } if options.flags&HTML_TOC != 0 { - out.WriteString(fmt.Sprintf("", level, options.toc_data.header_count)) - options.toc_data.header_count++ + out.WriteString(fmt.Sprintf("", level, options.tocData.headerCount)) + options.tocData.headerCount++ } else { out.WriteString(fmt.Sprintf("", level)) } @@ -185,17 +185,17 @@ func htmlRawBlock(out *bytes.Buffer, text []byte, opaque interface{}) { out.WriteByte('\n') } -func htmlHrule(out *bytes.Buffer, opaque interface{}) { +func htmlHRule(out *bytes.Buffer, opaque interface{}) { options := opaque.(*htmlOptions) if out.Len() > 0 { out.WriteByte('\n') } out.WriteString(" 0 { out.WriteByte('\n') } @@ -255,7 +255,7 @@ func htmlBlockcode(out *bytes.Buffer, text []byte, lang string, opaque interface * E.g. * ~~~~ {.python .numbered} =>

  */
-func htmlBlockcodeGithub(out *bytes.Buffer, text []byte, lang string, opaque interface{}) {
+func htmlBlockCodeGithub(out *bytes.Buffer, text []byte, lang string, opaque interface{}) {
 	if out.Len() > 0 {
 		out.WriteByte('\n')
 	}
@@ -287,7 +287,7 @@ func htmlBlockcodeGithub(out *bytes.Buffer, text []byte, lang string, opaque int
 }
 
 
-func htmlBlockquote(out *bytes.Buffer, text []byte, opaque interface{}) {
+func htmlBlockQuote(out *bytes.Buffer, text []byte, opaque interface{}) {
 	out.WriteString("
\n") out.Write(text) out.WriteString("
") @@ -349,7 +349,7 @@ func htmlList(out *bytes.Buffer, text []byte, flags int, opaque interface{}) { } } -func htmlListitem(out *bytes.Buffer, text []byte, flags int, opaque interface{}) { +func htmlListItem(out *bytes.Buffer, text []byte, flags int, opaque interface{}) { out.WriteString("
  • ") size := len(text) for size > 0 && text[size-1] == '\n' { @@ -396,7 +396,7 @@ func htmlParagraph(out *bytes.Buffer, text []byte, opaque interface{}) { } out.WriteString("
    ") - out.WriteString(options.close_tag) + out.WriteString(options.closeTag) i++ } } else { @@ -405,7 +405,7 @@ func htmlParagraph(out *bytes.Buffer, text []byte, opaque interface{}) { out.WriteString("

    \n") } -func htmlAutolink(out *bytes.Buffer, link []byte, kind int, opaque interface{}) int { +func htmlAutoLink(out *bytes.Buffer, link []byte, kind int, opaque interface{}) int { options := opaque.(*htmlOptions) if len(link) == 0 { @@ -441,7 +441,7 @@ func htmlAutolink(out *bytes.Buffer, link []byte, kind int, opaque interface{}) return 1 } -func htmlCodespan(out *bytes.Buffer, text []byte, opaque interface{}) int { +func htmlCodeSpan(out *bytes.Buffer, text []byte, opaque interface{}) int { out.WriteString("") attrEscape(out, text) out.WriteString("") @@ -485,14 +485,14 @@ func htmlImage(out *bytes.Buffer, link []byte, title []byte, alt []byte, opaque } out.WriteByte('"') - out.WriteString(options.close_tag) + out.WriteString(options.closeTag) return 1 } -func htmlLinebreak(out *bytes.Buffer, opaque interface{}) int { +func htmlLineBreak(out *bytes.Buffer, opaque interface{}) int { options := opaque.(*htmlOptions) out.WriteString(" options.toc_data.current_level { - if options.toc_data.current_level > 0 { + for level > options.tocData.currentLevel { + if options.tocData.currentLevel > 0 { out.WriteString("
  • ") } out.WriteString("
      \n") - options.toc_data.current_level++ + options.tocData.currentLevel++ } - for level < options.toc_data.current_level { + for level < options.tocData.currentLevel { out.WriteString("
    ") - if options.toc_data.current_level > 1 { + if options.tocData.currentLevel > 1 { out.WriteString("
  • \n") } - options.toc_data.current_level-- + options.tocData.currentLevel-- } out.WriteString("
  • ") - options.toc_data.header_count++ + options.tocData.headerCount++ if len(text) > 0 { out.Write(text) @@ -592,12 +592,12 @@ func htmlTocHeader(out *bytes.Buffer, text []byte, level int, opaque interface{} func htmlTocFinalize(out *bytes.Buffer, opaque interface{}) { options := opaque.(*htmlOptions) - for options.toc_data.current_level > 1 { + for options.tocData.currentLevel > 1 { out.WriteString("
  • \n") - options.toc_data.current_level-- + options.tocData.currentLevel-- } - if options.toc_data.current_level > 0 { + if options.tocData.currentLevel > 0 { out.WriteString("\n") } } diff --git a/inline.go b/inline.go index 4925391..9e7852b 100644 --- a/inline.go +++ b/inline.go @@ -32,8 +32,8 @@ func parseInline(out *bytes.Buffer, rndr *render, data []byte) { end++ } - if rndr.mk.normalText != nil { - rndr.mk.normalText(out, data[i:end], rndr.mk.opaque) + if rndr.mk.NormalText != nil { + rndr.mk.NormalText(out, data[i:end], rndr.mk.Opaque) } else { out.Write(data[i:end]) } @@ -102,7 +102,7 @@ func inlineEmphasis(out *bytes.Buffer, rndr *render, data []byte, offset int) in return 0 } -func inlineCodespan(out *bytes.Buffer, rndr *render, data []byte, offset int) int { +func inlineCodeSpan(out *bytes.Buffer, rndr *render, data []byte, offset int) int { data = data[offset:] nb := 0 @@ -138,15 +138,15 @@ func inlineCodespan(out *bytes.Buffer, rndr *render, data []byte, offset int) in } // real code span - if rndr.mk.codespan == nil { + if rndr.mk.CodeSpan == nil { return 0 } if f_begin < f_end { - if rndr.mk.codespan(out, data[f_begin:f_end], rndr.mk.opaque) == 0 { + if rndr.mk.CodeSpan(out, data[f_begin:f_end], rndr.mk.Opaque) == 0 { end = 0 } } else { - if rndr.mk.codespan(out, nil, rndr.mk.opaque) == 0 { + if rndr.mk.CodeSpan(out, nil, rndr.mk.Opaque) == 0 { end = 0 } } @@ -156,7 +156,7 @@ func inlineCodespan(out *bytes.Buffer, rndr *render, data []byte, offset int) in } // '\n' preceded by two spaces -func inlineLinebreak(out *bytes.Buffer, rndr *render, data []byte, offset int) int { +func inlineLineBreak(out *bytes.Buffer, rndr *render, data []byte, offset int) int { if offset < 2 || data[offset-1] != ' ' || data[offset-2] != ' ' { return 0 } @@ -169,10 +169,10 @@ func inlineLinebreak(out *bytes.Buffer, rndr *render, data []byte, offset int) i } out.Truncate(end) - if rndr.mk.linebreak == nil { + if rndr.mk.LineBreak == nil { return 0 } - if rndr.mk.linebreak(out, rndr.mk.opaque) > 0 { + if rndr.mk.LineBreak(out, rndr.mk.Opaque) > 0 { return 1 } else { return 0 @@ -192,7 +192,7 @@ func inlineLink(out *bytes.Buffer, rndr *render, data []byte, offset int) int { text_has_nl := false // check whether the correct renderer exists - if (isImg && rndr.mk.image == nil) || (!isImg && rndr.mk.link == nil) { + if (isImg && rndr.mk.Image == nil) || (!isImg && rndr.mk.Link == nil) { return 0 } @@ -428,9 +428,9 @@ func inlineLink(out *bytes.Buffer, rndr *render, data []byte, offset int) int { out.Truncate(outSize - 1) } - ret = rndr.mk.image(out, u_link, title, content.Bytes(), rndr.mk.opaque) + ret = rndr.mk.Image(out, u_link, title, content.Bytes(), rndr.mk.Opaque) } else { - ret = rndr.mk.link(out, u_link, title, content.Bytes(), rndr.mk.opaque) + ret = rndr.mk.Link(out, u_link, title, content.Bytes(), rndr.mk.Opaque) } if ret > 0 { @@ -440,7 +440,7 @@ func inlineLink(out *bytes.Buffer, rndr *render, data []byte, offset int) int { } // '<' when tags or autolinks are allowed -func inlineLangle(out *bytes.Buffer, rndr *render, data []byte, offset int) int { +func inlineLAngle(out *bytes.Buffer, rndr *render, data []byte, offset int) int { data = data[offset:] altype := LINK_TYPE_NOT_AUTOLINK end := tagLength(data, &altype) @@ -448,12 +448,12 @@ func inlineLangle(out *bytes.Buffer, rndr *render, data []byte, offset int) int if end > 2 { switch { - case rndr.mk.autolink != nil && altype != LINK_TYPE_NOT_AUTOLINK: + case rndr.mk.AutoLink != nil && altype != LINK_TYPE_NOT_AUTOLINK: u_link := bytes.NewBuffer(nil) unescapeText(u_link, data[1:end+1-2]) - ret = rndr.mk.autolink(out, u_link.Bytes(), altype, rndr.mk.opaque) - case rndr.mk.rawHtmlTag != nil: - ret = rndr.mk.rawHtmlTag(out, data[:end], rndr.mk.opaque) + ret = rndr.mk.AutoLink(out, u_link.Bytes(), altype, rndr.mk.Opaque) + case rndr.mk.RawHtmlTag != nil: + ret = rndr.mk.RawHtmlTag(out, data[:end], rndr.mk.Opaque) } } @@ -474,8 +474,8 @@ func inlineEscape(out *bytes.Buffer, rndr *render, data []byte, offset int) int return 0 } - if rndr.mk.normalText != nil { - rndr.mk.normalText(out, data[1:2], rndr.mk.opaque) + if rndr.mk.NormalText != nil { + rndr.mk.NormalText(out, data[1:2], rndr.mk.Opaque) } else { out.WriteByte(data[1]) } @@ -526,8 +526,8 @@ func inlineEntity(out *bytes.Buffer, rndr *render, data []byte, offset int) int return 0 // lone '&' } - if rndr.mk.entity != nil { - rndr.mk.entity(out, data[:end], rndr.mk.opaque) + if rndr.mk.Entity != nil { + rndr.mk.Entity(out, data[:end], rndr.mk.Opaque) } else { out.Write(data[:end]) } @@ -535,7 +535,7 @@ func inlineEntity(out *bytes.Buffer, rndr *render, data []byte, offset int) int return end } -func inlineAutolink(out *bytes.Buffer, rndr *render, data []byte, offset int) int { +func inlineAutoLink(out *bytes.Buffer, rndr *render, data []byte, offset int) int { // quick check to rule out most false hits on ':' if len(data) < offset + 3 || data[offset+1] != '/' || data[offset+2] != '/' { return 0 @@ -631,11 +631,11 @@ func inlineAutolink(out *bytes.Buffer, rndr *render, data []byte, offset int) in out.Truncate(len(out.Bytes()) - rewind) } - if rndr.mk.autolink != nil { + if rndr.mk.AutoLink != nil { u_link := bytes.NewBuffer(nil) unescapeText(u_link, data[:link_end]) - rndr.mk.autolink(out, u_link.Bytes(), LINK_TYPE_NORMAL, rndr.mk.opaque) + rndr.mk.AutoLink(out, u_link.Bytes(), LINK_TYPE_NORMAL, rndr.mk.Opaque) } return link_end - rewind @@ -687,7 +687,7 @@ func tagLength(data []byte, autolink *int) int { } if i > 1 && data[i] == '@' { - if j = isMailtoAutolink(data[i:]); j != 0 { + if j = isMailtoAutoLink(data[i:]); j != 0 { *autolink = LINK_TYPE_EMAIL return i + j } @@ -741,7 +741,7 @@ func tagLength(data []byte, autolink *int) int { // look for the address part of a mail autolink and '>' // this is less strict than the original markdown e-mail address matching -func isMailtoAutolink(data []byte) int { +func isMailtoAutoLink(data []byte) int { nb := 0 // address is assumed to be: [-@._a-zA-Z0-9]+ with exactly one '@' @@ -852,7 +852,7 @@ func inlineHelperFindEmphChar(data []byte, c byte) int { func inlineHelperEmph1(out *bytes.Buffer, rndr *render, data []byte, c byte) int { i := 0 - if rndr.mk.emphasis == nil { + if rndr.mk.Emphasis == nil { return 0 } @@ -886,7 +886,7 @@ func inlineHelperEmph1(out *bytes.Buffer, rndr *render, data []byte, c byte) int work := bytes.NewBuffer(nil) parseInline(work, rndr, data[:i]) - r := rndr.mk.emphasis(out, work.Bytes(), rndr.mk.opaque) + r := rndr.mk.Emphasis(out, work.Bytes(), rndr.mk.Opaque) if r > 0 { return i + 1 } else { @@ -899,9 +899,9 @@ func inlineHelperEmph1(out *bytes.Buffer, rndr *render, data []byte, c byte) int } func inlineHelperEmph2(out *bytes.Buffer, rndr *render, data []byte, c byte) int { - render_method := rndr.mk.doubleEmphasis + render_method := rndr.mk.DoubleEmphasis if c == '~' { - render_method = rndr.mk.strikethrough + render_method = rndr.mk.StrikeThrough } if render_method == nil { @@ -920,7 +920,7 @@ func inlineHelperEmph2(out *bytes.Buffer, rndr *render, data []byte, c byte) int if i+1 < len(data) && data[i] == c && data[i+1] == c && i > 0 && !isspace(data[i-1]) { work := bytes.NewBuffer(nil) parseInline(work, rndr, data[:i]) - r := render_method(out, work.Bytes(), rndr.mk.opaque) + r := render_method(out, work.Bytes(), rndr.mk.Opaque) if r > 0 { return i + 2 } else { @@ -950,12 +950,12 @@ func inlineHelperEmph3(out *bytes.Buffer, rndr *render, data []byte, offset int, } switch { - case (i+2 < len(data) && data[i+1] == c && data[i+2] == c && rndr.mk.tripleEmphasis != nil): + case (i+2 < len(data) && data[i+1] == c && data[i+2] == c && rndr.mk.TripleEmphasis != nil): // triple symbol found work := bytes.NewBuffer(nil) parseInline(work, rndr, data[:i]) - r := rndr.mk.tripleEmphasis(out, work.Bytes(), rndr.mk.opaque) + r := rndr.mk.TripleEmphasis(out, work.Bytes(), rndr.mk.Opaque) if r > 0 { return i + 3 } else { diff --git a/latex.go b/latex.go index 67eae70..00a98f0 100644 --- a/latex.go +++ b/latex.go @@ -19,40 +19,40 @@ import ( func LatexRenderer(flags int) *Renderer { // block-level rendering r := new(Renderer) - r.blockcode = latexBlockcode - r.blockquote = latexBlockquote - //r.blockhtml = ? - r.header = latexHeader - r.hrule = latexHrule - r.list = latexList - r.listitem = latexListitem - r.paragraph = latexParagraph - r.table = latexTable - r.tableRow = latexTableRow - r.tableCell = latexTableCell + r.BlockCode = latexBlockCode + r.BlockQuote = latexBlockQuote + //r.BlockHtml = ? + r.Header = latexHeader + r.HRule = latexHRule + r.List = latexList + r.ListItem = latexListItem + r.Paragraph = latexParagraph + r.Table = latexTable + r.TableRow = latexTableRow + r.TableCell = latexTableCell // inline rendering - r.autolink = latexAutolink - r.codespan = latexCodespan - r.doubleEmphasis = latexDoubleEmphasis - r.emphasis = latexEmphasis - r.image = latexImage - r.linebreak = latexLinebreak - r.link = latexLink + r.AutoLink = latexAutoLink + r.CodeSpan = latexCodeSpan + r.DoubleEmphasis = latexDoubleEmphasis + r.Emphasis = latexEmphasis + r.Image = latexImage + r.LineBreak = latexLineBreak + r.Link = latexLink //r.rawHtmlTag = ? - r.strikethrough = latexStrikethrough + r.StrikeThrough = latexStrikeThrough - r.normalText = latexNormalText + r.NormalText = latexNormalText - r.documentHeader = latexDocumentHeader - r.documentFooter = latexDocumentFooter + r.DocumentHeader = latexDocumentHeader + r.DocumentFooter = latexDocumentFooter - r.opaque = nil + r.Opaque = nil return r } // render code chunks using verbatim, or listings if we have a language -func latexBlockcode(out *bytes.Buffer, text []byte, lang string, opaque interface{}) { +func latexBlockCode(out *bytes.Buffer, text []byte, lang string, opaque interface{}) { if lang == "" { out.WriteString("\n\\begin{verbatim}\n") } else { @@ -68,13 +68,13 @@ func latexBlockcode(out *bytes.Buffer, text []byte, lang string, opaque interfac } } -func latexBlockquote(out *bytes.Buffer, text []byte, opaque interface{}) { +func latexBlockQuote(out *bytes.Buffer, text []byte, opaque interface{}) { out.WriteString("\n\\begin{quotation}\n") out.Write(text) out.WriteString("\n\\end{quotation}\n") } -//blockhtml func(out *bytes.Buffer, text []byte, opaque interface{}) +//BlockHtml func(out *bytes.Buffer, text []byte, opaque interface{}) func latexHeader(out *bytes.Buffer, text []byte, level int, opaque interface{}) { switch level { @@ -95,7 +95,7 @@ func latexHeader(out *bytes.Buffer, text []byte, level int, opaque interface{}) out.WriteString("}\n") } -func latexHrule(out *bytes.Buffer, opaque interface{}) { +func latexHRule(out *bytes.Buffer, opaque interface{}) { out.WriteString("\n\\HRule\n") } @@ -113,7 +113,7 @@ func latexList(out *bytes.Buffer, text []byte, flags int, opaque interface{}) { } } -func latexListitem(out *bytes.Buffer, text []byte, flags int, opaque interface{}) { +func latexListItem(out *bytes.Buffer, text []byte, flags int, opaque interface{}) { out.WriteString("\n\\item ") out.Write(text) } @@ -157,7 +157,7 @@ func latexTableCell(out *bytes.Buffer, text []byte, align int, opaque interface{ out.Write(text) } -func latexAutolink(out *bytes.Buffer, link []byte, kind int, opaque interface{}) int { +func latexAutoLink(out *bytes.Buffer, link []byte, kind int, opaque interface{}) int { out.WriteString("\\href{") if kind == LINK_TYPE_EMAIL { out.WriteString("mailto:") @@ -169,7 +169,7 @@ func latexAutolink(out *bytes.Buffer, link []byte, kind int, opaque interface{}) return 1 } -func latexCodespan(out *bytes.Buffer, text []byte, opaque interface{}) int { +func latexCodeSpan(out *bytes.Buffer, text []byte, opaque interface{}) int { out.WriteString("\\texttt{") escapeSpecialChars(out, text) out.WriteString("}") @@ -206,7 +206,7 @@ func latexImage(out *bytes.Buffer, link []byte, title []byte, alt []byte, opaque return 1 } -func latexLinebreak(out *bytes.Buffer, opaque interface{}) int { +func latexLineBreak(out *bytes.Buffer, opaque interface{}) int { out.WriteString(" \\\\\n") return 1 } @@ -231,7 +231,7 @@ func latexTripleEmphasis(out *bytes.Buffer, text []byte, opaque interface{}) int return 1 } -func latexStrikethrough(out *bytes.Buffer, text []byte, opaque interface{}) int { +func latexStrikeThrough(out *bytes.Buffer, text []byte, opaque interface{}) int { out.WriteString("\\sout{") out.Write(text) out.WriteString("}") diff --git a/markdown.go b/markdown.go index 8d2f52b..5513a69 100644 --- a/markdown.go +++ b/markdown.go @@ -95,40 +95,40 @@ var block_tags = map[string]bool{ // Most users will use the convenience functions to fill in this structure. type Renderer struct { // block-level callbacks---nil skips the block - blockcode func(out *bytes.Buffer, text []byte, lang string, opaque interface{}) - blockquote func(out *bytes.Buffer, text []byte, opaque interface{}) - blockhtml func(out *bytes.Buffer, text []byte, opaque interface{}) - header func(out *bytes.Buffer, text []byte, level int, opaque interface{}) - hrule func(out *bytes.Buffer, opaque interface{}) - list func(out *bytes.Buffer, text []byte, flags int, opaque interface{}) - listitem func(out *bytes.Buffer, text []byte, flags int, opaque interface{}) - paragraph func(out *bytes.Buffer, text []byte, opaque interface{}) - table func(out *bytes.Buffer, header []byte, body []byte, columnData []int, opaque interface{}) - tableRow func(out *bytes.Buffer, text []byte, opaque interface{}) - tableCell func(out *bytes.Buffer, text []byte, flags int, opaque interface{}) + BlockCode func(out *bytes.Buffer, text []byte, lang string, opaque interface{}) + BlockQuote func(out *bytes.Buffer, text []byte, opaque interface{}) + BlockHtml func(out *bytes.Buffer, text []byte, opaque interface{}) + Header func(out *bytes.Buffer, text []byte, level int, opaque interface{}) + HRule func(out *bytes.Buffer, opaque interface{}) + List func(out *bytes.Buffer, text []byte, flags int, opaque interface{}) + ListItem func(out *bytes.Buffer, text []byte, flags int, opaque interface{}) + Paragraph func(out *bytes.Buffer, text []byte, opaque interface{}) + Table func(out *bytes.Buffer, header []byte, body []byte, columnData []int, opaque interface{}) + TableRow func(out *bytes.Buffer, text []byte, opaque interface{}) + TableCell func(out *bytes.Buffer, text []byte, flags int, opaque interface{}) - // span-level callbacks---nil or return 0 prints the span verbatim - autolink func(out *bytes.Buffer, link []byte, kind int, opaque interface{}) int - codespan func(out *bytes.Buffer, text []byte, opaque interface{}) int - doubleEmphasis func(out *bytes.Buffer, text []byte, opaque interface{}) int - emphasis func(out *bytes.Buffer, text []byte, opaque interface{}) int - image func(out *bytes.Buffer, link []byte, title []byte, alt []byte, opaque interface{}) int - linebreak func(out *bytes.Buffer, opaque interface{}) int - link func(out *bytes.Buffer, link []byte, title []byte, content []byte, opaque interface{}) int - rawHtmlTag func(out *bytes.Buffer, tag []byte, opaque interface{}) int - tripleEmphasis func(out *bytes.Buffer, text []byte, opaque interface{}) int - strikethrough func(out *bytes.Buffer, text []byte, opaque interface{}) int + // Span-level callbacks---nil or return 0 prints the span verbatim + AutoLink func(out *bytes.Buffer, link []byte, kind int, opaque interface{}) int + CodeSpan func(out *bytes.Buffer, text []byte, opaque interface{}) int + DoubleEmphasis func(out *bytes.Buffer, text []byte, opaque interface{}) int + Emphasis func(out *bytes.Buffer, text []byte, opaque interface{}) int + Image func(out *bytes.Buffer, link []byte, title []byte, alt []byte, opaque interface{}) int + LineBreak func(out *bytes.Buffer, opaque interface{}) int + Link func(out *bytes.Buffer, link []byte, title []byte, content []byte, opaque interface{}) int + RawHtmlTag func(out *bytes.Buffer, tag []byte, opaque interface{}) int + TripleEmphasis func(out *bytes.Buffer, text []byte, opaque interface{}) int + StrikeThrough func(out *bytes.Buffer, text []byte, opaque interface{}) int - // low-level callbacks---nil copies input directly into the output - entity func(out *bytes.Buffer, entity []byte, opaque interface{}) - normalText func(out *bytes.Buffer, text []byte, opaque interface{}) + // Low-level callbacks---nil copies input directly into the output + Entity func(out *bytes.Buffer, entity []byte, opaque interface{}) + NormalText func(out *bytes.Buffer, text []byte, opaque interface{}) - // header and footer - documentHeader func(out *bytes.Buffer, opaque interface{}) - documentFooter func(out *bytes.Buffer, opaque interface{}) + // Header and footer + DocumentHeader func(out *bytes.Buffer, opaque interface{}) + DocumentFooter func(out *bytes.Buffer, opaque interface{}) - // user data---passed back to every callback - opaque interface{} + // User data---passed back to every callback + Opaque interface{} } type inlineParser func(out *bytes.Buffer, rndr *render, data []byte, offset int) int @@ -166,28 +166,28 @@ func Markdown(input []byte, renderer *Renderer, extensions uint32) []byte { rndr.maxNesting = 16 // register inline parsers - if rndr.mk.emphasis != nil || rndr.mk.doubleEmphasis != nil || rndr.mk.tripleEmphasis != nil { + if rndr.mk.Emphasis != nil || rndr.mk.DoubleEmphasis != nil || rndr.mk.TripleEmphasis != nil { rndr.inline['*'] = inlineEmphasis rndr.inline['_'] = inlineEmphasis if extensions&EXTENSION_STRIKETHROUGH != 0 { rndr.inline['~'] = inlineEmphasis } } - if rndr.mk.codespan != nil { - rndr.inline['`'] = inlineCodespan + if rndr.mk.CodeSpan != nil { + rndr.inline['`'] = inlineCodeSpan } - if rndr.mk.linebreak != nil { - rndr.inline['\n'] = inlineLinebreak + if rndr.mk.LineBreak != nil { + rndr.inline['\n'] = inlineLineBreak } - if rndr.mk.image != nil || rndr.mk.link != nil { + if rndr.mk.Image != nil || rndr.mk.Link != nil { rndr.inline['['] = inlineLink } - rndr.inline['<'] = inlineLangle + rndr.inline['<'] = inlineLAngle rndr.inline['\\'] = inlineEscape rndr.inline['&'] = inlineEntity if extensions&EXTENSION_AUTOLINK != 0 { - rndr.inline[':'] = inlineAutolink + rndr.inline[':'] = inlineAutoLink } // first pass: look for references, copy everything else @@ -221,8 +221,8 @@ func Markdown(input []byte, renderer *Renderer, extensions uint32) []byte { // second pass: actual rendering output := bytes.NewBuffer(nil) - if rndr.mk.documentHeader != nil { - rndr.mk.documentHeader(output, rndr.mk.opaque) + if rndr.mk.DocumentHeader != nil { + rndr.mk.DocumentHeader(output, rndr.mk.Opaque) } if text.Len() > 0 { @@ -234,8 +234,8 @@ func Markdown(input []byte, renderer *Renderer, extensions uint32) []byte { parseBlock(output, rndr, text.Bytes()) } - if rndr.mk.documentFooter != nil { - rndr.mk.documentFooter(output, rndr.mk.opaque) + if rndr.mk.DocumentFooter != nil { + rndr.mk.DocumentFooter(output, rndr.mk.Opaque) } if rndr.nesting != 0 {