diff options
| -rw-r--r-- | screenplain/parsers/spmd.py | 3 | ||||
| -rw-r--r-- | screenplain/types.py | 16 | ||||
| -rw-r--r-- | tests/spmd_test.py | 37 |
3 files changed, 48 insertions, 8 deletions
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py index 3da8864..fbf2ffa 100644 --- a/screenplain/parsers/spmd.py +++ b/screenplain/parsers/spmd.py @@ -48,7 +48,8 @@ def create_paragraph(blanks_before, line_list): return Action(line_list) def clean_line(line): - """Strips leading whitespace and trailing end of line characters in a string. + """Strips leading whitespace and trailing end of line characters + in a string. Leading whitespace is insignificant in SPMD, and trailing EOL appear when reading from a file or HTML form. diff --git a/screenplain/types.py b/screenplain/types.py index 4b12418..fe3c849 100644 --- a/screenplain/types.py +++ b/screenplain/types.py @@ -29,6 +29,7 @@ class Dialog(object): def _parse(self, lines): inside_parenthesis = False for line in lines: + line = line.rstrip() if line.startswith('('): inside_parenthesis = True self.blocks.append((inside_parenthesis, line)) @@ -78,11 +79,12 @@ class Action(object): top_margin = 1 def __init__(self, lines): - self.text = ' '.join(line.strip() for line in lines) + self.lines = [line.strip() for line in lines] def format(self): - for line in textwrap.wrap(self.text, width=self.fill): - yield self.indent + line + for logical_line in self.lines: + for line in textwrap.wrap(logical_line, width=self.fill): + yield self.indent + line class Transition(object): indent = '' @@ -90,9 +92,9 @@ class Transition(object): top_margin = 1 def __init__(self, lines): - self.text = ' '.join(line.strip() for line in lines) + self.lines = [line.strip() for line in lines] def format(self): - for line in textwrap.wrap(self.text, width=self.fill): - yield self.indent + line - + for logical_line in self.lines: + for line in textwrap.wrap(logical_line, width=self.fill): + yield self.indent + line diff --git a/tests/spmd_test.py b/tests/spmd_test.py index cb349a1..b66c478 100644 --- a/tests/spmd_test.py +++ b/tests/spmd_test.py @@ -148,5 +148,42 @@ class ParseTests(unittest2.TestCase): ])) self.assertEquals([Action, Action, Action], [type(p) for p in paras]) + def test_multiline_paragraph(self): + """Check that we don't join lines like Markdown does. + """ + paras = list(parse([ + 'They drink long and well from the beers.', + '', + "And then there's a long beat.", + "Longer than is funny. ", + " Long enough to be depressing.", + '', + 'The men look at each other.', + ])) + self.assertEquals([Action, Action, Action], [type(p) for p in paras]) + self.assertEquals( + [ + "And then there's a long beat.", + "Longer than is funny.", + "Long enough to be depressing.", + ], paras[1].lines + ) + + def test_multiline_dialog(self): + paras = list(parse([ + 'JULIET', + 'O Romeo, Romeo! wherefore art thou Romeo?', + ' Deny thy father and refuse thy name; ', + 'Or, if thou wilt not, be but sworn my love,', + " And I'll no longer be a Capulet.", + ])) + self.assertEquals([Dialog], [type(p) for p in paras]) + self.assertEquals([ + (False, 'O Romeo, Romeo! wherefore art thou Romeo?'), + (False, 'Deny thy father and refuse thy name;'), + (False, 'Or, if thou wilt not, be but sworn my love,'), + (False, "And I'll no longer be a Capulet."), + ], paras[0].blocks) + if __name__ == '__main__': unittest2.main() |
