From aed7df62a811b07b73ec5cbbf03e69e4bbf00919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 23 Feb 2021 18:04:05 +0100 Subject: [PATCH] markup: Handle attribute lists in code fences Fixes #8278 --- markup/goldmark/convert.go | 24 ++++++++++++++++++- markup/goldmark/convert_test.go | 19 +++++++++++++++ markup/goldmark/render_hooks.go | 41 +++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go index 629e2b15a..639fddace 100644 --- a/markup/goldmark/convert.go +++ b/markup/goldmark/convert.go @@ -22,6 +22,7 @@ import ( "runtime/debug" "github.com/gohugoio/hugo/markup/goldmark/internal/extensions/attributes" + "github.com/yuin/goldmark/ast" "github.com/gohugoio/hugo/identity" @@ -321,7 +322,28 @@ func newHighlighting(cfg highlight.Config) goldmark.Extender { highlight.WriteCodeTag(w, language) return } - w.WriteString(`
`) + + w.WriteString(`
") return } diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go index d35d4d1fd..c7367dd01 100644 --- a/markup/goldmark/convert_test.go +++ b/markup/goldmark/convert_test.go @@ -226,6 +226,25 @@ func TestConvertAttributes(t *testing.T) { "> foo\n> bar\n{#id .className attrName=attrValue class=\"class1 class2\"}\n", "

foo\nbar

\n
\n", }, + /*{ + // TODO(bep) this needs an upstream fix, see https://github.com/yuin/goldmark/issues/195 + "Code block, CodeFences=false", + func(conf *markup_config.Config) { + withBlockAttributes(conf) + conf.Highlight.CodeFences = false + }, + "```bash\necho 'foo';\n```\n{.myclass}", + "TODO", + },*/ + { + "Code block, CodeFences=true", + func(conf *markup_config.Config) { + withBlockAttributes(conf) + conf.Highlight.CodeFences = true + }, + "```bash\necho 'foo';\n````\n{.myclass id=\"myid\"}", + "
')
 	} else {