diff options
author | Martin Vilcans <martin@librador.com> | 2011-09-21 23:36:40 +0200 |
---|---|---|
committer | Martin Vilcans <martin@librador.com> | 2011-09-21 23:36:40 +0200 |
commit | 8372179a6d8426896737d6c37a5568fdea5dce5f (patch) | |
tree | 4181d3edf92dced69f36aa716b5e2b224b3a03f6 | |
parent | f38a458da58b0cbd456ff935f8a8f84f1a1f385d (diff) | |
download | screenplain-8372179a6d8426896737d6c37a5568fdea5dce5f.tar.gz |
Added requirement that a slug must be only one line.
Otherwise it is parsed as dialog.
-rw-r--r-- | screenplain/parsers/spmd.py | 8 | ||||
-rw-r--r-- | tests/spmd_test.py | 13 |
2 files changed, 18 insertions, 3 deletions
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py index ff9ac67..4e81386 100644 --- a/screenplain/parsers/spmd.py +++ b/screenplain/parsers/spmd.py @@ -17,10 +17,12 @@ TWOSPACE = ' ' * 2 def is_blank(string): return string == '' or string.isspace() and string != ' ' -def is_slug(blanks_before, string): +def is_slug(blanks_before, line_list): + if len(line_list) != 1: + return False if blanks_before >= 2: return True - upper = string.upper() + upper = line_list[0].upper() return any(upper.startswith(s) for s in slug_prefixes) def _create_dialog(line_list): @@ -32,7 +34,7 @@ def _create_dialog(line_list): return DualDialog(line_list[:dual_index], line_list[dual_index + 1:]) def create_paragraph(blanks_before, line_list): - if is_slug(blanks_before, line_list[0]): + if is_slug(blanks_before, line_list): return Slug(line_list) if ( len(line_list) > 1 and diff --git a/tests/spmd_test.py b/tests/spmd_test.py index 4a04660..5df8395 100644 --- a/tests/spmd_test.py +++ b/tests/spmd_test.py @@ -17,6 +17,19 @@ class ParseTests(unittest2.TestCase): ])) self.assertEquals([Slug, Action], [type(p) for p in paras]) + def test_slug_must_be_single_line(self): + paras = list(parse([ + 'INT. SOMEWHERE - DAY', + 'ANOTHER LINE', + '', + 'Some action', + ])) + self.assertEquals([Dialog, Action], [type(p) for p in paras]) + # What looks like a scene headingis parsed as a character name. + # Unexpected perhaps, but that's how I interpreted the spec. + self.assertEquals('INT. SOMEWHERE - DAY', paras[0].character) + self.assertEquals(['Some action'], paras[1].lines) + def test_action_is_not_a_slug(self): paras = list(parse([ '', |