Skip to content

Commit 8a9d8f1

Browse files
Meirna-kamalMeirna Kamal
andauthored
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 <[email protected]>
1 parent 1736565 commit 8a9d8f1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/markitdown/src/markitdown/converters/_markdownify.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,18 @@ def convert_img(
109109

110110
return "![%s](%s%s)" % (alt, src, title_part)
111111

112+
def convert_input(
113+
self,
114+
el: Any,
115+
text: str,
116+
convert_as_inline: Optional[bool] = False,
117+
**kwargs,
118+
) -> str:
119+
"""Convert checkboxes to Markdown [x]/[ ] syntax."""
120+
121+
if el.get("type") == "checkbox":
122+
return "[x] " if el.has_attr("checked") else "[ ] "
123+
return ""
124+
112125
def convert_soup(self, soup: Any) -> str:
113126
return super().convert_soup(soup) # type: ignore

0 commit comments

Comments
 (0)