diff options
-rw-r--r-- | screenplain/__init__.py | 1 | ||||
-rw-r--r-- | screenplain/export/annotated_html.py | 4 | ||||
-rw-r--r-- | screenplain/export/pdf.py | 1 | ||||
-rw-r--r-- | screenplain/export/text.py | 1 | ||||
-rw-r--r-- | screenplain/main.py | 1 | ||||
-rw-r--r-- | screenplain/parsers/spmd.py | 11 | ||||
-rw-r--r-- | screenplain/richstring.py | 8 | ||||
-rw-r--r-- | screenplain/types.py | 5 | ||||
-rw-r--r-- | tests/richstring_test.py | 3 | ||||
-rw-r--r-- | tests/spmd_test.py | 1 |
10 files changed, 32 insertions, 4 deletions
diff --git a/screenplain/__init__.py b/screenplain/__init__.py index 8b13789..e69de29 100644 --- a/screenplain/__init__.py +++ b/screenplain/__init__.py @@ -1 +0,0 @@ - diff --git a/screenplain/export/annotated_html.py b/screenplain/export/annotated_html.py index 64c38ee..a566701 100644 --- a/screenplain/export/annotated_html.py +++ b/screenplain/export/annotated_html.py @@ -3,6 +3,7 @@ import re import cgi from screenplain.types import * + def unspace(text): text = re.sub(r'\s*\n\s*', '\n', text) text = re.sub(r'\s\s+', ' ', text) @@ -25,9 +26,11 @@ types = { Transition: 'Transition', } + def to_html(text): return re.sub(' ', ' ', cgi.escape(text)) + def to_annotated_html(screenplay, out): for para in screenplay: lines = para.format() @@ -41,4 +44,3 @@ def to_annotated_html(screenplay, out): 'margin': margin } out.write(paragraph_html % data) - diff --git a/screenplain/export/pdf.py b/screenplain/export/pdf.py index d1b920b..eca7cac 100644 --- a/screenplain/export/pdf.py +++ b/screenplain/export/pdf.py @@ -5,6 +5,7 @@ from reportlab.lib import pagesizes from screenplain.format import get_pages + def to_pdf(screenplay, output_file): # pagesizes.letter, pagesizes.A4 page_width, page_height = pagesizes.A4 diff --git a/screenplain/export/text.py b/screenplain/export/text.py index d4c5b77..bb7d604 100644 --- a/screenplain/export/text.py +++ b/screenplain/export/text.py @@ -2,6 +2,7 @@ import sys import codecs from screenplain.format import get_pages + def to_text(screenplay, out): for page_no, page in enumerate(get_pages(screenplay)): # page_no is 0-based diff --git a/screenplain/main.py b/screenplain/main.py index a2d6c1f..2c114a6 100644 --- a/screenplain/main.py +++ b/screenplain/main.py @@ -16,6 +16,7 @@ output_formats = ( usage = 'Usage: %prog [options] input-file output-file' + def main(args): parser = OptionParser(usage=usage) parser.add_option( diff --git a/screenplain/parsers/spmd.py b/screenplain/parsers/spmd.py index 4e81386..0183376 100644 --- a/screenplain/parsers/spmd.py +++ b/screenplain/parsers/spmd.py @@ -14,9 +14,11 @@ slug_prefixes = ( TWOSPACE = ' ' * 2 + def is_blank(string): return string == '' or string.isspace() and string != ' ' + def is_slug(blanks_before, line_list): if len(line_list) != 1: return False @@ -25,6 +27,7 @@ def is_slug(blanks_before, line_list): upper = line_list[0].upper() return any(upper.startswith(s) for s in slug_prefixes) + def _create_dialog(line_list): try: dual_index = line_list.index('||') @@ -33,6 +36,7 @@ def _create_dialog(line_list): else: 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): return Slug(line_list) @@ -42,13 +46,17 @@ def create_paragraph(blanks_before, line_list): not line_list[0].endswith(TWOSPACE) ): return _create_dialog(line_list) - elif len(line_list) == 1 and line_list[0].endswith(':') and line_list[0].isupper(): + elif ( + len(line_list) == 1 and + line_list[0].endswith(':') and line_list[0].isupper() + ): # 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(line_list) else: return Action(line_list) + def clean_line(line): """Strips leading whitespace and trailing end of line characters in a string. @@ -58,6 +66,7 @@ def clean_line(line): """ return line.lstrip().rstrip('\r\n') + def parse(source): """Reads raw text input and generates paragraph objects.""" blank_count = 0 diff --git a/screenplain/richstring.py b/screenplain/richstring.py index 7543aaf..f48f54b 100644 --- a/screenplain/richstring.py +++ b/screenplain/richstring.py @@ -20,6 +20,7 @@ _emphasis = re.compile( r')' ) + class RichString(object): def __init__(self, *segments): self.segments = segments @@ -54,18 +55,22 @@ class RichString(object): self.segments != other.segments ) + class Italic(RichString): def to_html(self): return '<em>' + super(Italic, self).to_html() + '</em>' + class Bold(RichString): def to_html(self): return '<strong>' + super(Bold, self).to_html() + '</strong>' + class Underline(RichString): def to_html(self): return '<u>' + super(Underline, self).to_html() + '</u>' + def _parse(source): segments = [] @@ -95,10 +100,11 @@ def _parse(source): return segments + def parse_emphasis(source): """Parses emphasis markers like * and ** in a string and returns a RichString object. - + >>> parse_emphasis(u'**hello**') Bold(u'hello') >>> parse_emphasis(u'plain') diff --git a/screenplain/types.py b/screenplain/types.py index fe3c849..d7d5c7c 100644 --- a/screenplain/types.py +++ b/screenplain/types.py @@ -1,5 +1,6 @@ import textwrap + class Slug(object): indent = '' top_margin = 1 @@ -10,6 +11,7 @@ class Slug(object): def format(self): return self.lines + class Dialog(object): indent_character = ' ' * 22 indent_dialog = ' ' * 10 @@ -57,6 +59,7 @@ class Dialog(object): for line in lines: yield line + class DualDialog(object): top_margin = 1 @@ -73,6 +76,7 @@ class DualDialog(object): for left, right in zip(llines, rlines): yield '%-34s%s' % (left, right) + class Action(object): indent = '' fill = 68 @@ -86,6 +90,7 @@ class Action(object): for line in textwrap.wrap(logical_line, width=self.fill): yield self.indent + line + class Transition(object): indent = '' fill = 68 diff --git a/tests/richstring_test.py b/tests/richstring_test.py index bd7ea22..258cdb1 100644 --- a/tests/richstring_test.py +++ b/tests/richstring_test.py @@ -3,6 +3,7 @@ from screenplain.richstring import RichString, Bold, Italic, Underline from screenplain.richstring import parse_emphasis from screenplain.types import Slug, Action, Dialog, DualDialog, Transition + class RichStringOperatorTests(unittest2.TestCase): def test_repr(self): @@ -28,6 +29,7 @@ class RichStringOperatorTests(unittest2.TestCase): def test_ne(self): self.assertFalse(Bold('Hello') != Bold('Hello')) + class RichStringTests(unittest2.TestCase): def test_to_html(self): @@ -42,6 +44,7 @@ class RichStringTests(unittest2.TestCase): s.to_html() ) + class ParseEmphasisTests(unittest2.TestCase): def test_parse_without_emphasis(self): diff --git a/tests/spmd_test.py b/tests/spmd_test.py index 5df8395..d4e8c5d 100644 --- a/tests/spmd_test.py +++ b/tests/spmd_test.py @@ -2,6 +2,7 @@ import unittest2 from screenplain.parsers.spmd import parse from screenplain.types import Slug, Action, Dialog, DualDialog, Transition + class ParseTests(unittest2.TestCase): # A Scene Heading, or "slugline," is any line that has a blank |