feat: add checkbox support to Markdown converter (#1208)
This change introduces functionality to convert HTML checkbox input elements (<input type=checkbox>) into Markdown checkbox syntax ([ ] or [x]). Co-authored-by: Meirna Kamal <meirna.kamal@vodafone.com>
This commit is contained in:
@@ -109,5 +109,18 @@ class _CustomMarkdownify(markdownify.MarkdownConverter):
|
|||||||
|
|
||||||
return "" % (alt, src, title_part)
|
return "" % (alt, src, title_part)
|
||||||
|
|
||||||
|
def convert_input(
|
||||||
|
self,
|
||||||
|
el: Any,
|
||||||
|
text: str,
|
||||||
|
convert_as_inline: Optional[bool] = False,
|
||||||
|
**kwargs,
|
||||||
|
) -> str:
|
||||||
|
"""Convert checkboxes to Markdown [x]/[ ] syntax."""
|
||||||
|
|
||||||
|
if el.get("type") == "checkbox":
|
||||||
|
return "[x] " if el.has_attr("checked") else "[ ] "
|
||||||
|
return ""
|
||||||
|
|
||||||
def convert_soup(self, soup: Any) -> str:
|
def convert_soup(self, soup: Any) -> str:
|
||||||
return super().convert_soup(soup) # type: ignore
|
return super().convert_soup(soup) # type: ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user