From 107fbde0cfd48b0c9cae172c2af1ac65c5e9dd36 Mon Sep 17 00:00:00 2001 From: Milan Hauth Date: Sun, 10 Mar 2024 20:49:33 +0100 Subject: [PATCH] microdvd: add option keep_style_tags --- pysubs2/microdvd.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pysubs2/microdvd.py b/pysubs2/microdvd.py index fd6b7f5..112cdd3 100644 --- a/pysubs2/microdvd.py +++ b/pysubs2/microdvd.py @@ -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) @@ -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)