diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-26 10:42:21 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-26 21:54:36 +0100 |
commit | 10928a4f781c2faf704825ef95234125812ad860 (patch) | |
tree | 6d53312b301ad5259eb509fbdd13efa6c5c199e5 /markup/goldmark/codeblocks | |
parent | afd63bf7d56194a6aa5d32483151d71fa0b84f3a (diff) |
Remove the trailing new line in .Code
Fixes #9572
Diffstat (limited to 'markup/goldmark/codeblocks')
-rw-r--r-- | markup/goldmark/codeblocks/integration_test.go | 31 | ||||
-rw-r--r-- | markup/goldmark/codeblocks/render.go | 4 |
2 files changed, 34 insertions, 1 deletions
diff --git a/markup/goldmark/codeblocks/integration_test.go b/markup/goldmark/codeblocks/integration_test.go index d662b3911..0c9039cec 100644 --- a/markup/goldmark/codeblocks/integration_test.go +++ b/markup/goldmark/codeblocks/integration_test.go @@ -113,3 +113,34 @@ Go Language: golang| "<h2 id=\"bash-code\">Bash Code</h2>\n<div class=\"highlight blue\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"ln\">32</span><span class=\"cl\"><span class=\"nb\">echo</span> <span class=\"s2\">"l1"</span><span class=\"p\">;</span>\n</span></span><span class=\"line hl\"><span class=\"ln\">33</span>", ) } + +func TestCodeChomp(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +-- content/p1.md -- +--- +title: "p1" +--- + +§§§bash +echo "p1"; +§§§ +-- layouts/_default/single.html -- +{{ .Content }} +-- layouts/_default/_markup/render-codeblock.html -- +|{{ .Code | safeHTML }}| + +` + + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + TxtarString: files, + NeedsOsFS: false, + }, + ).Build() + + b.AssertFileContent("public/p1/index.html", "|echo \"p1\";|") +} diff --git a/markup/goldmark/codeblocks/render.go b/markup/goldmark/codeblocks/render.go index b598763d3..6cc43128b 100644 --- a/markup/goldmark/codeblocks/render.go +++ b/markup/goldmark/codeblocks/render.go @@ -17,6 +17,7 @@ import ( "bytes" "fmt" + htext "github.com/gohugoio/hugo/common/text" "github.com/gohugoio/hugo/markup/converter/hooks" "github.com/gohugoio/hugo/markup/goldmark/internal/render" "github.com/gohugoio/hugo/markup/internal/attributes" @@ -75,7 +76,8 @@ func (r *htmlRenderer) renderCodeBlock(w util.BufWriter, src []byte, node ast.No line := n.b.Lines().At(i) buff.Write(line.Value(src)) } - text := buff.String() + + text := htext.Chomp(buff.String()) var info []byte if n.b.Info != nil { |