1
0
mirror of https://github.com/danog/blackfriday.git synced 2024-11-26 20:14:43 +01:00

Merge pull request #324 from russross/move-toc-to-html

Move TOC and OmitContents to HTML flags
This commit is contained in:
Vytautas Šaltenis 2016-12-07 21:07:04 +02:00 committed by GitHub
commit a4dd8ad4a6
4 changed files with 17 additions and 16 deletions

View File

@ -1601,7 +1601,9 @@ func TestTOC(t *testing.T) {
"#",
"",
}
doTestsBlock(t, tests, TOC)
doTestsParam(t, tests, TestParams{
HTMLFlags: UseXHTML | TOC,
})
}
func TestOmitContents(t *testing.T) {
@ -1625,9 +1627,13 @@ func TestOmitContents(t *testing.T) {
"#\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) {

View File

@ -44,7 +44,6 @@ func execRecoverableTestSuite(t *testing.T, tests []string, params TestParams, s
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,
},
})
}

View File

@ -45,6 +45,8 @@ const (
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:._-]*"
@ -89,8 +91,7 @@ type HTMLRendererParameters struct {
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.
@ -821,9 +822,9 @@ func (r *HTMLRenderer) Render(ast *Node) []byte {
//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()
}
}

View File

@ -46,8 +46,6 @@ const (
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 @@ type Options struct {
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 @@ func MarkdownBasic(input []byte) []byte {
func MarkdownCommon(input []byte) []byte {
// set up the HTML renderer
renderer := NewHTMLRenderer(HTMLRendererParameters{
Flags: CommonHTMLFlags,
Extensions: CommonExtensions,
Flags: CommonHTMLFlags,
})
return Markdown(input, renderer, DefaultOptions)
}