diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-27 17:57:28 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-02-27 19:51:40 +0100 |
commit | 3ad39001df84c01a5da8ec7e008ee3835e1a7c4e (patch) | |
tree | fe9d125324fdf291d13bf0f65f158824cff46d40 /markup/goldmark | |
parent | 39261b689e47116de5cfd3bee6b6e3af57deb97c (diff) |
markup/highlight: Rework the return value from HighlightCodeblock
To make it possible to render it with a custom HTML ("<div>") wrapper.
Updates #9573
Diffstat (limited to 'markup/goldmark')
-rw-r--r-- | markup/goldmark/codeblocks/integration_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/markup/goldmark/codeblocks/integration_test.go b/markup/goldmark/codeblocks/integration_test.go index fcd406c2c..fb83e7d24 100644 --- a/markup/goldmark/codeblocks/integration_test.go +++ b/markup/goldmark/codeblocks/integration_test.go @@ -113,6 +113,57 @@ Go Language: golang| ) } +func TestHighlightCodeblock(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +[markup] +[markup.highlight] +anchorLineNos = false +codeFences = true +guessSyntax = false +hl_Lines = '' +lineAnchors = '' +lineNoStart = 1 +lineNos = false +lineNumbersInTable = true +noClasses = false +style = 'monokai' +tabWidth = 4 +-- layouts/_default/_markup/render-codeblock.html -- +{{ $result := transform.HighlightCodeBlock . }} +Inner: |{{ $result.Inner | safeHTML }}| +Wrapped: |{{ $result.Wrapped | safeHTML }}| +-- layouts/_default/single.html -- +{{ .Content }} +-- content/p1.md -- +--- +title: "p1" +--- + +## Go Code + +§§§go +fmt.Println("Hello, World!"); +§§§ + +` + + b := hugolib.NewIntegrationTestBuilder( + hugolib.IntegrationTestConfig{ + T: t, + TxtarString: files, + NeedsOsFS: false, + }, + ).Build() + + b.AssertFileContent("public/p1/index.html", + "Inner: |<span class=\"line\"><span class=\"cl\"><span class=\"nx\">fmt</span><span class=\"p\">.</span><span class=\"nf\">Println</span><span class=\"p\">(</span><span class=\"s\">"Hello, World!"</span><span class=\"p\">);</span></span></span>|", + "Wrapped: |<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-go\" data-lang=\"go\"><span class=\"line\"><span class=\"cl\"><span class=\"nx\">fmt</span><span class=\"p\">.</span><span class=\"nf\">Println</span><span class=\"p\">(</span><span class=\"s\">"Hello, World!"</span><span class=\"p\">);</span></span></span></code></pre></div>|", + ) +} + func TestCodeChomp(t *testing.T) { t.Parallel() |