all repos — grayfriday @ 9c4ef640b9d298803f93982f7abbfcde074b3b05

blackfriday fork with a few changes

Move TOC and OmitContents to HTML flags

The root problem this commit fixes is the duplication of Extensions
field in HTMLRendererParameters. The duplication crept in there only to
support these two flags, so moving the flags solves the problem. They're
only used in renderer anyway.

Fixes #277.
Vytautas Ĺ altenis vytas@rtfb.lt
Thu, 24 Nov 2016 21:48:48 +0200
commit

9c4ef640b9d298803f93982f7abbfcde074b3b05

parent

52676fb0053ff19b59451b2aed2a1b8de7d89592

4 files changed, 17 insertions(+), 16 deletions(-)

jump to
M block_test.goblock_test.go

@@ -1601,7 +1601,9 @@ // Trigger empty TOC

"#", "", } - doTestsBlock(t, tests, TOC) + doTestsParam(t, tests, TestParams{ + HTMLFlags: UseXHTML | TOC, + }) } func TestOmitContents(t *testing.T) {

@@ -1625,9 +1627,13 @@ // Make sure OmitContents omits even with no TOC

"#\n\nfoo", "", } - doTestsBlock(t, tests, TOC|OmitContents) + doTestsParam(t, tests, TestParams{ + HTMLFlags: UseXHTML | TOC | OmitContents, + }) // Now run again: make sure OmitContents implies TOC - doTestsBlock(t, tests, OmitContents) + doTestsParam(t, tests, TestParams{ + HTMLFlags: UseXHTML | OmitContents, + }) } func TestCompletePage(t *testing.T) {
M helpers_test.gohelpers_test.go

@@ -44,7 +44,6 @@ }

func runMarkdown(input string, params TestParams) string { params.HTMLRendererParameters.Flags = params.HTMLFlags - params.HTMLRendererParameters.Extensions = params.Options.Extensions renderer := NewHTMLRenderer(params.HTMLRendererParameters) return string(Markdown([]byte(input), renderer, params.Options)) }

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

doTestsParam(t, tests, TestParams{ Options: DefaultOptions, HTMLRendererParameters: HTMLRendererParameters{ - Flags: CommonHTMLFlags, - Extensions: CommonExtensions, + Flags: CommonHTMLFlags, }, }) }
M html.gohtml.go

@@ -46,6 +46,8 @@ SmartypantsFractions // Enable smart fractions (with Smartypants)

SmartypantsDashes // Enable smart dashes (with Smartypants) SmartypantsLatexDashes // Enable LaTeX-style dashes (with Smartypants) 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) TagName = "[A-Za-z][A-Za-z0-9-]*" AttributeName = "[a-zA-Z_:][a-zA-Z0-9:._-]*"

@@ -90,8 +92,7 @@ Title string // Document title (used if CompletePage is set)

CSS string // Optional CSS file URL (used if CompletePage is set) Icon string // Optional icon file URL (used if CompletePage is set) - Flags HTMLFlags // Flags allow customizing this renderer's behavior - Extensions Extensions // Extensions give Smartypants and HTML renderer access to Blackfriday's global extensions + Flags HTMLFlags // Flags allow customizing this renderer's behavior } // HTMLRenderer is a type that implements the Renderer interface for HTML output.

@@ -829,9 +830,9 @@ //println("render_Blackfriday")

//dump(ast) var buff bytes.Buffer r.writeDocumentHeader(&buff) - if r.Extensions&TOC != 0 || r.Extensions&OmitContents != 0 { + if r.Flags&TOC != 0 || r.Flags&OmitContents != 0 { r.writeTOC(&buff, ast) - if r.Extensions&OmitContents != 0 { + if r.Flags&OmitContents != 0 { return buff.Bytes() } }
M markdown.gomarkdown.go

@@ -46,8 +46,6 @@ Titleblock // Titleblock ala pandoc

AutoHeaderIDs // Create the header ID from the text BackslashLineBreak // Translate trailing backslashes into line breaks DefinitionLists // Render definition lists - TOC // Generate a table of contents - OmitContents // Skip the main contents (for a standalone table of contents) CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants | SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes

@@ -290,8 +288,7 @@ // It processes markdown input with no extensions enabled.

func MarkdownBasic(input []byte) []byte { // set up the HTML renderer renderer := NewHTMLRenderer(HTMLRendererParameters{ - Flags: UseXHTML, - Extensions: CommonExtensions, + Flags: UseXHTML, }) // set up the parser

@@ -319,8 +316,7 @@ // * Custom Header IDs

func MarkdownCommon(input []byte) []byte { // set up the HTML renderer renderer := NewHTMLRenderer(HTMLRendererParameters{ - Flags: CommonHTMLFlags, - Extensions: CommonExtensions, + Flags: CommonHTMLFlags, }) return Markdown(input, renderer, DefaultOptions) }