Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.

Commit e68e7ef

Browse files
halostatuespf13
authored andcommitted
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]`.
1 parent eeaf343 commit e68e7ef

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

commands/hugo.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ func InitializeConfig() {
121121
viper.SetDefault("PygmentsUseClasses", false)
122122
viper.SetDefault("DisableLiveReload", false)
123123
viper.SetDefault("PluralizeListTitles", true)
124+
viper.SetDefault("FootnoteAnchorPrefix", "")
125+
viper.SetDefault("FootnoteReturnLinkContents", "")
124126

125127
if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
126128
viper.Set("BuildDrafts", Draft)

docs/content/overview/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The following is an example of a toml config file with some of the default value
4040
builddrafts = false
4141
baseurl = "http://yoursite.example.com/"
4242
canonifyurls = true
43+
4344
[indexes]
4445
category = "categories"
4546
tag = "tags"
@@ -49,6 +50,7 @@ Here is a yaml configuration file which sets a few more options
4950
---
5051
baseurl: "http://yoursite.example.com/"
5152
title: "Yoyodyne Widget Blogging"
53+
footnotereturnlinkcontents: "↩"
5254
permalinks:
5355
post: /:year/:month/:title/
5456
params:

hugolib/page.go

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -671,49 +671,42 @@ func (page *Page) Convert() error {
671671
return nil
672672
}
673673

674-
func markdownRender(content []byte) []byte {
674+
func getHtmlRenderer(withTOC bool) blackfriday.Renderer {
675+
renderParameters := blackfriday.HtmlRendererParameters{
676+
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
677+
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
678+
}
679+
675680
htmlFlags := 0
676681
htmlFlags |= blackfriday.HTML_USE_XHTML
677682
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
678683
htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
679684
htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
680685
htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS
681-
renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
682686

683-
extensions := 0
684-
extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
685-
extensions |= blackfriday.EXTENSION_TABLES
686-
extensions |= blackfriday.EXTENSION_FENCED_CODE
687-
extensions |= blackfriday.EXTENSION_AUTOLINK
688-
extensions |= blackfriday.EXTENSION_STRIKETHROUGH
689-
extensions |= blackfriday.EXTENSION_SPACE_HEADERS
690-
extensions |= blackfriday.EXTENSION_FOOTNOTES
691-
extensions |= blackfriday.EXTENSION_HEADER_IDS
687+
if withTOC {
688+
htmlFlags |= blackfriday.HTML_TOC
689+
}
692690

693-
return blackfriday.Markdown(content, renderer, extensions)
691+
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
694692
}
695693

696-
func markdownRenderWithTOC(content []byte) []byte {
697-
htmlFlags := 0
698-
htmlFlags |= blackfriday.HTML_TOC
699-
htmlFlags |= blackfriday.HTML_USE_XHTML
700-
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
701-
htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
702-
htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
703-
htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS
704-
renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
694+
func getMarkdownExtensions() int {
695+
return 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
696+
blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE |
697+
blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH |
698+
blackfriday.EXTENSION_SPACE_HEADERS | blackfriday.EXTENSION_FOOTNOTES |
699+
blackfriday.EXTENSION_HEADER_IDS
700+
}
705701

706-
extensions := 0
707-
extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
708-
extensions |= blackfriday.EXTENSION_TABLES
709-
extensions |= blackfriday.EXTENSION_FENCED_CODE
710-
extensions |= blackfriday.EXTENSION_AUTOLINK
711-
extensions |= blackfriday.EXTENSION_STRIKETHROUGH
712-
extensions |= blackfriday.EXTENSION_SPACE_HEADERS
713-
extensions |= blackfriday.EXTENSION_FOOTNOTES
714-
extensions |= blackfriday.EXTENSION_HEADER_IDS
702+
func markdownRender(content []byte) []byte {
703+
return blackfriday.Markdown(content, getHtmlRenderer(false),
704+
getMarkdownExtensions())
705+
}
715706

716-
return blackfriday.Markdown(content, renderer, extensions)
707+
func markdownRenderWithTOC(content []byte) []byte {
708+
return blackfriday.Markdown(content, getHtmlRenderer(true),
709+
getMarkdownExtensions())
717710
}
718711

719712
func extractTOC(content []byte) (newcontent []byte, toc []byte) {
@@ -802,7 +795,7 @@ func sliceToLower(s []string) []string {
802795
return nil
803796
}
804797

805-
l := make([]string, len(s))
798+
l := make([]string, len(s))
806799
for i, v := range s {
807800
l[i] = strings.ToLower(v)
808801
}

0 commit comments

Comments
 (0)