From c1b9380dfd35632577fc6960cde316af203e32df Mon Sep 17 00:00:00 2001 From: Niels Widger Date: Thu, 30 Jan 2014 17:50:47 -0500 Subject: [PATCH] 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 `–`. --- hugolib/page.go | 26 ++++++++++++++++++++++++-- hugolib/page_test.go | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/hugolib/page.go b/hugolib/page.go index dedbfa7fb..2c423c5bb 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -587,20 +587,42 @@ func (page *Page) Convert() error { 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 { 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) { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index e369aa351..b140b6593 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -344,7 +344,7 @@ func TestTableOfContents(t *testing.T) { if err != nil { t.Fatalf("Unable to create a page with frontmatter and body content: %s", err) } - checkPageContent(t, p, "\n\n

For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.

\n\n

AA

\n\n

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.

\n\n

AAA

\n\n

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

\n\n

BBB

\n\n

“You’re a great Granser,” he cried delightedly, “always making believe them little marks mean something.”

\n") + checkPageContent(t, p, "\n\n

For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.

\n\n

AA

\n\n

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.

\n\n

AAA

\n\n

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

\n\n

BBB

\n\n

“You’re a great Granser,” he cried delightedly, “always making believe them little marks mean something.”

\n") checkPageTOC(t, p, "") }