markup/goldmark: Unwrap inner HTML for plain code blocks

Fixes #14820
This commit is contained in:
Rayan Salhab
2026-05-09 12:41:18 +03:00
committed by GitHub
parent d27b9c06bd
commit 694906f6f1
2 changed files with 15 additions and 6 deletions
@@ -147,6 +147,12 @@ title: "p1"
fmt.Println("Hello, World!");
§§§
## Plain Code
§§§
plain <code> & text
§§§
`
b := hugolib.Test(t, files)
@@ -154,6 +160,8 @@ fmt.Println("Hello, World!");
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\">&#34;Hello, World!&#34;</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\">&#34;Hello, World!&#34;</span><span class=\"p\">);</span></span></span></code></pre></div>|",
"Inner: |plain &lt;code&gt; &amp; text|",
"Wrapped: |<pre tabindex=\"0\"><code>plain &lt;code&gt; &amp; text</code></pre>|",
)
}
+7 -6
View File
@@ -181,13 +181,14 @@ func highlight(fw hugio.FlexiWriter, code, lang string, attributes []attributes.
if lexer == nil {
if cfg.Hl_inline {
fmt.Fprintf(w, "<code%s>%s</code>", inlineCodeAttrs(lang), gohtml.EscapeString(code))
} else {
preWrapper := getPreWrapper(lang, w)
fmt.Fprint(w, preWrapper.Start(true, ""))
fmt.Fprint(w, gohtml.EscapeString(code))
fmt.Fprint(w, preWrapper.End(true))
return 0, 0, nil
}
return 0, 0, nil
preWrapper := getPreWrapper(lang, w)
fmt.Fprint(w, preWrapper.Start(true, ""))
fmt.Fprint(w, gohtml.EscapeString(code))
fmt.Fprint(w, preWrapper.End(true))
return preWrapper.low, preWrapper.high, nil
}
style := styles.Get(cfg.Style)