aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2011-12-16 23:41:56 +0100
committerMartin Vilcans <martin@librador.com>2011-12-16 23:45:01 +0100
commit8485c49836ea746016101e6fc3f941564ced75c3 (patch)
treebb42f702c87968c6a7c3de7f0f4cfd2b4a3ae66a
parent1f76285463d19f21e7e09ddb8c6fc876ea2c8740 (diff)
downloadscreenplain-8485c49836ea746016101e6fc3f941564ced75c3.tar.gz
A leading ">" on a line means it's parsed as a transition.
(But only if it's the last paragraph or followed by a slug.)
-rw-r--r--screenplain/parsers/spmd.py14
-rw-r--r--tests/spmd_test.py21
2 files changed, 30 insertions, 5 deletions
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py
index 621e8df..7bdb79b 100644
--- a/screenplain/parsers/spmd.py
+++ b/screenplain/parsers/spmd.py
@@ -67,6 +67,7 @@ def _to_rich(line_list):
def create_paragraph(blanks_before, line_list):
+ first_line = line_list[0]
if is_slug(blanks_before, line_list):
return Slug(_to_rich(line_list)[0])
elif all(centered_re.match(line) for line in line_list):
@@ -75,17 +76,20 @@ def create_paragraph(blanks_before, line_list):
), centered=True)
elif (
len(line_list) > 1 and
- line_list[0].isupper() and
- not line_list[0].endswith(TWOSPACE)
+ first_line.isupper() and
+ not first_line.endswith(TWOSPACE)
):
return _create_dialog(line_list)
elif (
- len(line_list) == 1 and
- line_list[0].endswith(':') and line_list[0].isupper()
+ len(line_list) == 1 and first_line.isupper()
+ and (first_line.endswith(':') or first_line.startswith('>'))
):
# Assume this is a transition. It may be changed to Action
# later if we find that it's not followed by a slug.
- return Transition(_to_rich(line_list)[0])
+ if first_line.startswith('>'):
+ return Transition(_to_rich([first_line[1:]])[0])
+ else:
+ return Transition(_to_rich([first_line])[0])
else:
return Action(_to_rich(line_list))
diff --git a/tests/spmd_test.py b/tests/spmd_test.py
index 2efa2d4..52b2348 100644
--- a/tests/spmd_test.py
+++ b/tests/spmd_test.py
@@ -190,6 +190,27 @@ class ParseTests(unittest2.TestCase):
]))
self.assertEquals([Action, Action, Action], [type(p) for p in paras])
+ def test_greater_than_sign_means_transition(self):
+ paras = list(parse([
+ 'Bill blows out the match.',
+ '',
+ '> FADE OUT.',
+ '',
+ '',
+ 'DARKNESS',
+ ]))
+ self.assertEquals([Action, Transition, Slug], [type(p) for p in paras])
+ self.assertEquals(plain('FADE OUT.'), paras[1].line)
+
+ def test_transition_at_end(self):
+ paras = list(parse([
+ 'They stroll hand in hand down the street.',
+ '',
+ '> FADE OUT.',
+ ]))
+ self.assertEquals([Action, Transition], [type(p) for p in paras])
+ self.assertEquals(plain('FADE OUT.'), paras[1].line)
+
def test_multiline_paragraph(self):
"""Check that we don't join lines like Markdown does.
"""