mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Make each generated page’s footnotes unique.
If content pages are fully rendered in a list page, footnotes that use the same reference (`[^fn]`) will have duplicated anchors. This change builds on #526 to put the page filename (`Page.File.Name`) as part of the anchor for a footnote. This would fix discussion [116](http://discuss.gohugo.io/t/footnote-references-are-duplicated-on-list-pages/116).
This commit is contained in:
parent
e68e7ef96f
commit
603b24a163
2 changed files with 21 additions and 19 deletions
|
@ -119,30 +119,30 @@ func bytesToHTML(b []byte) template.HTML {
|
|||
}
|
||||
|
||||
func (p *Page) renderBytes(content []byte) []byte {
|
||||
return renderBytes(content, p.guessMarkupType())
|
||||
return renderBytes(content, p.guessMarkupType(), p.File.Name)
|
||||
}
|
||||
|
||||
func (p *Page) renderContent(content []byte) []byte {
|
||||
return renderBytesWithTOC(content, p.guessMarkupType())
|
||||
return renderBytesWithTOC(content, p.guessMarkupType(), p.File.Name)
|
||||
}
|
||||
|
||||
func renderBytesWithTOC(content []byte, pagefmt string) []byte {
|
||||
func renderBytesWithTOC(content []byte, pagefmt string, footnoteref string) []byte {
|
||||
switch pagefmt {
|
||||
default:
|
||||
return markdownRenderWithTOC(content)
|
||||
return markdownRenderWithTOC(content, footnoteref)
|
||||
case "markdown":
|
||||
return markdownRenderWithTOC(content)
|
||||
return markdownRenderWithTOC(content, footnoteref)
|
||||
case "rst":
|
||||
return []byte(getRstContent(content))
|
||||
}
|
||||
}
|
||||
|
||||
func renderBytes(content []byte, pagefmt string) []byte {
|
||||
func renderBytes(content []byte, pagefmt string, footnoteref string) []byte {
|
||||
switch pagefmt {
|
||||
default:
|
||||
return markdownRender(content)
|
||||
return markdownRender(content, footnoteref)
|
||||
case "markdown":
|
||||
return markdownRender(content)
|
||||
return markdownRender(content, footnoteref)
|
||||
case "rst":
|
||||
return []byte(getRstContent(content))
|
||||
}
|
||||
|
@ -671,23 +671,24 @@ func (page *Page) Convert() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getHtmlRenderer(withTOC bool) blackfriday.Renderer {
|
||||
func getHtmlRenderer(defaultFlags int, footnoteref string) blackfriday.Renderer {
|
||||
renderParameters := blackfriday.HtmlRendererParameters{
|
||||
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
||||
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
||||
}
|
||||
|
||||
htmlFlags := 0
|
||||
if len(footnoteref) != 0 {
|
||||
renderParameters.FootnoteAnchorPrefix = footnoteref + ":" +
|
||||
renderParameters.FootnoteAnchorPrefix
|
||||
}
|
||||
|
||||
htmlFlags := defaultFlags
|
||||
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
|
||||
|
||||
if withTOC {
|
||||
htmlFlags |= blackfriday.HTML_TOC
|
||||
}
|
||||
|
||||
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
|
||||
}
|
||||
|
||||
|
@ -699,13 +700,14 @@ func getMarkdownExtensions() int {
|
|||
blackfriday.EXTENSION_HEADER_IDS
|
||||
}
|
||||
|
||||
func markdownRender(content []byte) []byte {
|
||||
return blackfriday.Markdown(content, getHtmlRenderer(false),
|
||||
func markdownRender(content []byte, footnoteref string) []byte {
|
||||
return blackfriday.Markdown(content, getHtmlRenderer(0, footnoteref),
|
||||
getMarkdownExtensions())
|
||||
}
|
||||
|
||||
func markdownRenderWithTOC(content []byte) []byte {
|
||||
return blackfriday.Markdown(content, getHtmlRenderer(true),
|
||||
func markdownRenderWithTOC(content []byte, footnoteref string) []byte {
|
||||
return blackfriday.Markdown(content,
|
||||
getHtmlRenderer(blackfriday.HTML_TOC, footnoteref),
|
||||
getMarkdownExtensions())
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ func ShortcodesHandle(stringToParse string, p *Page, t Template) string {
|
|||
var data = &ShortcodeWithPage{Params: params, Page: p}
|
||||
if endStart > 0 {
|
||||
s := stringToParse[leadEnd+3 : leadEnd+endStart]
|
||||
data.Inner = template.HTML(renderBytes([]byte(CleanP(ShortcodesHandle(s, p, t))), p.guessMarkupType()))
|
||||
data.Inner = template.HTML(renderBytes([]byte(CleanP(ShortcodesHandle(s, p, t))), p.guessMarkupType(), p.File.Name))
|
||||
remainder := CleanP(stringToParse[leadEnd+endEnd:])
|
||||
|
||||
return CleanP(stringToParse[:leadStart]) +
|
||||
|
|
Loading…
Reference in a new issue