From 9e1787a26b222d3e59aa533e79686cf23ea73c42 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Sep 2023 10:30:25 +0200 Subject: [PATCH] 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 --- block.go | 2 +- html.go | 4 ++-- node.go | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/block.go b/block.go index dcd61e6e..59d62359 100644 --- a/block.go +++ b/block.go @@ -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 diff --git a/html.go b/html.go index cb4f26e3..c5840613 100644 --- a/html.go +++ b/html.go @@ -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 } diff --git a/node.go b/node.go index 04e6050c..299f54ed 100644 --- a/node.go +++ b/node.go @@ -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",