diff --git a/packages/markitdown/src/markitdown/converters/_markdownify.py b/packages/markitdown/src/markitdown/converters/_markdownify.py index ed34144863..982d847fb3 100644 --- a/packages/markitdown/src/markitdown/converters/_markdownify.py +++ b/packages/markitdown/src/markitdown/converters/_markdownify.py @@ -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 "" diff --git a/packages/markitdown/tests/test_html.py b/packages/markitdown/tests/test_html.py index 94cece47b9..0e5f20a016 100644 --- a/packages/markitdown/tests/test_html.py +++ b/packages/markitdown/tests/test_html.py @@ -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'
Task
' + + 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"Task
") == "Task" + + @pytest.mark.parametrize( "whitespace", ["", " ", " ", "\t", "\n", "\r\n", "\u00a0", " \t\n\u00a0 "] )