summaryrefslogtreecommitdiffstats
path: root/markup/highlight
diff options
context:
space:
mode:
authorHelder Pereira <helfper@gmail.com>2021-08-22 15:03:20 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-08-23 12:28:45 +0200
commit7a15edafe240471c072d3548b72ccda0271ffd8f (patch)
tree19617e70943aab2f49f5943bb3c3030c9c4cb4b9 /markup/highlight
parent2f0945bafe501103abe97b2f2b5566b28ec48e52 (diff)
highlight: Add tabindex when code is not highlighted
Diffstat (limited to 'markup/highlight')
-rw-r--r--markup/highlight/highlight.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/markup/highlight/highlight.go b/markup/highlight/highlight.go
index 772244a91..319426241 100644
--- a/markup/highlight/highlight.go
+++ b/markup/highlight/highlight.go
@@ -122,17 +122,17 @@ type preWrapper struct {
}
func (p preWrapper) Start(code bool, styleAttr string) string {
- w := &strings.Builder{}
- fmt.Fprintf(w, `<pre tabindex="0"%s>`, styleAttr)
var language string
if code {
language = p.language
}
- WriteCodeTag(w, language)
+ w := &strings.Builder{}
+ WritePreStart(w, language, styleAttr)
return w.String()
}
-func WriteCodeTag(w io.Writer, language string) {
+func WritePreStart(w io.Writer, language, styleAttr string) {
+ fmt.Fprintf(w, `<pre tabindex="0"%s>`, styleAttr)
fmt.Fprint(w, "<code")
if language != "" {
fmt.Fprint(w, ` class="language-`+language+`"`)
@@ -141,6 +141,12 @@ func WriteCodeTag(w io.Writer, language string) {
fmt.Fprint(w, ">")
}
+const preEnd = "</code></pre>"
+
func (p preWrapper) End(code bool) string {
- return "</code></pre>"
+ return preEnd
+}
+
+func WritePreEnd(w io.Writer) {
+ fmt.Fprint(w, preEnd)
}