Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure footnote rendering. #526

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions commands/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/content/overview/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
57 changes: 25 additions & 32 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 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, "", "")
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
}

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
func markdownRender(content []byte) []byte {
return blackfriday.Markdown(content, getHtmlRenderer(false),
getMarkdownExtensions())
}

return blackfriday.Markdown(content, renderer, extensions)
func markdownRenderWithTOC(content []byte) []byte {
return blackfriday.Markdown(content, getHtmlRenderer(true),
getMarkdownExtensions())
}

func extractTOC(content []byte) (newcontent []byte, toc []byte) {
Expand Down Expand Up @@ -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)
}
Expand Down