Skip to content

Commit 8d598de

Browse files
committed
fix(_balanced_quotes_shadow): handle trailing comments correctly
1 parent c7580a8 commit 8d598de

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

tests/wikitext/test_get_bolds_and_italics.py

+6
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,9 @@ def test_four_apostrophe_to_three_to_two():
185185
assert [repr(i) for i in parse("''''a''b").get_bolds_and_italics()] == [
186186
"Italic(\"''a''\")"
187187
]
188+
189+
190+
def test_comment_at_end_of_four():
191+
assert [
192+
repr(i) for i in parse("''''<!---->a''b").get_bolds_and_italics()
193+
] == ["Italic(\"''<!---->a''\")"]

wikitextparser/_wikitext.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1071,12 +1071,12 @@ def repl(m) -> bytes:
10711071
if n == 4: # four apostrophes -> hide the first one
10721072
s = starts[1]
10731073
append_bold_start(s)
1074-
return b'_' * (s - starts[0]) + m.string[s : starts[-1] + 1]
1074+
return b'_' * (s - starts[0]) + m.string[s : m.end()]
10751075
if n > 5: # more than 5 apostrophes -> hide the prior ones
10761076
odd_bold_italics ^= True
10771077
odd_italics ^= True
10781078
s = starts[-5]
1079-
return b'_' * (s - starts[0]) + m.string[s : starts[-1] + 1]
1079+
return b'_' * (s - starts[0]) + m.string[s : m.end()]
10801080

10811081
return bytearray(b'\n').join(
10821082
[

0 commit comments

Comments
 (0)