Skip to content

Commit dcb4cf8

Browse files
committed
Whitespace inside nested block elements in conditional comments should be ignored.
When content inside a conditional comment is formatted with indentation and newlines, html5lib parses these as TextNode children of the elements. For block-level elements like table/tr/td, this whitespace is semantically insignificant and should be ignored.
1 parent 452ad24 commit dcb4cf8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

htmlcompare/elements.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
2626
# Metadata (typically not rendered)
2727
'base', 'link', 'meta', 'noscript', 'script', 'style', 'template', 'title',
28+
# VML elements (used in Outlook conditional comments)
29+
'v:image', 'v:rect', 'v:fill', 'v:stroke', 'v:textbox', 'v:shape',
30+
'v:shapetype', 'v:roundrect', 'v:oval', 'v:line', 'v:polyline',
31+
'v:group', 'v:background',
32+
# Microsoft Office elements
33+
'o:p', 'o:wrapblock',
2834
})
2935

3036
# Inline elements where whitespace is significant for rendering.

htmlcompare/tests/compare_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,3 +625,23 @@ def test_style_tag_detects_different_media_query_content():
625625
'<style>@media screen { .foo { width: 50%; } }</style>',
626626
)
627627
assert not result.is_equal
628+
629+
630+
# --- Conditional Comment Tests ---
631+
632+
def test_conditional_comment_ignores_whitespace_inside_nested_block_elements():
633+
"""Whitespace inside nested block elements in conditional comments should be ignored.
634+
635+
When content inside a conditional comment is formatted with indentation and newlines,
636+
html5lib parses these as TextNode children of the elements. For block-level elements
637+
like table/tr/td, this whitespace is semantically insignificant and should be ignored.
638+
"""
639+
multi_line = '''<div><!--[if mso | IE]>
640+
<table>
641+
<tr>
642+
<td>
643+
<v:image src="test.jpg" />
644+
<![endif]--></div>'''
645+
single_line = '<div><!--[if mso | IE]><table><tr><td><v:image src="test.jpg" /><![endif]--></div>' # noqa: E501
646+
result = compare_html(multi_line, single_line)
647+
assert result.is_equal

0 commit comments

Comments
 (0)