ref: c1b9380dfd35632577fc6960cde316af203e32df
parent: 6dd2e9a49acde23dcf5e9701915f7e8ed692ce5a
author: Niels Widger <[email protected]>
date: Thu Jan 30 12:50:47 EST 2014
Add back blackfriday extensions during Markdown conversion Modified markdownRender and markdownRenderWithTOC in hugolib/page.go to use the same flags and extensions as were previously used when we simply called blackfriday.MarkdownCommon to convert Markdown to HTML. These flags/extensions were dropped during the refactor that added the `.TableOfContents` page variable, and caused features like Markdown tables to no longer work. Modified the expected output for TestTableOfContents in page_test.go, apparently changing the flags/extensions caused an `—` to become `–`.
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -587,10 +587,21 @@
func markdownRender(content []byte) []byte {
htmlFlags := 0
htmlFlags |= blackfriday.HTML_SKIP_SCRIPT
+ htmlFlags |= blackfriday.HTML_USE_XHTML
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
+ htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
+ htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
- return blackfriday.Markdown(content, renderer, 0)
+ extensions := 0
+ extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
+ extensions |= blackfriday.EXTENSION_TABLES
+ extensions |= blackfriday.EXTENSION_FENCED_CODE
+ extensions |= blackfriday.EXTENSION_AUTOLINK
+ extensions |= blackfriday.EXTENSION_STRIKETHROUGH
+ extensions |= blackfriday.EXTENSION_SPACE_HEADERS
+
+ return blackfriday.Markdown(content, renderer, extensions)
}
func markdownRenderWithTOC(content []byte) []byte {
@@ -597,10 +608,21 @@
htmlFlags := 0
htmlFlags |= blackfriday.HTML_SKIP_SCRIPT
htmlFlags |= blackfriday.HTML_TOC
+ htmlFlags |= blackfriday.HTML_USE_XHTML
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
+ htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
+ htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
- return blackfriday.Markdown(content, renderer, 0)
+ extensions := 0
+ extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
+ extensions |= blackfriday.EXTENSION_TABLES
+ extensions |= blackfriday.EXTENSION_FENCED_CODE
+ extensions |= blackfriday.EXTENSION_AUTOLINK
+ extensions |= blackfriday.EXTENSION_STRIKETHROUGH
+ extensions |= blackfriday.EXTENSION_SPACE_HEADERS
+
+ return blackfriday.Markdown(content, renderer, extensions)
}
func extractTOC(content []byte) (newcontent []byte, toc []byte) {
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -344,7 +344,7 @@
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
- checkPageContent(t, p, "\n\n<p>For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.</p>\n\n<h2 id=\"toc_0\">AA</h2>\n\n<p>I have no idea, of course, how long it took me to reach the limit of the plain,\nbut at last I entered the foothills, following a pretty little canyon upward\ntoward the mountains. Beside me frolicked a laughing brooklet, hurrying upon\nits noisy way down to the silent sea. In its quieter pools I discovered many\nsmall fish, of four-or five-pound weight I should imagine. In appearance,\nexcept as to size and color, they were not unlike the whale of our own seas. As\nI watched them playing about I discovered, not only that they suckled their\nyoung, but that at intervals they rose to the surface to breathe as well as to\nfeed upon certain grasses and a strange, scarlet lichen which grew upon the\nrocks just above the water line.</p>\n\n<h3 id=\"toc_1\">AAA</h3>\n\n<p>I remember I felt an extraordinary persuasion that I was being played with,\nthat presently, when I was upon the very verge of safety, this mysterious\ndeath—as swift as the passage of light—would leap after me from the pit about\nthe cylinder and strike me down. ## BB</p>\n\n<h3 id=\"toc_2\">BBB</h3>\n\n<p>“You’re a great Granser,” he cried delightedly, “always making believe them little marks mean something.”</p>\n")
+ checkPageContent(t, p, "\n\n<p>For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.</p>\n\n<h2 id=\"toc_0\">AA</h2>\n\n<p>I have no idea, of course, how long it took me to reach the limit of the plain,\nbut at last I entered the foothills, following a pretty little canyon upward\ntoward the mountains. Beside me frolicked a laughing brooklet, hurrying upon\nits noisy way down to the silent sea. In its quieter pools I discovered many\nsmall fish, of four-or five-pound weight I should imagine. In appearance,\nexcept as to size and color, they were not unlike the whale of our own seas. As\nI watched them playing about I discovered, not only that they suckled their\nyoung, but that at intervals they rose to the surface to breathe as well as to\nfeed upon certain grasses and a strange, scarlet lichen which grew upon the\nrocks just above the water line.</p>\n\n<h3 id=\"toc_1\">AAA</h3>\n\n<p>I remember I felt an extraordinary persuasion that I was being played with,\nthat presently, when I was upon the very verge of safety, this mysterious\ndeath–as swift as the passage of light–would leap after me from the pit about\nthe cylinder and strike me down. ## BB</p>\n\n<h3 id=\"toc_2\">BBB</h3>\n\n<p>“You’re a great Granser,” he cried delightedly, “always making believe them little marks mean something.”</p>\n")
checkPageTOC(t, p, "<nav id=\"TableOfContents\">\n<ul>\n<li>\n<ul>\n<li><a href=\"#toc_0\">AA</a>\n<ul>\n<li><a href=\"#toc_1\">AAA</a></li>\n<li><a href=\"#toc_2\">BBB</a></li>\n</ul></li>\n</ul></li>\n</ul>\n</nav>")
}