Add HTMLComment node type

This allows users of this library to handle HTML-comments different
than other HTML blocks.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-09-28 10:30:25 +02:00
parent 4c9bf95126
commit 9e1787a26b
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 5 additions and 3 deletions

View File

@ -430,7 +430,7 @@ func (p *Markdown) htmlComment(data []byte, doRender bool) int {
for end > 0 && data[end-1] == '\n' {
end--
}
block := p.addBlock(HTMLBlock, data[:end])
block := p.addBlock(HTMLComment, data[:end])
finalizeHTMLBlock(block)
}
return size

View File

@ -632,7 +632,7 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
// to be added and when not.
if node.Prev != nil {
switch node.Prev.Type {
case HTMLBlock, List, Paragraph, Heading, CodeBlock, BlockQuote, HorizontalRule:
case HTMLBlock, HTMLComment, List, Paragraph, Heading, CodeBlock, BlockQuote, HorizontalRule:
r.cr(w)
}
}
@ -654,7 +654,7 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
r.out(w, blockquoteCloseTag)
r.cr(w)
}
case HTMLBlock:
case HTMLBlock, HTMLComment:
if r.Flags&SkipHTML != 0 {
break
}

View File

@ -26,6 +26,7 @@ const (
Image
Text
HTMLBlock
HTMLComment
CodeBlock
Softbreak
Hardbreak
@ -53,6 +54,7 @@ var nodeTypeNames = []string{
Image: "Image",
Text: "Text",
HTMLBlock: "HTMLBlock",
HTMLComment: "HTMLComment",
CodeBlock: "CodeBlock",
Softbreak: "Softbreak",
Hardbreak: "Hardbreak",