Skip to content

Commit

Permalink
feat: trim whitespace with support for style tags (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted authored Jan 4, 2022
1 parent 4030941 commit 74be885
Show file tree
Hide file tree
Showing 8 changed files with 5,329 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "subclean"
version = "0.3.6"
version = "0.4.0"
description = "Simple CLI tool to instantly enhance your movie & TV show subtitles."
authors = ["disrupted <[email protected]>"]
license = "GPL-3.0"
Expand Down
4 changes: 3 additions & 1 deletion subclean/core/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def sub(self, regex, replacement: str) -> Line:
return Line(re.sub(regex, replacement, self))

def strip(self, chars=None) -> Line:
return Line(super().strip(chars))
"""Remove leading and trailing whitespace
also between style tags"""
return self.sub(r"^(<\/?i>)*\s+|\s+(<\/?i>)*$", r"\1\2")

def is_dialog(self) -> bool:
return bool(re.search(r"^(<\/?i>)*[-]", self))
Expand Down
3 changes: 2 additions & 1 deletion subclean/processors/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ def fix_spaces(line: Line) -> Line:

@staticmethod
def trim_whitespace(line: Line) -> Line:
return line.sub(r"\s+", " ").strip()
"""Trim multiple spaces between words, also if there are style tags in between"""
return line.sub(r"\s+(<\/?i>)*\s*", r" \1").strip()

@staticmethod
def fix_space_punctuation(line: Line) -> Line:
Expand Down
Loading

0 comments on commit 74be885

Please sign in to comment.