matthewwithanm / matthewwithanm/python-markdownify
Feature request - implement "passthrough" option to preserve selected elements
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 203
- PR merge metrics
- No merged PRs in 30d
Description
Using markdownify 0.11.6, and it is working like a charm except for one thing. I'm scraping a site that has a youtube video embedded in an iframe. In this case i need to just it unchanged from out the site had it.
an option like --skip 'iframe' for example would be great. (ideally with some criteria, such as matching an id or regex).
The following change produces the desired outcome. It's obviously just a quick hack, but it demonstrates to the functionality.
in init.py line ~143
for el in node.children:
if isinstance(el, Comment) or isinstance(el, Doctype):
continue
elif isinstance(el, NavigableString):
text += self.process_text(el)
else:
if el.name == 'iframe':
text += self.process_text(el)
else:
text += self.process_tag(el, convert_children_as_inline)
test.html
<p>Need a way to preserve the original html for a given element.</p>
<i>Please don't discard my iframe :) </i>
<div class="ratio ratio-16x9" data-video="">
<iframe allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" class="border" data-video="" src="https://www.youtube.com/embed/EHfq0miBu8c?modestbranding=0&rel=0&showinfo=0"></iframe>
</div>
<hr />
Produces:
===================
Need a way to preserve the original html for a given element.
*Please don't discard my iframe :)*
<iframe allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" class="border" data-video="" src="https://www.youtube.com/embed/EHfq0miBu8c?modestbranding=0&rel=0&showinfo=0"></iframe>
---```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in init.py around line 143, where child elements are converted, and review how the supplied test.html example is processed. Define how a passthrough selection option should identify elements, then verify that selected elements such as the iframe retain their original HTML while other content is still converted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100