-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(page_analyzer): use most contentful elements to infer selectors
- Loading branch information
Showing
7 changed files
with
83 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from markdownify import MarkdownConverter | ||
|
||
|
||
class CompactConverter(MarkdownConverter): | ||
def convert_img(self, el, text, convert_as_inline): | ||
src = el.attrs.get("src", "") | ||
|
||
if not src: | ||
return "" | ||
|
||
if src.startswith("data:image"): | ||
el.attrs["src"] = "<base64_image>" | ||
|
||
return super().convert_img(el, text, convert_as_inline) | ||
|
||
def convert_noscript(self, _el, _text, _convert_as_inline): | ||
return "" | ||
|
||
# def convert_div(self, el, text, convert_as_inline): | ||
# if text: | ||
# text = text.strip("\n") | ||
# | ||
# if convert_as_inline or not text: | ||
# return text | ||
# | ||
# return f"{text}\n" | ||
|
||
|
||
def html_to_markdown(html: str, **options) -> str: | ||
return CompactConverter(**options).convert(html).strip() |