From f27e542442d19436f1428cc22bb03aca398d37a7 Mon Sep 17 00:00:00 2001 From: rhymes Date: Thu, 15 Jul 2021 16:48:39 +0200 Subject: [PATCH] markup: Add tabindex="0" to default
 wrapper

Currently the generated `
` element isn't fully accessible as it can't be focused by keyboard users.
To make this fully accessible, the attribute `tabindex="0"` should be added to the `
` tag.

Closes #7194
---
 hugolib/embedded_shortcodes_test.go | 4 ++--
 hugolib/page_test.go                | 6 +++---
 markup/goldmark/convert_test.go     | 6 +++---
 markup/highlight/highlight.go       | 2 +-
 markup/highlight/highlight_test.go  | 8 ++++----
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go
index 9fb25e22a74..53ad2fe8efb 100644
--- a/hugolib/embedded_shortcodes_test.go
+++ b/hugolib/embedded_shortcodes_test.go
@@ -89,13 +89,13 @@ func TestShortcodeHighlight(t *testing.T) {
 			`{{< highlight java >}}
 void do();
 {{< /highlight >}}`,
-			`(?s)
}}
 void do();
 {{< /highlight >}}`,
-			`(?s)
`,
+			`(?s)
`,
 		},
 	} {
 
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index 5bc3db22fb4..7a1ff6c4e22 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1731,12 +1731,12 @@ $$$
 
 	// Blackfriday does not support this extended attribute syntax.
 	b.AssertFileContent("public/page1/index.html",
-		`
SHORT
`, - `
MARKDOWN`,
+		`
SHORT
`, + `
MARKDOWN`,
 	)
 
 	b.AssertFileContent("public/page2/index.html",
-		`
SHORT`,
+		`
SHORT`,
 	)
 }
 
diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go
index 6e6b0009f9e..f2c6efedd13 100644
--- a/markup/goldmark/convert_test.go
+++ b/markup/goldmark/convert_test.go
@@ -154,7 +154,7 @@ description
 	c.Assert(got, qt.Contains, `

神真美好

`, qt.Commentf(got)) // Code fences - c.Assert(got, qt.Contains, "
LINE1\n
") + c.Assert(got, qt.Contains, "
LINE1\n
") c.Assert(got, qt.Contains, "Code Fences No Lexer\n
LINE1\n
") // Extensions @@ -389,7 +389,7 @@ LINE5 result := convertForConfig(c, cfg, `echo "Hugo Rocks!"`, "bash") // TODO(bep) there is a whitespace mismatch (\n) between this and the highlight template func. - c.Assert(result, qt.Equals, `
echo "Hugo Rocks!"
+		c.Assert(result, qt.Equals, `
echo "Hugo Rocks!"
 
`) result = convertForConfig(c, cfg, `echo "Hugo Rocks!"`, "unknown") c.Assert(result, qt.Equals, "
echo "Hugo Rocks!"\n
") @@ -400,7 +400,7 @@ LINE5 cfg.NoClasses = false result := convertForConfig(c, cfg, lines, `bash {linenos=table,hl_lines=[2 "4-5"],linenostart=3}`) - c.Assert(result, qt.Contains, "
\n
\n
\n
\n
4")
 
 		result = convertForConfig(c, cfg, lines, "bash {linenos=inline,hl_lines=[2]}")
diff --git a/markup/highlight/highlight.go b/markup/highlight/highlight.go
index 4727843ccdd..772244a916f 100644
--- a/markup/highlight/highlight.go
+++ b/markup/highlight/highlight.go
@@ -123,7 +123,7 @@ type preWrapper struct {
 
 func (p preWrapper) Start(code bool, styleAttr string) string {
 	w := &strings.Builder{}
-	fmt.Fprintf(w, "", styleAttr)
+	fmt.Fprintf(w, `
`, styleAttr)
 	var language string
 	if code {
 		language = p.language
diff --git a/markup/highlight/highlight_test.go b/markup/highlight/highlight_test.go
index eb8ba3e961e..f68df629a40 100644
--- a/markup/highlight/highlight_test.go
+++ b/markup/highlight/highlight_test.go
@@ -43,9 +43,9 @@ User-Agent: foo
 		h := New(cfg)
 
 		result, _ := h.Highlight(`echo "Hugo Rocks!"`, "bash", "")
-		c.Assert(result, qt.Equals, `
echo "Hugo Rocks!"
`) + c.Assert(result, qt.Equals, `
echo "Hugo Rocks!"
`) result, _ = h.Highlight(`echo "Hugo Rocks!"`, "unknown", "") - c.Assert(result, qt.Equals, `
echo "Hugo Rocks!"
`) + c.Assert(result, qt.Equals, `
echo "Hugo Rocks!"
`) }) c.Run("Highlight lines, default config", func(c *qt.C) { @@ -54,7 +54,7 @@ User-Agent: foo h := New(cfg) result, _ := h.Highlight(lines, "bash", "linenos=table,hl_lines=2 4-5,linenostart=3") - c.Assert(result, qt.Contains, "
\n
\n
\n
\n
4")
 
 		result, _ = h.Highlight(lines, "bash", "linenos=inline,hl_lines=2")
@@ -113,7 +113,7 @@ User-Agent: foo
 		h := New(cfg)
 
 		result, _ := h.Highlight(lines, "", "")
-		c.Assert(result, qt.Equals, "
LINE1\nLINE2\nLINE3\nLINE4\nLINE5\n
") + c.Assert(result, qt.Equals, "
LINE1\nLINE2\nLINE3\nLINE4\nLINE5\n
") }) c.Run("No language, guess syntax", func(c *qt.C) {