From b9205f2b6b64de4df5a421aa13b75dab6a015339 Mon Sep 17 00:00:00 2001 From: Meirna Kamal Date: Thu, 24 Apr 2025 22:38:42 +0200 Subject: [PATCH] feat: add checkbox support to Markdown converter This change introduces functionality to convert HTML checkbox input elements () into Markdown checkbox syntax ([ ] or [x]). --- .../src/markitdown/converters/_markdownify.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/markitdown/src/markitdown/converters/_markdownify.py b/packages/markitdown/src/markitdown/converters/_markdownify.py index d98bdfb..690b005 100644 --- a/packages/markitdown/src/markitdown/converters/_markdownify.py +++ b/packages/markitdown/src/markitdown/converters/_markdownify.py @@ -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