mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
@@ -23,10 +23,6 @@ import (
|
||||
"os/exec"
|
||||
"unicode/utf8"
|
||||
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/miekg/mmark"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/russross/blackfriday"
|
||||
@@ -34,6 +30,9 @@ 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.
|
||||
@@ -168,11 +167,11 @@ func getHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Render
|
||||
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
||||
}
|
||||
|
||||
b := ctx.DocumentID != 0
|
||||
b := len(ctx.DocumentID) != 0
|
||||
|
||||
if b && !ctx.getConfig().PlainIDAnchors {
|
||||
renderParameters.FootnoteAnchorPrefix = fmt.Sprintf("%d:%s", ctx.DocumentID, renderParameters.FootnoteAnchorPrefix)
|
||||
renderParameters.HeaderIDSuffix = fmt.Sprintf(":%d", ctx.DocumentID)
|
||||
renderParameters.FootnoteAnchorPrefix = ctx.DocumentID + ":" + renderParameters.FootnoteAnchorPrefix
|
||||
renderParameters.HeaderIDSuffix = ":" + ctx.DocumentID
|
||||
}
|
||||
|
||||
htmlFlags := defaultFlags
|
||||
@@ -259,10 +258,10 @@ func getMmarkHTMLRenderer(defaultFlags int, ctx *RenderingContext) mmark.Rendere
|
||||
FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"),
|
||||
}
|
||||
|
||||
b := ctx.DocumentID != 0
|
||||
b := len(ctx.DocumentID) != 0
|
||||
|
||||
if b && !ctx.getConfig().PlainIDAnchors {
|
||||
renderParameters.FootnoteAnchorPrefix = fmt.Sprintf("%d:%s", ctx.DocumentID, renderParameters.FootnoteAnchorPrefix)
|
||||
renderParameters.FootnoteAnchorPrefix = ctx.DocumentID + ":" + renderParameters.FootnoteAnchorPrefix
|
||||
// renderParameters.HeaderIDSuffix = ":" + ctx.DocumentId
|
||||
}
|
||||
|
||||
@@ -344,7 +343,7 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
|
||||
type RenderingContext struct {
|
||||
Content []byte
|
||||
PageFmt string
|
||||
DocumentID int
|
||||
DocumentID string
|
||||
Config *Blackfriday
|
||||
FileResolver FileResolverFunc
|
||||
LinkResolver LinkResolverFunc
|
||||
|
@@ -172,15 +172,15 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
|
||||
|
||||
func TestGetHTMLRendererAnchors(t *testing.T) {
|
||||
ctx := &RenderingContext{}
|
||||
ctx.DocumentID = 123
|
||||
ctx.DocumentID = "testid"
|
||||
ctx.Config = ctx.getConfig()
|
||||
ctx.Config.PlainIDAnchors = false
|
||||
|
||||
actualRenderer := getHTMLRenderer(0, ctx)
|
||||
headerBuffer := &bytes.Buffer{}
|
||||
footnoteBuffer := &bytes.Buffer{}
|
||||
expectedFootnoteHref := []byte("href=\"#fn:123:href\"")
|
||||
expectedHeaderID := []byte("<h1 id=\"id:123\"></h1>\n")
|
||||
expectedFootnoteHref := []byte("href=\"#fn:testid:href\"")
|
||||
expectedHeaderID := []byte("<h1 id=\"id:testid\"></h1>\n")
|
||||
|
||||
actualRenderer.Header(headerBuffer, func() bool { return true }, 1, "id")
|
||||
actualRenderer.FootnoteRef(footnoteBuffer, []byte("href"), 1)
|
||||
@@ -196,14 +196,14 @@ func TestGetHTMLRendererAnchors(t *testing.T) {
|
||||
|
||||
func TestGetMmarkHTMLRenderer(t *testing.T) {
|
||||
ctx := &RenderingContext{}
|
||||
ctx.DocumentID = 321
|
||||
ctx.DocumentID = "testid"
|
||||
ctx.Config = ctx.getConfig()
|
||||
ctx.Config.PlainIDAnchors = false
|
||||
actualRenderer := getMmarkHTMLRenderer(0, ctx)
|
||||
|
||||
headerBuffer := &bytes.Buffer{}
|
||||
footnoteBuffer := &bytes.Buffer{}
|
||||
expectedFootnoteHref := []byte("href=\"#fn:321:href\"")
|
||||
expectedFootnoteHref := []byte("href=\"#fn:testid:href\"")
|
||||
expectedHeaderID := []byte("<h1 id=\"id\"></h1>")
|
||||
|
||||
actualRenderer.FootnoteRef(footnoteBuffer, []byte("href"), 1)
|
||||
|
Reference in New Issue
Block a user