diff options
author | Martin Vilcans <martin@librador.com> | 2011-11-26 22:32:37 +0100 |
---|---|---|
committer | Martin Vilcans <martin@librador.com> | 2011-11-26 22:32:37 +0100 |
commit | b8ba084fe1d976a4da7a3344dfdd17f7770d891b (patch) | |
tree | 070eb9379776ae81c5b3ac2812da141527bc1b1c | |
parent | 2bfa3b3e77b0cbd8ad2db3dee52e66f7fde12a30 (diff) | |
download | screenplain-b8ba084fe1d976a4da7a3344dfdd17f7770d891b.tar.gz |
Some code style changes
-rw-r--r-- | screenplain/export/fdx.py | 1 | ||||
-rw-r--r-- | screenplain/main.py | 3 | ||||
-rw-r--r-- | screenplain/parsers/spmd.py | 1 | ||||
-rw-r--r-- | screenplain/richstring.py | 44 | ||||
-rw-r--r-- | tests/fdx_test.py | 4 | ||||
-rw-r--r-- | tests/richstring_test.py | 14 | ||||
-rw-r--r-- | tests/spmd_test.py | 1 |
7 files changed, 44 insertions, 24 deletions
diff --git a/screenplain/export/fdx.py b/screenplain/export/fdx.py index b2d2d87..7bd9cfe 100644 --- a/screenplain/export/fdx.py +++ b/screenplain/export/fdx.py @@ -31,6 +31,7 @@ def write_text(out, rich, trailing_linebreak): else: _write_text_element(out, fdx_styles, segment.text) + def write_paragraph(out, para_type, lines, centered=False): if centered: out.write(' <Paragraph Alignment="Center" Type="%s">\n' % para_type) diff --git a/screenplain/main.py b/screenplain/main.py index 43b48d5..0ae37cd 100644 --- a/screenplain/main.py +++ b/screenplain/main.py @@ -1,8 +1,5 @@ #!/usr/bin/env python -# Run with: -# PYTHONPATH=. python screenplain/main.py filename.txt - import fileinput import sys import codecs diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py index 76a5028..6348d75 100644 --- a/screenplain/parsers/spmd.py +++ b/screenplain/parsers/spmd.py @@ -21,6 +21,7 @@ TWOSPACE = ' ' * 2 centered_re = re.compile(r'\s*>\s*(.*)\s*<\s*$') + def is_blank(string): return string == '' or string.isspace() and string != ' ' diff --git a/screenplain/richstring.py b/screenplain/richstring.py index 9aaa163..8392f5d 100644 --- a/screenplain/richstring.py +++ b/screenplain/richstring.py @@ -56,14 +56,16 @@ class RichString(object): else: raise ValueError('Concatenating requires RichString') + class Segment(object): """A piece of a rich string. Has a set of styles.""" def __init__(self, text, styles): """ Creates a segment with a set of styles. - text is the raw text string, and - styles is a set of Style subclasses""" + text is the raw text string, and + styles is a set of Style subclasses. + """ self.styles = set(styles) self.text = text @@ -106,10 +108,14 @@ class Style(object): class Italic(Style): parse_re = re.compile( - r'\*' # one star - r'([^\s].*?)' # anything but a space, then text - r'\*' # finishing with one star - r'(?!\*)' # must not be followed by star + # one star + r'\*' + # anything but a space, then text + r'([^\s].*?)' + # finishing with one star + r'\*' + # must not be followed by star + r'(?!\*)' ) start_magic = u'\ue700' @@ -122,10 +128,14 @@ class Italic(Style): class Bold(Style): parse_re = re.compile( - r'\*\*' # two stars - r'(?=\S)' # must not be followed by space - r'(.+?[*_]*)' # inside text - r'(?<=\S)\*\*' # finishing with two stars + # two stars + r'\*\*' + # must not be followed by space + r'(?=\S)' + # inside text + r'(.+?[*_]*)' + # finishing with two stars + r'(?<=\S)\*\*' ) start_magic = u'\ue702' @@ -137,11 +147,15 @@ class Bold(Style): class Underline(Style): - parse_re = re.compile( - r'_' # underline - r'(?=\S)' # must not be followed by space - r'([^_]+)' # inside text - r'(?<=\S)_' # finishing with underline + parse_re = re.compile( + # underline + r'_' + # must not be followed by space + r'(?=\S)' + # inside text + r'([^_]+)' + # finishing with underline + r'(?<=\S)_' ) start_magic = u'\ue704' diff --git a/tests/fdx_test.py b/tests/fdx_test.py index 1e2c743..c9cd387 100644 --- a/tests/fdx_test.py +++ b/tests/fdx_test.py @@ -35,7 +35,7 @@ class OutputTests(unittest2.TestCase): ) def test_several_styles(self): - rich = bold('outer') + (bold + italic)('inner') + bold('outer') + rich = bold('outer') + (bold + italic)('inner') + bold('outer') write_text(self.out, rich, False) self.assertEqual( self.out.getvalue(), @@ -45,7 +45,7 @@ class OutputTests(unittest2.TestCase): ) def test_write_text_adds_line_break_if_requested(self): - rich = bold('outer') + (bold + italic)('inner') + bold('outer') + rich = bold('outer') + (bold + italic)('inner') + bold('outer') write_text(self.out, rich, True) self.assertEqual( self.out.getvalue(), diff --git a/tests/richstring_test.py b/tests/richstring_test.py index 2804ec2..7c04368 100644 --- a/tests/richstring_test.py +++ b/tests/richstring_test.py @@ -72,6 +72,7 @@ class RichStringTests(unittest2.TestCase): s.to_html() ) + class ParseEmphasisTests(unittest2.TestCase): def test_parse_without_emphasis(self): @@ -87,7 +88,7 @@ class ParseEmphasisTests(unittest2.TestCase): def test_parse_pre_and_postfix_and_bold(self): self.assertEquals( parse_emphasis('pre**Hello**post'), - plain('pre') + bold('Hello') + plain('post') + plain('pre') + bold('Hello') + plain('post') ) def test_parse_multiple_bold(self): @@ -155,16 +156,21 @@ class ParseEmphasisTests(unittest2.TestCase): def test_complicated(self): # As reported by Stu self.assertEquals( - parse_emphasis('You can _underline_ words, make them **bold** or *italic* or even ***bold italic.***'), + parse_emphasis( + 'You can _underline_ words, make them **bold** or *italic* ' + 'or even ***bold italic.***' + ), (plain('You can ') + underline('underline') + plain(' words, make them ') + bold('bold') + plain(' or ') + - italic('italic') + plain(' or even ') + (bold + italic)('bold italic.')) + italic('italic') + plain(' or even ') + + (bold + italic)('bold italic.')) ) def test_simplified_complicated(self): self.assertEquals( parse_emphasis('*italic* or even ***bold italic.***'), - italic('italic') + plain(' or even ') + (bold + italic)('bold italic.') + italic('italic') + plain(' or even ') + + (bold + italic)('bold italic.') ) def test_two_italic_should_not_create_one_long_italic_string(self): diff --git a/tests/spmd_test.py b/tests/spmd_test.py index ee4cd19..61a54ec 100644 --- a/tests/spmd_test.py +++ b/tests/spmd_test.py @@ -3,6 +3,7 @@ from screenplain.parsers.spmd import parse from screenplain.types import Slug, Action, Dialog, DualDialog, Transition from screenplain.richstring import plain + class ParseTests(unittest2.TestCase): # A Scene Heading, or "slugline," is any line that has a blank |