From c950c86b4e5fb93f787ec78ca823bded9ef9fa3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 25 May 2020 21:05:59 +0200 Subject: [PATCH] publisher: Fix tag collector for nested table elements Fixes #7318 --- hugolib/site_test.go | 2 +- publisher/htmlElementsCollector.go | 20 ++++++++++++++++++++ publisher/htmlElementsCollector_test.go | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 3116113c0..54c2fbe59 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -1123,7 +1123,7 @@ ABC. els := stats.HTMLElements b.Assert(els.Classes, qt.HasLen, 3606) // (4 * 900) + 4 +2 - b.Assert(els.Tags, qt.HasLen, 8) + b.Assert(els.Tags, qt.HasLen, 9) b.Assert(els.IDs, qt.HasLen, 1) } diff --git a/publisher/htmlElementsCollector.go b/publisher/htmlElementsCollector.go index e033f52d7..7bb2ebf15 100644 --- a/publisher/htmlElementsCollector.go +++ b/publisher/htmlElementsCollector.go @@ -116,7 +116,13 @@ func (w *cssClassCollectorWriter) Write(p []byte) (n int, err error) { w.buff.Reset() + if strings.HasPrefix(s, ". +func (c *cssClassCollectorWriter) insertStandinHTMLElement(el string) (string, string) { + tag := el[1:] + spacei := strings.Index(tag, " ") + if spacei != -1 { + tag = tag[:spacei] + } + newv := strings.Replace(el, tag, "div", 1) + return newv, strings.ToLower(tag) + +} + func (c *cssClassCollectorWriter) endCollecting(drop bool) { c.isCollecting = false c.inQuote = false diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go index 72abd94f0..e255a7354 100644 --- a/publisher/htmlElementsCollector_test.go +++ b/publisher/htmlElementsCollector_test.go @@ -51,6 +51,12 @@ func TestClassCollector(t *testing.T) { {"duplicates", `
`, f("div", "a b", "")}, {"single quote", ``, f("body", "a b", "")}, {"no quote", ``, f("body", "b", "myelement")}, + {"thead", ` + https://github.com/gohugoio/hugo/issues/7318 + + + +
`, f("table tbody td thead tr", "cl1 cl2 cl3 cl4 cl5 cl6 cl7", "")}, // https://github.com/gohugoio/hugo/issues/7161 {"minified a href", ``, f("a", "a b", "")},