Skip to content

Commit

Permalink
microdvd: add option keep_style_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Mar 10, 2024
1 parent 319ad18 commit 107fbde
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pysubs2/microdvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def guess_format(cls, text):
return "microdvd"

@classmethod
def from_file(cls, subs, fp, format_, fps=None, **kwargs):
def from_file(cls, subs, fp, format_, fps=None, keep_style_tags=False, **kwargs):
"""See :meth:`pysubs2.formats.FormatBase.from_file()`"""
for line in fp:
match = MICRODVD_LINE.match(line)
Expand Down Expand Up @@ -48,6 +48,9 @@ def from_file(cls, subs, fp, format_, fps=None, **kwargs):
def prepare_text(text):
text = text.replace(b"|", rb"\N")

if keep_style_tags:
return text.strip()

def style_replacer(match: re.Match) -> str:
tags = [c for c in b"biu" if c in match.group(0)]
return b"{%s}" % b"".join(b"\\" + str(c).encode("ascii") + b"1" for c in tags)
Expand Down

0 comments on commit 107fbde

Please sign in to comment.