summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-11-01 10:39:44 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-11-01 21:06:35 +0100
commit33a7b36fd42ee31dd79115ec6639bed24247332f (patch)
tree95488b5d51a2a2f9375f812cd807df0e04034a84 /hugolib/shortcode_test.go
parent6180c85fb8f95e01446b74c50cab3f0480305fe4 (diff)
hugolib: Add .Position to shortcode
To allow for better error logging in shortcodes. Note that this may be expensive to calculate, so this is primarily for error situations. See #5371
Diffstat (limited to 'hugolib/shortcode_test.go')
-rw-r--r--hugolib/shortcode_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index 0d397f9ee..2ddecc2ff 100644
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -1026,3 +1026,39 @@ ordinal: 2 scratch ordinal: 3 scratch get ordinal: 2
ordinal: 4 scratch ordinal: 5 scratch get ordinal: 4`)
}
+
+func TestShortcodePosition(t *testing.T) {
+ t.Parallel()
+ assert := require.New(t)
+
+ builder := newTestSitesBuilder(t).WithSimpleConfigFile()
+
+ builder.WithContent("page.md", `---
+title: "Hugo Rocks!"
+---
+
+# doc
+
+ {{< s1 >}}
+
+`).WithTemplatesAdded("layouts/shortcodes/s1.html", `
+{{ with .Position }}
+File: {{ .Filename }}
+Offset: {{ .Offset }}
+Line: {{ .LineNumber }}
+Column: {{ .ColumnNumber }}
+String: {{ . | safeHTML }}
+{{ end }}
+
+`).CreateSites().Build(BuildCfg{})
+
+ s := builder.H.Sites[0]
+ assert.Equal(1, len(s.RegularPages))
+
+ builder.AssertFileContent("public/page/index.html",
+ "File: content/page.md",
+ "Line: 7", "Column: 4", "Offset: 40",
+ "String: content/page.md:7:4",
+ )
+
+}