summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-06 09:20:59 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-06 09:29:38 +0100
commitc26d00db648a4b475d94c9ed8e21dafb6efa1776 (patch)
tree9238178a5d568e7a1f0b64f9f764b505539c7302 /hugolib/shortcode_test.go
parent8483b53aefc3c6b52f9917e6e5af9c4d2e98df66 (diff)
hugolib: Fix ref/relref anhcor handling
Fixes #6481
Diffstat (limited to 'hugolib/shortcode_test.go')
-rw-r--r--hugolib/shortcode_test.go65
1 files changed, 64 insertions, 1 deletions
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index 36f004253..614b8f060 100644
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -16,9 +16,10 @@ package hugolib
import (
"fmt"
"path/filepath"
-
"reflect"
+ "github.com/spf13/viper"
+
"github.com/gohugoio/hugo/parser/pageparser"
"github.com/gohugoio/hugo/resources/page"
@@ -1195,3 +1196,65 @@ Get: {{ printf "%v (%T)" $b1 $b1 | safeHTML }}
"types string: - 0: true (string) - 1: trues (string) - 2: 33 (string) - 3: 3.14 (string) ",
)
}
+
+func TestShortcodeRef(t *testing.T) {
+ for _, plainIDAnchors := range []bool{false, true} {
+ plainIDAnchors := plainIDAnchors
+ t.Run(fmt.Sprintf("plainIDAnchors=%t", plainIDAnchors), func(t *testing.T) {
+ t.Parallel()
+
+ v := viper.New()
+ v.Set("baseURL", "https://example.org")
+ v.Set("blackfriday", map[string]interface{}{
+ "plainIDAnchors": plainIDAnchors,
+ })
+
+ builder := newTestSitesBuilder(t).WithViper(v)
+
+ for i := 1; i <= 2; i++ {
+ builder.WithContent(fmt.Sprintf("page%d.md", i), `---
+title: "Hugo Rocks!"
+---
+
+
+
+[Page 1]({{< ref "page1.md" >}})
+[Page 1 with anchor]({{< relref "page1.md#doc" >}})
+[Page 2]({{< ref "page2.md" >}})
+[Page 2 with anchor]({{< relref "page2.md#doc" >}})
+
+
+## Doc
+
+
+`)
+ }
+
+ builder.Build(BuildCfg{})
+
+ if plainIDAnchors {
+ builder.AssertFileContent("public/page2/index.html",
+ `
+<a href="/page1/#doc">Page 1 with anchor</a>
+<a href="https://example.org/page2/">Page 2</a>
+<a href="/page2/#doc">Page 2 with anchor</a></p>
+
+<h2 id="doc">Doc</h2>
+`,
+ )
+ } else {
+ builder.AssertFileContent("public/page2/index.html",
+ `
+<p><a href="https://example.org/page1/">Page 1</a>
+<a href="/page1/#doc:45ca767ba77bc1445a0acab74f80812f">Page 1 with anchor</a>
+<a href="https://example.org/page2/">Page 2</a>
+<a href="/page2/#doc:8e3cdf52fa21e33270c99433820e46bd">Page 2 with anchor</a></p>
+<h2 id="doc:8e3cdf52fa21e33270c99433820e46bd">Doc</h2>
+`,
+ )
+ }
+
+ })
+ }
+
+}