From ec0caaec7ce41ca6236da9d661e92dc433e1951b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 25 Dec 2024 18:20:16 +0100 Subject: [PATCH] markup/highlight: Add wrapperClass option The need comes from Tailwind's typography plugin. There's currently no way to turn that off outside of the markup, see https://github.com/tailwindlabs/tailwindcss-typography/pull/363 --- markup/highlight/config.go | 5 ++++ markup/highlight/highlight.go | 7 ++--- .../highlight/highlight_integration_test.go | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/markup/highlight/config.go b/markup/highlight/config.go index 62db6b237ee..338ea77e502 100644 --- a/markup/highlight/config.go +++ b/markup/highlight/config.go @@ -45,13 +45,18 @@ var DefaultConfig = Config{ NoClasses: true, LineNumbersInTable: true, TabWidth: 4, + WrapperClass: "highlight", } type Config struct { Style string + // Enable syntax highlighting of fenced code blocks. CodeFences bool + // The class or classes to use for the outermost element of the highlighted code. + WrapperClass string + // Use inline CSS styles. NoClasses bool diff --git a/markup/highlight/highlight.go b/markup/highlight/highlight.go index a284b59813c..30f225c0b2f 100644 --- a/markup/highlight/highlight.go +++ b/markup/highlight/highlight.go @@ -202,7 +202,7 @@ func highlight(fw hugio.FlexiWriter, code, lang string, attributes []attributes. } if !cfg.Hl_inline { - writeDivStart(w, attributes) + writeDivStart(w, attributes, cfg.WrapperClass) } options := cfg.toHTMLOptions() @@ -303,8 +303,9 @@ func (s startEnd) End(code bool) string { return s.end(code) } -func writeDivStart(w hugio.FlexiWriter, attrs []attributes.Attribute) { - w.WriteString(`
xəx `) } + +func TestHighlightClass(t *testing.T) { + t.Parallel() + + files := ` +-- config.toml -- +[markup.highlight] +noClasses = false +wrapperClass = "highlight no-prose" +-- content/_index.md -- +--- +title: home +--- +§§§go +xəx := 0 +§§§ +-- layouts/index.html -- +{{ .Content }} +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/index.html", ` +