diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-05-30 20:42:46 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-05-31 09:05:54 +0200 |
commit | 6f7bf3f2d7eda178d0dba4a6bf3dfa50229df7ae (patch) | |
tree | 781580c54bed6942f1844def43750b027d8bbc76 /hugolib/shortcode_test.go | |
parent | 9e904d756be02ca30e4cd9abb1eae8ba01f9c8af (diff) | |
download | hugo-6f7bf3f2d7eda178d0dba4a6bf3dfa50229df7ae.tar.gz hugo-6f7bf3f2d7eda178d0dba4a6bf3dfa50229df7ae.zip |
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
Diffstat (limited to 'hugolib/shortcode_test.go')
-rw-r--r-- | hugolib/shortcode_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
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", "<pre><code>echo "foo";\n</code></pre>") } + +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", ` +<pre><code> <div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">line 1<span class="p">;</span> +</span></span><span class="line"><span class="cl">line 2<span class="p">;</span> +</span></span><span class="line"><span class="cl">line 3<span class="p">;</span></span></span></code></pre></div> +</code></pre> + + `) + +} |