From 066db0952cb3f142b9fd87c4f91defb2feb2af5d Mon Sep 17 00:00:00 2001 From: Will Norris Date: Tue, 26 Apr 2016 10:33:18 -0700 Subject: [PATCH] website: use custom markdown options This is all so that we can enable auto creating header IDs based on the text of the header. For example "# Foo" is converted to:

Foo

I'm not really sure why this isn't a default option, but whatever. It's also unfortunate that we have to copy all of the flags and extensions from MarkdownCommon, but at least this will make it easier to add more options in the future, I gues. Change-Id: I65800c75560ad3b9a3fd0389b722c07ba11ee098 --- website/camweb.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/website/camweb.go b/website/camweb.go index acb514654..a4af08c52 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -342,6 +342,31 @@ func findAndServeFile(rw http.ResponseWriter, req *http.Request, root string) { serveFile(rw, req, relPath, absPath) } +// configure blackfriday options. These are the same options that +// blackfriday.MarkdownCommon uses with minor additions. +const ( + markdownHTMLFlags = 0 | + blackfriday.HTML_USE_XHTML | + blackfriday.HTML_USE_SMARTYPANTS | + blackfriday.HTML_SMARTYPANTS_FRACTIONS | + blackfriday.HTML_SMARTYPANTS_DASHES | + blackfriday.HTML_SMARTYPANTS_LATEX_DASHES + + markdownExtensions = 0 | + blackfriday.EXTENSION_NO_INTRA_EMPHASIS | + blackfriday.EXTENSION_TABLES | + blackfriday.EXTENSION_FENCED_CODE | + blackfriday.EXTENSION_AUTOLINK | + blackfriday.EXTENSION_STRIKETHROUGH | + blackfriday.EXTENSION_SPACE_HEADERS | + blackfriday.EXTENSION_HEADER_IDS | + blackfriday.EXTENSION_BACKSLASH_LINE_BREAK | + blackfriday.EXTENSION_DEFINITION_LISTS | + blackfriday.EXTENSION_AUTO_HEADER_IDS +) + +var markdownRenderer = blackfriday.HtmlRenderer(markdownHTMLFlags, "", "") + // serveFile serves a file from disk, converting any markdown to HTML. func serveFile(rw http.ResponseWriter, req *http.Request, relPath, absPath string) { data, err := ioutil.ReadFile(absPath) @@ -350,7 +375,7 @@ func serveFile(rw http.ResponseWriter, req *http.Request, relPath, absPath strin return } - data = blackfriday.MarkdownCommon(data) + data = blackfriday.MarkdownOptions(data, markdownRenderer, blackfriday.Options{Extensions: markdownExtensions}) title := "" if m := h1TitlePattern.FindSubmatch(data); len(m) > 1 {