matthewwithanm / matthewwithanm/python-markdownify

The strip_document option works on BeautifulSoup objects but not Tag objects

Open
#209 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
203
PR merge metrics
No merged PRs in 30d

Description

The default value of the strip_document option is STRIP, which strips leading and trailing whitespace from the Markdown.

If I have a BeautifulSoup object:

import bs4
import markdownify

html = """
<html>
 <body>
  <div>
   <p>hello</p>
  </div>
 </body>
</html>"""
soup = bs4.BeautifulSoup(html, "lxml")

strip_document is applied for the BeautifulSoup object:

print(repr(markdownify.MarkdownConverter().convert_soup(soup)))
# 'hello'

but not for a Tag object:

print(repr(markdownify.MarkdownConverter().convert_soup(soup.find("html"))))
# '\n\n\nhello\n\n'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the convert_soup entry point and reproduce the two examples from the issue with BeautifulSoup and the html Tag. Trace where strip_document is applied for each input type, then verify that converting the Tag produces the same stripped output as converting the soup.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.