@@ -46,6 +46,35 @@ def test_escaped_marker_inside_list_item(self):
4646 def test_escaped_backtick (self ):
4747 self .assert_round_trip (r"\`not code\`" + "\n " )
4848
49+ def test_escaped_emphasis_markers (self ):
50+ # an escaped "*"/"_" is a literal delimiter, not emphasis; re-emitting
51+ # it unescaped would turn plain text back into <em>/<strong>
52+ for text in (
53+ r"\*not emphasis\*" + "\n " ,
54+ r"\_not emphasis\_" + "\n " ,
55+ r"\*\*not strong\*\*" + "\n " ,
56+ r"\_\_not strong\_\_" + "\n " ,
57+ r"a word\_with\_underscores" + "\n " ,
58+ r"2 \* 3 \* 4" + "\n " ,
59+ r"trailing star\*" + "\n " ,
60+ r"\*leading star" + "\n " ,
61+ ):
62+ self .assert_round_trip (text )
63+
64+ def test_real_emphasis_not_over_escaped (self ):
65+ # genuine emphasis must survive untouched, and prose punctuation with
66+ # spaces around a "*"/"_" must not gain stray backslashes
67+ for text in (
68+ "*emphasis*\n " ,
69+ "**strong**\n " ,
70+ "***both***\n " ,
71+ "_under_ and __strong__\n " ,
72+ "a *b* and _c_ mixed\n " ,
73+ "2 * 3 = 6 and 4 * 5\n " ,
74+ "snake_case_variable\n " ,
75+ ):
76+ self .assert_round_trip (text )
77+
4978 def test_codespan_containing_backticks (self ):
5079 # the delimiter must grow past any backtick run inside the code span,
5180 # and pad away a leading/trailing backtick, or the re-parse breaks
0 commit comments