diff options
-rw-r--r-- | screenplain/parsers/spmd.py | 15 | ||||
-rw-r--r-- | screenplain/types.py | 6 | ||||
-rw-r--r-- | tests/spmd_test.py | 38 |
3 files changed, 59 insertions, 0 deletions
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py index f9aa643..4083725 100644 --- a/screenplain/parsers/spmd.py +++ b/screenplain/parsers/spmd.py @@ -50,6 +50,7 @@ class InputParagraph(object): Modifies the `previous_paragraphs` list. """ previous_paragraphs.append( + self.as_synopsis(previous_paragraphs) or self.as_section() or self.as_slug() or self.as_centered_action() or @@ -139,6 +140,19 @@ class InputParagraph(object): def as_action(self): return Action(_to_rich(line.rstrip() for line in self.lines)) + def as_synopsis(self, previous_paragraphs): + if ( + len(self.lines) == 1 and + self.lines[0].startswith('=') and + previous_paragraphs and + hasattr(previous_paragraphs[-1], 'set_synopsis') + ): + paragraph = previous_paragraphs.pop() + paragraph.set_synopsis(self.lines[0][1:].lstrip()) + return paragraph + else: + return None + def _preprocess_line(raw_line): r"""Replaces tabs with spaces and removes trailing end of line markers. @@ -183,6 +197,7 @@ def parse_body(source): return paragraphs + def parse_title_page(lines): result = {} diff --git a/screenplain/types.py b/screenplain/types.py index d814af3..8c10692 100644 --- a/screenplain/types.py +++ b/screenplain/types.py @@ -20,6 +20,9 @@ class Slug(object): def lines(self): return [self.line] + def set_synopsis(self, text): + self.synopsis = text + class Section(object): """A section heading.""" @@ -27,6 +30,9 @@ class Section(object): self.text = text self.level = level + def set_synopsis(self, text): + self.synopsis = text + class Dialog(object): def __init__(self, character, lines): diff --git a/tests/spmd_test.py b/tests/spmd_test.py index bb5f463..ab371cb 100644 --- a/tests/spmd_test.py +++ b/tests/spmd_test.py @@ -333,6 +333,44 @@ class ParseTests(unittest2.TestCase): self.assertFalse(paras[0].centered) self.assertEquals([plain(line) for line in lines], paras[0].lines) + def test_synopsis_after_slug_adds_synopsis_to_scene(self): + paras = list(parse([ + "EXT. BRICK'S PATIO - DAY", + '', + "= Set up Brick & Steel's new life." + '', + ])) + self.assertEquals([Slug], [type(p) for p in paras]) + self.assertEquals( + "Set up Brick & Steel's new life.", + paras[0].synopsis + ) + + def test_synopsis_in_section(self): + paras = list(parse([ + '# section one', + '', + '= In which we get to know our characters' + ])) + self.assertEquals([Section], [type(p) for p in paras]) + self.assertEquals( + 'In which we get to know our characters', + paras[0].synopsis + ) + + def test_synopsis_syntax_parsed_as_literal(self): + paras = list(parse([ + 'Some action', + '', + '= A line that just happens to look like a synopsis' + ])) + self.assertEquals([Action, Action], [type(p) for p in paras]) + self.assertEquals( + [plain('= A line that just happens to look like a synopsis')], + paras[1].lines + ) + + class TitlePageTests(unittest2.TestCase): def test_basic_title_page(self): |