Skip to content

Commit

Permalink
fix(_balanced_quotes_shadow): handle trailing comments correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
5j9 committed Apr 12, 2024
1 parent c7580a8 commit 8d598de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tests/wikitext/test_get_bolds_and_italics.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,9 @@ def test_four_apostrophe_to_three_to_two():
assert [repr(i) for i in parse("''''a''b").get_bolds_and_italics()] == [
"Italic(\"''a''\")"
]


def test_comment_at_end_of_four():
assert [
repr(i) for i in parse("''''<!---->a''b").get_bolds_and_italics()
] == ["Italic(\"''<!---->a''\")"]
4 changes: 2 additions & 2 deletions wikitextparser/_wikitext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,12 +1071,12 @@ def repl(m) -> bytes:
if n == 4: # four apostrophes -> hide the first one
s = starts[1]
append_bold_start(s)
return b'_' * (s - starts[0]) + m.string[s : starts[-1] + 1]
return b'_' * (s - starts[0]) + m.string[s : m.end()]
if n > 5: # more than 5 apostrophes -> hide the prior ones
odd_bold_italics ^= True
odd_italics ^= True
s = starts[-5]
return b'_' * (s - starts[0]) + m.string[s : starts[-1] + 1]
return b'_' * (s - starts[0]) + m.string[s : m.end()]

return bytearray(b'\n').join(
[
Expand Down

0 comments on commit 8d598de

Please sign in to comment.