aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2011-11-15 21:17:40 +0100
committerMartin Vilcans <martin@librador.com>2011-11-15 21:17:40 +0100
commitddda345a77ee4232002e5179b3ba7992a112af76 (patch)
treed80fa7698e23a1b7c46a21bd03b4a825cc688dd6
parent083800d933041f7a35cb19011d68d1e51c7f8b9f (diff)
downloadscreenplain-ddda345a77ee4232002e5179b3ba7992a112af76.tar.gz
Added support for >centering text<
-rw-r--r--screenplain/export/fdx.py22
-rw-r--r--screenplain/parsers/spmd.py14
-rw-r--r--screenplain/types.py7
-rw-r--r--tests/spmd_test.py23
4 files changed, 54 insertions, 12 deletions
diff --git a/screenplain/export/fdx.py b/screenplain/export/fdx.py
index 937963d..3644714 100644
--- a/screenplain/export/fdx.py
+++ b/screenplain/export/fdx.py
@@ -4,11 +4,6 @@ from screenplain.types import *
from screenplain.richstring import RichString
from screenplain.richstring import Bold, Italic, Underline
-paragraph_types = {
- Slug: 'Scene Heading',
- Action: 'Action',
- Transition: 'Transition',
-}
style_names = {
Bold: 'Bold',
@@ -36,8 +31,12 @@ def write_text(out, rich, trailing_linebreak):
else:
_write_text_element(out, fdx_styles, segment.text)
-def write_paragraph(out, para_type, lines):
- out.write(' <Paragraph Type="%s">\n' % para_type)
+def write_paragraph(out, para_type, lines, centered=False):
+ if centered:
+ out.write(' <Paragraph Alignment="Center" Type="%s">\n' % para_type)
+ else:
+ out.write(' <Paragraph Type="%s">\n' % para_type)
+
last_line_no = len(lines) - 1
for line_no, line in enumerate(lines):
write_text(out, line, line_no != last_line_no)
@@ -80,9 +79,14 @@ def to_fdx(screenplay, out):
write_dialog(out, para)
elif isinstance(para, DualDialog):
write_dual_dialog(out, para)
+ elif isinstance(para, Action):
+ write_paragraph(out, 'Action', para.lines, centered=para.centered)
+ elif isinstance(para, Slug):
+ write_paragraph(out, 'Scene Heading', para.lines)
+ elif isinstance(para, Transition):
+ write_paragraph(out, 'Transition', para.lines)
else:
- para_type = paragraph_types[type(para)]
- write_paragraph(out, para_type, para.lines)
+ raise RuntimeError('Unknown type: %s' % type(para))
out.write(
' </Content>\n'
'</FinalDraft>\n'
diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py
index 27778c3..7b0f361 100644
--- a/screenplain/parsers/spmd.py
+++ b/screenplain/parsers/spmd.py
@@ -1,5 +1,9 @@
import itertools
-from screenplain.types import Slug, Action, Dialog, DualDialog, Transition
+import re
+
+from screenplain.types import (
+ Slug, Action, Dialog, DualDialog, Transition
+)
from screenplain.richstring import parse_emphasis
slug_prefixes = (
@@ -15,6 +19,7 @@ slug_prefixes = (
TWOSPACE = ' ' * 2
+centered_re = re.compile(r'\s*>\s*(.*)\s*<$')
def is_blank(string):
return string == '' or string.isspace() and string != ' '
@@ -73,7 +78,12 @@ def create_paragraph(blanks_before, line_list):
# later if we find that it's not followed by a slug.
return Transition(_to_rich(line_list))
else:
- return Action(_to_rich(line_list))
+ if 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
+ ), centered=True)
+ else:
+ return Action(_to_rich(line_list))
def clean_line(line):
diff --git a/screenplain/types.py b/screenplain/types.py
index 460b6aa..c81ffd2 100644
--- a/screenplain/types.py
+++ b/screenplain/types.py
@@ -81,8 +81,9 @@ class Action(object):
fill = 68
top_margin = 1
- def __init__(self, lines):
+ def __init__(self, lines, centered=False):
self.lines = lines
+ self.centered = centered
def format(self):
for logical_line in self.lines:
@@ -90,6 +91,10 @@ class Action(object):
yield self.indent + line
+class Centered(Action):
+ pass
+
+
class Transition(object):
indent = ''
fill = 68
diff --git a/tests/spmd_test.py b/tests/spmd_test.py
index fbc7867..f1c62bf 100644
--- a/tests/spmd_test.py
+++ b/tests/spmd_test.py
@@ -208,5 +208,28 @@ class ParseTests(unittest2.TestCase):
(False, plain("And I'll no longer be a Capulet.")),
], paras[0].blocks)
+ def test_single_centered_line(self):
+ paras = list(parse(['> center me! <']))
+ self.assertEquals([Action], [type(p) for p in paras])
+ self.assertTrue(paras[0].centered)
+
+ def test_full_centered_paragraph(self):
+ paras = list(parse([
+ '> first! <',
+ ' > second! <',
+ '> third! <',
+ ]))
+ self.assertEquals([Action], [type(p) for p in paras])
+ self.assertTrue(paras[0].centered)
+
+ def test_centering_marks_in_middle_of_paragraphs_are_verbatim(self):
+ paras = list(parse([
+ 'first!',
+ '> second! <',
+ 'third!',
+ ]))
+ self.assertEquals([Action], [type(p) for p in paras])
+ self.assertFalse(paras[0].centered)
+
if __name__ == '__main__':
unittest2.main()