Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def convert_input(
) -> str:
"""Convert checkboxes to Markdown [x]/[ ] syntax."""

if el.get("type") == "checkbox":
input_type = el.get("type") or ""
if input_type.isascii() and input_type.lower() == "checkbox":
return "[x] " if el.has_attr("checked") else "[ ] "
return ""

Expand Down
27 changes: 27 additions & 0 deletions packages/markitdown/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ def _convert_html(html: str, **kwargs) -> str:
return result.markdown


@pytest.mark.parametrize("input_type", ["checkbox", "CHECKBOX", "Checkbox", "cHeCkBoX"])
@pytest.mark.parametrize("checked", [False, True])
def test_html_checkbox_type_is_ascii_case_insensitive(
input_type: str, checked: bool
) -> None:
checked_attribute = " checked" if checked else ""
html = f'<p><input type="{input_type}"{checked_attribute}>Task</p>'

assert _convert_html(html) == ("[x] Task" if checked else "[ ] Task")


@pytest.mark.parametrize(
"type_attribute",
[
"",
" type",
' type=""',
' type="text"',
' type="radio"',
' type=" checkbox "',
' type="chec\u212abox"',
],
)
def test_html_non_checkbox_inputs_do_not_render_markers(type_attribute: str) -> None:
assert _convert_html(f"<p><input{type_attribute} checked>Task</p>") == "Task"


@pytest.mark.parametrize(
"whitespace", ["", " ", " ", "\t", "\n", "\r\n", "\u00a0", " \t\n\u00a0 "]
)
Expand Down