Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_i_tag():
text = "Hello, {\\i1}world{\\i0}!"
assert parse_tags(text) == [("Hello, ", SSAStyle()),
("world", SSAStyle(italic=True)),
("!", SSAStyle())]
def test_r_named_tag():
styles = {"other style": SSAStyle(bold=True)}
text = "Hello, {\\rother style\\i1}world!"
assert parse_tags(text, styles=styles) == \
[("Hello, ", SSAStyle()),
("world!", SSAStyle(italic=True, bold=True))]
def test_r_tag():
text = "{\\i1}Hello, {\\r}world!"
assert parse_tags(text) == [("", SSAStyle()),
("Hello, ", SSAStyle(italic=True)),
("world!", SSAStyle())]
def test_no_tags():
text = "Hello, world!"
assert parse_tags(text) == [(text, SSAStyle())]
def prepare_text(text, style):
body = []
for fragment, sty in parse_tags(text, style, subs.styles):
fragment = fragment.replace(r"\h", " ")
fragment = fragment.replace(r"\n", "\n")
fragment = fragment.replace(r"\N", "\n")
if sty.italic: fragment = "<i>%s</i>" % fragment
if sty.underline: fragment = "<u>%s</u>" % fragment
if sty.strikeout: fragment = "<s>%s</s>" % fragment
body.append(fragment)
return re.sub("\n+", "\n", "".join(body).strip())
def is_entirely_italic(line):
style = subs.styles.get(line.style, SSAStyle.DEFAULT_STYLE)
for fragment, sty in parse_tags(line.text, style, subs.styles):
fragment = fragment.replace(r"\h", " ")
fragment = fragment.replace(r"\n", "\n")
fragment = fragment.replace(r"\N", "\n")
if not sty.italic and fragment and not fragment.isspace():
return False
return True
def prepare_text(text, style):
body = []
for fragment, sty in parse_tags(text, style, subs.styles):
fragment = fragment.replace(r"\h", " ")
fragment = fragment.replace(r"\n", "\n")
fragment = fragment.replace(r"\N", "\n")
if sty.italic: fragment = "<i>%s</i>" % fragment
if sty.underline: fragment = "<u>%s</u>" % fragment
if sty.strikeout: fragment = "<s>%s</s>" % fragment
body.append(fragment)
return re.sub("\n+", "\n", "".join(body).strip())