aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2015-11-17 08:49:32 +0100
committerMartin Vilcans <martin@librador.com>2015-11-17 08:49:32 +0100
commitd4a721b470a960e71a683b8ebff61b26c868d1cd (patch)
tree4468ee69a0620e04e777aaf3b1997b6d7a3517cd
parentf52103e567f18c652b8b9f28bbe8a1d754a78471 (diff)
downloadscreenplain-d4a721b470a960e71a683b8ebff61b26c868d1cd.tar.gz
Support non-alphanumeric character names with "@"
Fixes #22
-rw-r--r--screenplain/parsers/fountain.py6
-rw-r--r--tests/fountain_test.py16
2 files changed, 19 insertions, 3 deletions
diff --git a/screenplain/parsers/fountain.py b/screenplain/parsers/fountain.py
index 9b0c6c7..3290dd2 100644
--- a/screenplain/parsers/fountain.py
+++ b/screenplain/parsers/fountain.py
@@ -128,7 +128,11 @@ class InputParagraph(object):
return False
character = self.lines[0]
- if not character.isupper() or character.endswith(TWOSPACE):
+ if character.endswith(TWOSPACE):
+ return False
+ if character.startswith('@') and len(character) >= 2:
+ character = character[1:]
+ elif not character.isupper():
return False
if paragraphs and isinstance(paragraphs[-1], Dialog):
diff --git a/tests/fountain_test.py b/tests/fountain_test.py
index 9a5d308..95a4a81 100644
--- a/tests/fountain_test.py
+++ b/tests/fountain_test.py
@@ -148,8 +148,10 @@ class DialogTests(TestCase):
self.assertEquals(Dialog, type(dialog))
self.assertEquals(plain('SOME GUY'), dialog.character)
- # Fountain would not be able to support a character named "23". We
- # might need a syntax to force a character element.
+
+ # Spec http://fountain.io/syntax#section-character:
+ # Character names must include at least one alphabetical character.
+ # "R2D2" works, but "23" does not.
def test_nonalpha_character(self):
paras = parse([
'23',
@@ -157,6 +159,16 @@ class DialogTests(TestCase):
])
self.assertEquals([Action], [type(p) for p in paras])
+ # Spec http://fountain.io/syntax#section-character:
+ # You can force a Character element by preceding it with the "at" symbol @.
+ def test_at_sign_forces_dialog(self):
+ paras = parse([
+ '@McCLANE',
+ 'Yippee ki-yay',
+ ])
+ self.assertEquals([Dialog], [type(p) for p in paras])
+ self.assertEquals(plain('McCLANE'), paras[0].character)
+
def test_twospaced_line_is_not_character(self):
paras = parse([
'SCANNING THE AISLES... ',