feat: add checkbox support to Markdown converter

This change introduces functionality to convert HTML checkbox input elements
(<input type=checkbox>) into Markdown checkbox syntax ([ ] or [x]).
This commit is contained in:
Meirna Kamal 2025-04-24 22:38:42 +02:00
parent 041be54471
commit b9205f2b6b

View file

@ -107,5 +107,18 @@ class _CustomMarkdownify(markdownify.MarkdownConverter):
return "![%s](%s%s)" % (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:
return super().convert_soup(soup) # type: ignore