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