html: Clean up and simplify code

- we can use type casting to check for type instead of adding a dependency on
  reflect
- lint complains about redundant types, so get rid of that for peace of mind
This commit is contained in:
Niklas Fasching 2023-03-12 11:25:44 +01:00
parent 5464ab37d2
commit c1b428de28

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"html" "html"
"log" "log"
"reflect"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@ -50,20 +49,20 @@ type footnotes struct {
} }
var emphasisTags = map[string][]string{ var emphasisTags = map[string][]string{
"/": []string{"<em>", "</em>"}, "/": {"<em>", "</em>"},
"*": []string{"<strong>", "</strong>"}, "*": {"<strong>", "</strong>"},
"+": []string{"<del>", "</del>"}, "+": {"<del>", "</del>"},
"~": []string{"<code>", "</code>"}, "~": {"<code>", "</code>"},
"=": []string{`<code class="verbatim">`, "</code>"}, "=": {`<code class="verbatim">`, "</code>"},
"_": []string{`<span style="text-decoration: underline;">`, "</span>"}, "_": {`<span style="text-decoration: underline;">`, "</span>"},
"_{}": []string{"<sub>", "</sub>"}, "_{}": {"<sub>", "</sub>"},
"^{}": []string{"<sup>", "</sup>"}, "^{}": {"<sup>", "</sup>"},
} }
var listTags = map[string][]string{ var listTags = map[string][]string{
"unordered": []string{"<ul>", "</ul>"}, "unordered": {"<ul>", "</ul>"},
"ordered": []string{"<ol>", "</ol>"}, "ordered": {"<ol>", "</ol>"},
"descriptive": []string{"<dl>", "</dl>"}, "descriptive": {"<dl>", "</dl>"},
} }
var listItemStatuses = map[string]string{ var listItemStatuses = map[string]string{
@ -646,7 +645,7 @@ func setHTMLAttribute(attributes []h.Attribute, k, v string) []h.Attribute {
func isParagraphNodeSlice(ns []Node) bool { func isParagraphNodeSlice(ns []Node) bool {
for _, n := range ns { for _, n := range ns {
if reflect.TypeOf(n).Name() != "Paragraph" { if _, ok := n.(Paragraph); !ok {
return false return false
} }
} }