Skip to content

Commit

Permalink
Don't merge font tags with different values
Browse files Browse the repository at this point in the history
Closes #224
  • Loading branch information
otsaloma committed May 29, 2024
1 parent 21e2b6b commit 568f60f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PENDING: Gaupol 1.15
====================

* Don't merge font tags with different values (#224)
* Drop dependency on chardet
* Add dependency on charset-normalizer
* Raise Python dependency to >= 3.5
Expand Down
4 changes: 3 additions & 1 deletion aeidon/markups/subrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def clean(self, text):
# Remove tags that are immediately closed after opening.
text = self._substitute(text, r"<([a-z]+)[^<]*?>( *)</\1>", r"\2")
# Remove tags that are immediately opened after closing.
text = self._substitute(text, r"</([a-z]+)>( *)<\1[^<]*?>", r"\2")
# Don't apply to tags that have values, such as 'font',
# because then we'd need to check the value is the same too.
text = self._substitute(text, r"</([a-z]+)>( *)<\1>", r"\2")
# Remove or relocate space right after an opening tag.
text = self._substitute(text, r" ?(<(?!/)[^>]+?>) ", r" \1")
# Remove or relocate space right before a closing tag.
Expand Down
8 changes: 8 additions & 0 deletions aeidon/markups/test/test_subrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def test_clean__closing(self):
"All <i>things</i> weird are normal\n"
"in <i>this</i> whore of cities.")

def test_clean__font(self):
# Don't merge font tags with different values.
# https://github.com/otsaloma/gaupol/issues/224
text = ('<font color="#00ff00">Yes, exactly.</font>'
'<font color="#00ffff">Oh, wow!</font>'
'<font color="#ffff00">Nice.</font>')
assert self.markup.clean(text) == text

def test_clean__opening(self):
text = ("All <i>things </i>weird are normal\n"
"in <i>this </i> whore of cities.")
Expand Down

0 comments on commit 568f60f

Please sign in to comment.