From 6f7bf3f2d7eda178d0dba4a6bf3dfa50229df7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 30 May 2022 20:42:46 +0200 Subject: Fix indentation in highlight shortcode This commit adds a new `.InnerDeindent` method to the shortcode context, which is `.Inner` with any indendation removed. This is then used in the built-in `highlight` shortcode to prevent the extra whitespace getting hightlighted. Fixes #4717 --- hugolib/shortcode_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'hugolib/shortcode_test.go') diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 15c27a42e..5b8a5c295 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -1009,3 +1009,47 @@ echo "foo"; b.AssertFileContent("public/p1/index.html", "
echo "foo";\n
") } + +func TestShortcodeHighlightDeindent(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +[markup] +[markup.highlight] +codeFences = true +noClasses = false +-- content/p1.md -- +--- +title: "p1" +--- + +## Indent 5 Spaces + + {{< highlight bash >}} + line 1; + line 2; + line 3; + {{< /highlight >}} + +-- layouts/_default/single.html -- +{{ .Content }} +` + + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + Running: true, + }, + ).Build() + + b.AssertFileContent("public/p1/index.html", ` +
 
line 1;
+line 2;
+line 3;
+
+ + `) + +} -- cgit v1.2.3