gomarkdown / markdown

markdown parser and HTML renderer for Go
Other
1.41k stars 173 forks source link

Only one newline breaks blockquote parsing #242

Closed DenisDuev closed 2 years ago

DenisDuev commented 2 years ago

Only one newline breaks blockquote parsing:

test
> blockquote

Returns:

<p>text
&gt; blockquote</p>

Expected result:

<p>text</p>

<blockquote>
<p>blockquote</p>
</blockquote>

https://babelmark.github.io/?text=asd%0A%3E+blockquote+with+no+space

miekg commented 2 years ago

looks like the paragraph code doesn't check for blockquotes, this patch fixes that and doesn't break any current tests:

diff --git parser/block.go parser/block.go
index eeebec7..7c2401f 100644
--- parser/block.go
+++ parser/block.go
@@ -1675,6 +1675,12 @@ func (p *Parser) paragraph(data []byte) int {
                        return i
                }

+               // if there's a block quote, paragraph is over
+               if p.quotePrefix(current) > 0 {
+                       p.renderParagraph(data[:i])
+                       return i
+               }
+
                // if there's a fenced code block, paragraph is over
                if p.extensions&FencedCode != 0 {
                        if p.fencedCodeBlock(current, false) > 0 {
kjk commented 2 years ago

Thanks, applied.

miekg commented 2 years ago

Cheers. Note that there isn't a specific test for this.

On Tue, 7 Jun 2022, 18:33 Krzysztof Kowalczyk, @.***> wrote:

Thanks, applied.

— Reply to this email directly, view it on GitHub https://github.com/gomarkdown/markdown/issues/242#issuecomment-1148905098, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACWIWZUI73PRS6HIE3IXJLVN52XBANCNFSM5X7PFBJA . You are receiving this because you commented.Message ID: @.***>

kjk commented 2 years ago

I've added a test as part of this change.