Don't panic on empty code block. Fixes #237

This commit is contained in:
Tulir Asokan 2020-10-20 13:29:50 +03:00
parent 180ecc36cc
commit 1437a799e5

View File

@ -320,7 +320,7 @@ func (parser *htmlParser) syntaxHighlight(text, language string) Entity {
func (parser *htmlParser) codeblockToEntity(node *html.Node) Entity {
lang := "plaintext"
// TODO allow disabling syntax highlighting
if node.FirstChild.Type == html.ElementNode && node.FirstChild.Data == "code" {
if node.FirstChild != nil && node.FirstChild.Type == html.ElementNode && node.FirstChild.Data == "code" {
node = node.FirstChild
attr := parser.getAttribute(node, "class")
for _, class := range strings.Split(attr, " ") {