Skip to content

Commit

Permalink
srt: add option keep_newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Mar 10, 2024
1 parent e05beb1 commit 5661336
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pysubs2/subrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def guess_format(cls, text):
return "srt"

@classmethod
def from_file(cls, subs, fp, format_, keep_html_tags=False, keep_unknown_html_tags=False, **kwargs):
def from_file(cls, subs, fp, format_, keep_html_tags=False, keep_unknown_html_tags=False, keep_newlines=False, **kwargs):
"""
See :meth:`pysubs2.formats.FormatBase.from_file()`
Expand Down Expand Up @@ -105,7 +105,8 @@ def prepare_text(lines):
s = re.sub(rb"< */ *b *>", rb"{\\b0}", s)
if not (keep_html_tags or keep_unknown_html_tags):
s = re.sub(rb"< */? *[a-zA-Z][^>]*>", b"", s) # strip other HTML tags
s = re.sub(rb"\n", rb"\\N", s) # convert newlines
if not keep_newlines:
s = re.sub(rb"\n", rb"\\N", s) # convert newlines
return s

subs.events = [SSAEvent(start=start, end=end, text=prepare_text(lines))
Expand Down

0 comments on commit 5661336

Please sign in to comment.