Use Node.ID for anchor ID

Fixes #2057
This commit is contained in:
Bjørn Erik Pedersen
2016-04-11 13:17:25 +02:00
parent 5ef52294f9
commit cd558958a0
11 changed files with 96 additions and 45 deletions

View File

@@ -23,6 +23,10 @@ import (
"os/exec"
"unicode/utf8"
"fmt"
"strings"
"sync"
"github.com/miekg/mmark"
"github.com/mitchellh/mapstructure"
"github.com/russross/blackfriday"
@@ -30,9 +34,6 @@ import (
bp "github.com/spf13/hugo/bufferpool"
jww "github.com/spf13/jwalterweatherman"
"github.com/spf13/viper"
"strings"
"sync"
)
// SummaryLength is the length of the summary that Hugo extracts from a content.
@@ -167,11 +168,11 @@ func getHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Render
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
}
b := len(ctx.DocumentID) != 0
b := ctx.DocumentID != 0
if b && !ctx.getConfig().PlainIDAnchors {
renderParameters.FootnoteAnchorPrefix = ctx.DocumentID + ":" + renderParameters.FootnoteAnchorPrefix
renderParameters.HeaderIDSuffix = ":" + ctx.DocumentID
renderParameters.FootnoteAnchorPrefix = fmt.Sprintf("%d:%s", ctx.DocumentID, renderParameters.FootnoteAnchorPrefix)
renderParameters.HeaderIDSuffix = fmt.Sprintf(":%d", ctx.DocumentID)
}
htmlFlags := defaultFlags
@@ -258,10 +259,10 @@ func getMmarkHTMLRenderer(defaultFlags int, ctx *RenderingContext) mmark.Rendere
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
}
b := len(ctx.DocumentID) != 0
b := ctx.DocumentID != 0
if b && !ctx.getConfig().PlainIDAnchors {
renderParameters.FootnoteAnchorPrefix = ctx.DocumentID + ":" + renderParameters.FootnoteAnchorPrefix
renderParameters.FootnoteAnchorPrefix = fmt.Sprintf("%d:%s", ctx.DocumentID, renderParameters.FootnoteAnchorPrefix)
// renderParameters.HeaderIDSuffix = ":" + ctx.DocumentId
}
@@ -343,7 +344,7 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
type RenderingContext struct {
Content []byte
PageFmt string
DocumentID string
DocumentID int
Config *Blackfriday
FileResolver FileResolverFunc
LinkResolver LinkResolverFunc