aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2012-01-31 23:30:12 +0100
committerMartin Vilcans <martin@librador.com>2012-01-31 23:30:12 +0100
commit888addaa73f9615103fc70edd1e9a027755647e3 (patch)
treebec75dafc4fcf229c090d4f35dde6ad64b578caa
parentc58355251be5d92892163f13bc927c28a65ad30b (diff)
downloadscreenplain-888addaa73f9615103fc70edd1e9a027755647e3.tar.gz
Changed rules for forced Scene Headings (slugs).
Double linebreaks no longer signify a slug. Instead you can force one with a leading period: e.g. FADE IN: .DARKNESS (whatever that would look like!?)
-rw-r--r--screenplain/parsers/spmd.py12
-rw-r--r--tests/spmd_test.py17
2 files changed, 22 insertions, 7 deletions
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py
index 2c552e9..0c7ef19 100644
--- a/screenplain/parsers/spmd.py
+++ b/screenplain/parsers/spmd.py
@@ -30,12 +30,18 @@ preprocess_re = re.compile(r'^([ \t]*)(.*?)([ \t]*)[\r\n]*$')
def is_slug(blanks_before, line_list):
if len(line_list) != 1:
return False
- if blanks_before >= 2:
- return True
upper = line_list[0].upper()
+ if upper.startswith('.') and len(upper) > 1:
+ return True
return any(upper.startswith(s) for s in slug_prefixes)
+def _create_slug(line):
+ if line.startswith('.') and len(line) > 1:
+ line = line[1:]
+ return Slug(_to_rich([line])[0])
+
+
def _create_dialog(line_list):
dual_index = None
try:
@@ -66,7 +72,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])
+ return _create_slug(line_list[0])
elif all(centered_re.match(line) for line in line_list):
return Action(_to_rich(
centered_re.match(line).group(1) for line in line_list
diff --git a/tests/spmd_test.py b/tests/spmd_test.py
index 52b2348..34fddf7 100644
--- a/tests/spmd_test.py
+++ b/tests/spmd_test.py
@@ -43,14 +43,24 @@ class ParseTests(unittest2.TestCase):
]))
self.assertEquals([Action], [type(p) for p in paras])
- def test_two_lines_creates_a_slug(self):
+ def test_two_lines_creates_no_slug(self):
types = [type(p) for p in parse([
'',
'',
'This is a slug',
'',
])]
- self.assertEquals([Slug], types)
+ # This used to be Slug. Changed in the Jan 2012 version of the spec.
+ self.assertEquals([Action], types)
+
+ def test_period_creates_slug(self):
+ paras = parse([
+ '.SNIPER SCOPE POV',
+ '',
+ ])
+ self.assertEquals(1, len(paras))
+ self.assertEquals(Slug, type(paras[0]))
+ self.assertEquals(plain('SNIPER SCOPE POV'), paras[0].line)
# A Character element is any line entirely in caps, with one empty
# line before it and without an empty line after it.
@@ -196,8 +206,7 @@ class ParseTests(unittest2.TestCase):
'',
'> FADE OUT.',
'',
- '',
- 'DARKNESS',
+ '.DARKNESS',
]))
self.assertEquals([Action, Transition, Slug], [type(p) for p in paras])
self.assertEquals(plain('FADE OUT.'), paras[1].line)