@@ -275,3 +275,113 @@ def test_empty_string(self):
275275 from mdformat_space_control .plugin import _convert_dash_sequences
276276
277277 assert _convert_dash_sequences ("" ) == ""
278+
279+ def test_html_comment_preserved (self ):
280+ """Direct function test: HTML comments are preserved."""
281+ from mdformat_space_control .plugin import _convert_dash_sequences
282+
283+ assert _convert_dash_sequences ("<!-- comment -->" ) == "<!-- comment -->"
284+
285+ def test_html_triple_dash_comment_preserved (self ):
286+ """Direct function test: triple-dash HTML comments are preserved."""
287+ from mdformat_space_control .plugin import _convert_dash_sequences
288+
289+ assert _convert_dash_sequences ("<!--- comment --->" ) == "<!--- comment --->"
290+
291+ def test_html_tag_with_dashes_preserved (self ):
292+ """Direct function test: HTML tags with dash attributes are preserved."""
293+ from mdformat_space_control .plugin import _convert_dash_sequences
294+
295+ text = '<div data-value="test--value">'
296+ assert _convert_dash_sequences (text ) == text
297+
298+ def test_html_self_closing_tag_preserved (self ):
299+ """Direct function test: self-closing HTML tags with dashes preserved."""
300+ from mdformat_space_control .plugin import _convert_dash_sequences
301+
302+ text = '<img alt="a--b" />'
303+ assert _convert_dash_sequences (text ) == text
304+
305+ def test_html_comment_with_surrounding_dashes (self ):
306+ """Direct function test: dashes outside HTML convert, inside preserved."""
307+ from mdformat_space_control .plugin import _convert_dash_sequences
308+
309+ text = "word--word <!-- comment --> word---word"
310+ expected = "word\u2013 word <!-- comment --> word\u2014 word"
311+ assert _convert_dash_sequences (text ) == expected
312+
313+ def test_multiline_html_comment_preserved (self ):
314+ """Direct function test: multi-line HTML comments are preserved."""
315+ from mdformat_space_control .plugin import _convert_dash_sequences
316+
317+ text = "<!--\n comment with--dashes\n -->"
318+ assert _convert_dash_sequences (text ) == text
319+
320+ def test_multiline_html_comment_with_surrounding_text (self ):
321+ """Direct function test: text around multi-line HTML comment converts."""
322+ from mdformat_space_control .plugin import _convert_dash_sequences
323+
324+ text = "before--after\n <!--\n comment--here\n -->\n more--text"
325+ expected = "before\u2013 after\n <!--\n comment--here\n -->\n more\u2013 text"
326+ assert _convert_dash_sequences (text ) == expected
327+
328+
329+ class TestDashConversionHTML :
330+ """Tests for HTML comment and tag preservation through mdformat."""
331+
332+ def test_single_line_html_comment (self ):
333+ """Single-line HTML comment should be preserved."""
334+ input_text = "<!-- comment -->\n "
335+ result = mdformat .text (input_text , extensions = {"space_control" })
336+ assert "<!--" in result
337+ assert "-->" in result
338+ assert "\u2013 " not in result
339+ assert "\u2014 " not in result
340+
341+ def test_triple_dash_comment (self ):
342+ """Triple-dash HTML comment should be preserved."""
343+ input_text = "<!--- comment --->\n "
344+ result = mdformat .text (input_text , extensions = {"space_control" })
345+ assert "<!---" in result
346+ assert "--->" in result
347+ assert "\u2014 " not in result
348+
349+ def test_block_level_html_comment (self ):
350+ """Block-level HTML comment (own paragraph) should be preserved."""
351+ input_text = "Text.\n \n <!-- block comment -->\n \n More text.\n "
352+ result = mdformat .text (input_text , extensions = {"space_control" })
353+ assert "<!-- block comment -->" in result
354+
355+ def test_inline_html_comment_with_dashes (self ):
356+ """Dashes outside HTML comment convert; comment preserved."""
357+ input_text = "Text--here <!-- comment --> more---text.\n "
358+ result = mdformat .text (input_text , extensions = {"space_control" })
359+ assert "<!-- comment -->" in result
360+ assert "\u2013 " in result # en-dash from --
361+ assert "\u2014 " in result # em-dash from ---
362+
363+ def test_multi_line_html_comment (self ):
364+ """Multi-line HTML comment should be preserved."""
365+ input_text = "Text.\n \n <!--\n comment with--dashes\n -->\n \n More text.\n "
366+ result = mdformat .text (input_text , extensions = {"space_control" })
367+ assert "\u2013 " not in result
368+ assert "\u2014 " not in result
369+
370+ def test_html_tag_with_dash_attributes (self ):
371+ """HTML tags with dash-containing attributes should be preserved."""
372+ input_text = '<div data-value="test--value">\n \n Content.\n \n </div>\n '
373+ result = mdformat .text (input_text , extensions = {"space_control" })
374+ assert 'data-value="test--value"' in result
375+
376+ def test_self_closing_tag_with_dashes (self ):
377+ """Self-closing HTML tags with dashes should be preserved."""
378+ input_text = '<img alt="a--b" />\n '
379+ result = mdformat .text (input_text , extensions = {"space_control" })
380+ assert 'alt="a--b"' in result
381+
382+ def test_dashes_outside_html_still_convert (self ):
383+ """Dashes outside HTML elements should still convert normally."""
384+ input_text = "word--word and word---word\n "
385+ expected = "word\u2013 word and word\u2014 word\n "
386+ result = mdformat .text (input_text , extensions = {"space_control" })
387+ assert result == expected
0 commit comments