all repos — grayfriday @ e054c962e7e3592790620265d793539b1e8b6029

blackfriday fork with a few changes

More lint: markdown.go and ripples to other files
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 27 Jul 2016 21:28:41 +0300
commit

e054c962e7e3592790620265d793539b1e8b6029

parent

72633fddee675b450f536cb2e3d93549993394c1

6 files changed, 40 insertions(+), 36 deletions(-)

jump to
M block_test.goblock_test.go

@@ -1572,7 +1572,7 @@ `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> - <meta name="GENERATOR" content="Blackfriday Markdown Processor v1.4" /> + <meta name="GENERATOR" content="Blackfriday Markdown Processor v2.0" /> <meta charset="utf-8" /> </head> <body>
M helpers_test.gohelpers_test.go

@@ -54,7 +54,7 @@ func doTests(t *testing.T, tests []string) {

doTestsParam(t, tests, TestParams{ Options: DefaultOptions, HTMLRendererParameters: HTMLRendererParameters{ - Flags: CommonHtmlFlags, + Flags: CommonHTMLFlags, Extensions: CommonExtensions, }, })

@@ -106,7 +106,7 @@ doTestsInlineParam(t, transformTests, TestParams{

HTMLRendererParameters: params, }) doTestsInlineParam(t, transformTests, TestParams{ - HTMLFlags: CommonHtmlFlags, + HTMLFlags: CommonHTMLFlags, HTMLRendererParameters: params, }) }
M html.gohtml.go

@@ -727,7 +727,7 @@ w.Write(esc([]byte(r.Title)))

} w.WriteString("</title>\n") w.WriteString(" <meta name=\"GENERATOR\" content=\"Blackfriday Markdown Processor v") - w.WriteString(VERSION) + w.WriteString(Version) w.WriteString("\"") w.WriteString(ending) w.WriteString(">\n")
M inline.goinline.go

@@ -285,7 +285,7 @@ data = data[offset:]

var ( i = 1 - noteId int + noteID int title, link, altContent []byte textHasNl = false )

@@ -501,7 +501,7 @@ }

if t == linkInlineFootnote { // create a new reference - noteId = len(p.notes) + 1 + noteID = len(p.notes) + 1 var fragment []byte if len(id) > 0 {

@@ -512,11 +512,11 @@ fragment = make([]byte, 16)

} copy(fragment, slugify(id)) } else { - fragment = append([]byte("footnote-"), []byte(strconv.Itoa(noteId))...) + fragment = append([]byte("footnote-"), []byte(strconv.Itoa(noteID))...) } ref := &reference{ - noteId: noteId, + noteID: noteID, hasBlock: false, link: fragment, title: id,

@@ -534,7 +534,7 @@ return 0

} if t == linkDeferredFootnote { - lr.noteId = len(p.notes) + 1 + lr.noteID = len(p.notes) + 1 p.notes = append(p.notes, lr) }

@@ -542,7 +542,7 @@ // keep link and title from reference

link = lr.link // if inline footnote, title == footnote contents title = lr.title - noteId = lr.noteId + noteID = lr.noteID } // rewind the whitespace

@@ -596,7 +596,7 @@ case linkInlineFootnote, linkDeferredFootnote:

linkNode := NewNode(Link) linkNode.Destination = link linkNode.Title = title - linkNode.NoteID = noteId + linkNode.NoteID = noteID p.currBlock.appendChild(linkNode) if t == linkInlineFootnote { i++
M latex.golatex.go

@@ -311,7 +311,7 @@ r.w.WriteString(" urlcolor=black,%\n")

r.w.WriteString(" pdfstartview=FitH,%\n") r.w.WriteString(" breaklinks=true,%\n") r.w.WriteString(" pdfauthor={Blackfriday Markdown Processor v") - r.w.WriteString(VERSION) + r.w.WriteString(Version) r.w.WriteString("}}\n") r.w.WriteString("\n") r.w.WriteString("\\newcommand{\\HRule}{\\rule{\\linewidth}{0.5mm}}\n")
M markdown.gomarkdown.go

@@ -13,7 +13,7 @@ // Markdown parsing and processing

// // -// Blackfriday markdown processor. +// Package blackfriday is a markdown processor. // // Translates plain text with simple formatting rules into HTML or LaTeX. package blackfriday

@@ -26,8 +26,11 @@ "strings"

"unicode/utf8" ) -const VERSION = "1.4" +// Version string of the package. +const Version = "2.0" +// Extensions is a bitwise or'ed collection of enabled Blackfriday's +// extensions. type Extensions int // These are the supported markdown parsing extensions.

@@ -58,7 +61,7 @@ SmartypantsAngledQuotes // Enable angled double quotes (with Smartypants) for double quotes rendering

TOC // Generate a table of contents OmitContents // Skip the main contents (for a standalone table of contents) - CommonHtmlFlags HTMLFlags = UseXHTML + CommonHTMLFlags HTMLFlags = UseXHTML CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode | Autolink | Strikethrough | SpaceHeaders | HeaderIDs |

@@ -66,10 +69,13 @@ BackslashLineBreak | DefinitionLists | Smartypants |

SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes ) +// DefaultOptions is a convenience variable with all the options that are +// enabled by default. var DefaultOptions = Options{ Extensions: CommonExtensions, } +// TODO: this should probably be unexported. Or moved to node.go type LinkType int // These are the possible flag values for the link renderer.

@@ -81,6 +87,7 @@ LinkTypeNormal

LinkTypeEmail ) +// ListType contains bitwise or'ed flags for list and list item objects. type ListType int // These are the possible flag values for the ListItem renderer.

@@ -96,6 +103,7 @@ ListItemBeginningOfList

ListItemEndOfList ) +// CellAlignFlags holds a type of alignment in a table cell. type CellAlignFlags int // These are the possible flag values for the table cell renderer.

@@ -213,7 +221,7 @@ }

return &reference{ link: []byte(r.Link), title: []byte(r.Title), - noteId: 0, + noteID: 0, hasBlock: false, text: []byte(r.Text)}, true }

@@ -312,29 +320,21 @@ // set up the parser

return Markdown(input, renderer, Options{}) } -// Call Markdown with most useful extensions enabled -// MarkdownCommon is a convenience function for simple rendering. -// It processes markdown input with common extensions enabled, including: +// MarkdownCommon is a convenience function for simple rendering. It calls +// Markdown with most useful extensions enabled, including: // // * Smartypants processing with smart fractions and LaTeX dashes -// // * Intra-word emphasis suppression -// // * Tables -// // * Fenced code blocks -// // * Autolinking -// // * Strikethrough support -// // * Strict header parsing -// // * Custom Header IDs func MarkdownCommon(input []byte) []byte { // set up the HTML renderer renderer := NewHTMLRenderer(HTMLRendererParameters{ - Flags: CommonHtmlFlags, + Flags: CommonHTMLFlags, Extensions: CommonExtensions, }) return Markdown(input, renderer, DefaultOptions)

@@ -354,6 +354,10 @@ }

return renderer.Render(Parse(input, options)) } +// Parse is an entry point to the parsing part of Blackfriday. It takes an +// input markdown document and produces a syntax tree for its contents. This +// tree can then be rendered with a default or custom renderer, or +// analyzed/transformed by the caller to whatever non-standard needs they have. func Parse(input []byte, opts Options) *Node { extensions := opts.Extensions

@@ -592,7 +596,7 @@ p.block(input)

if p.flags&Footnotes != 0 && len(p.notes) > 0 { flags := ListItemBeginningOfList - for i := 0; i < len(p.notes); i += 1 { + for i := 0; i < len(p.notes); i++ { ref := p.notes[i] if ref.hasBlock { flags |= ListItemContainsBlock

@@ -642,14 +646,14 @@ // References are parsed and stored in this struct.

type reference struct { link []byte title []byte - noteId int // 0 if not a footnote ref + noteID int // 0 if not a footnote ref hasBlock bool text []byte } func (r *reference) String() string { - return fmt.Sprintf("{link: %q, title: %q, text: %q, noteId: %d, hasBlock: %v}", - r.link, r.title, r.text, r.noteId, r.hasBlock) + return fmt.Sprintf("{link: %q, title: %q, text: %q, noteID: %d, hasBlock: %v}", + r.link, r.title, r.text, r.noteID, r.hasBlock) } // Check whether or not data starts with a reference link.

@@ -667,7 +671,7 @@ for i < 3 && data[i] == ' ' {

i++ } - noteId := 0 + noteID := 0 // id part: anything but a newline between brackets if data[i] != '[' {

@@ -678,7 +682,7 @@ if p.flags&Footnotes != 0 {

if i < len(data) && data[i] == '^' { // we can set it to anything here because the proper noteIds will // be assigned later during the second pass. It just has to be != 0 - noteId = 1 + noteID = 1 i++ } }

@@ -721,7 +725,7 @@ raw []byte

hasBlock bool ) - if p.flags&Footnotes != 0 && noteId != 0 { + if p.flags&Footnotes != 0 && noteID != 0 { linkOffset, linkEnd, raw, hasBlock = scanFootnote(p, data, i, tabSize) lineEnd = linkEnd } else {

@@ -734,11 +738,11 @@

// a valid ref has been found ref := &reference{ - noteId: noteId, + noteID: noteID, hasBlock: hasBlock, } - if noteId > 0 { + if noteID > 0 { // reusing the link field for the id since footnotes don't have links ref.link = data[idOffset:idEnd] // if footnote, it's not really a title, it's the contained text