From e68e7ef96fb7a83319f6d828799524f85c75c5eb Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Fri, 26 Sep 2014 23:44:09 -0400 Subject: [PATCH] Configure footnote rendering. - The config file can provide FootnoteAnchorPrefix, which will be used by blackfriday when rendering to HTML. A value of `q:` has the effect of making the anchor for a footnote `[^footie]` be `fn:q:footie`. The default is `""`. - The config file can provide FootnoteReturnLinkContents, which will be used by blackfriday when rendering to HTML. A value of `^` has the effect of making the return link be `^` instead of `[return]`. --- commands/hugo.go | 2 + docs/content/overview/configuration.md | 2 + hugolib/page.go | 59 ++++++++++++-------------- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/commands/hugo.go b/commands/hugo.go index 9e9518493..0fb76c7cd 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -121,6 +121,8 @@ func InitializeConfig() { viper.SetDefault("PygmentsUseClasses", false) viper.SetDefault("DisableLiveReload", false) viper.SetDefault("PluralizeListTitles", true) + viper.SetDefault("FootnoteAnchorPrefix", "") + viper.SetDefault("FootnoteReturnLinkContents", "") if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed { viper.Set("BuildDrafts", Draft) diff --git a/docs/content/overview/configuration.md b/docs/content/overview/configuration.md index d82adb903..c612b244e 100644 --- a/docs/content/overview/configuration.md +++ b/docs/content/overview/configuration.md @@ -40,6 +40,7 @@ The following is an example of a toml config file with some of the default value builddrafts = false baseurl = "http://yoursite.example.com/" canonifyurls = true + [indexes] category = "categories" tag = "tags" @@ -49,6 +50,7 @@ Here is a yaml configuration file which sets a few more options --- baseurl: "http://yoursite.example.com/" title: "Yoyodyne Widget Blogging" + footnotereturnlinkcontents: "↩" permalinks: post: /:year/:month/:title/ params: diff --git a/hugolib/page.go b/hugolib/page.go index 0a9648e5e..4f2c6c483 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -671,49 +671,42 @@ func (page *Page) Convert() error { return nil } -func markdownRender(content []byte) []byte { +func getHtmlRenderer(withTOC bool) blackfriday.Renderer { + renderParameters := blackfriday.HtmlRendererParameters{ + FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"), + FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"), + } + htmlFlags := 0 htmlFlags |= blackfriday.HTML_USE_XHTML htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS - renderer := blackfriday.HtmlRenderer(htmlFlags, "", "") - 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 - extensions |= blackfriday.EXTENSION_FOOTNOTES - extensions |= blackfriday.EXTENSION_HEADER_IDS + if withTOC { + htmlFlags |= blackfriday.HTML_TOC + } - return blackfriday.Markdown(content, renderer, extensions) + return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters) +} + +func getMarkdownExtensions() int { + return 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_FOOTNOTES | + blackfriday.EXTENSION_HEADER_IDS +} + +func markdownRender(content []byte) []byte { + return blackfriday.Markdown(content, getHtmlRenderer(false), + getMarkdownExtensions()) } func markdownRenderWithTOC(content []byte) []byte { - htmlFlags := 0 - 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 - htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS - renderer := blackfriday.HtmlRenderer(htmlFlags, "", "") - - 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 - extensions |= blackfriday.EXTENSION_FOOTNOTES - extensions |= blackfriday.EXTENSION_HEADER_IDS - - return blackfriday.Markdown(content, renderer, extensions) + return blackfriday.Markdown(content, getHtmlRenderer(true), + getMarkdownExtensions()) } func extractTOC(content []byte) (newcontent []byte, toc []byte) { @@ -802,7 +795,7 @@ func sliceToLower(s []string) []string { return nil } - l := make([]string, len(s)) + l := make([]string, len(s)) for i, v := range s { l[i] = strings.ToLower(v) }