Skip to content

Conversation

andredelft
Copy link
Contributor

@andredelft andredelft commented Sep 4, 2022

Hello!

@johannesdewit and I noticed there are quite a few cases where converted blockquotes generate redundant > markers, for example when newlines are inside the blockquote:

In [0]: print(md("<blockquote>\nHello\n</blockquote>"))

> 
> Hello
> 

But also when nesting a paragraph inside a blockquote tag:

In [1]: print(md("<blockquote><p>Hello</p></blockquote>"))

> Hello
> 
> 

And finally, nesting blockquotes:

In [2]: print(md("<blockquote>And she was like <blockquote>Hello</blockquote></blockquote>"))

> And she was like 
> > Hello
> 
> 

If we apply a simple .strip() on the text before adding the blockquote markers, we can avoid these all. I have done that in this PR, and it produces these results:

In [3]: print(md("<blockquote>\nHello\n</blockquote>"))

> Hello

In [4]: print(md("<blockquote><p>Hello</p></blockquote>"))

> Hello

In [5]: print(md("<blockquote>And she was like <blockquote>Hello</blockquote></blockquote>"))

> And she was like 
> > Hello

Also note that it still preserves blockquote markers between paragraphs, e.g.:

In [6]: print(md("<blockquote><p>Hello</p><p>Hello again</p></blockquote>"))

> Hello
> 
> Hello again

This PR also incorporates these examples in the tests.

@clach04
Copy link

clach04 commented Nov 24, 2022

👍 lgtm

@AlexVonB AlexVonB merged commit 2f9a42d into matthewwithanm:develop Mar 26, 2024
Wuhall pushed a commit to Wuhall/python-markdownify that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants