diff options
author | Martin Vilcans <martin@librador.com> | 2011-09-27 21:40:28 +0200 |
---|---|---|
committer | Martin Vilcans <martin@librador.com> | 2011-09-27 21:40:28 +0200 |
commit | 88e2d8a3fb158bad057de614f57e3c2b1490b7c5 (patch) | |
tree | e780f1bf5e287d94d6eecedfc01782ef587262f7 | |
parent | d09d1b2c57a2a8900c33b78840600b7cc1ca40a8 (diff) | |
download | screenplain-88e2d8a3fb158bad057de614f57e3c2b1490b7c5.tar.gz |
When exporting HTML, use HTML styles for formatting.
-rw-r--r-- | screenplain/export/annotated_html.py | 62 | ||||
-rw-r--r-- | screenplain/richstring.py | 3 | ||||
-rw-r--r-- | screenplain/types.py | 5 |
3 files changed, 53 insertions, 17 deletions
diff --git a/screenplain/export/annotated_html.py b/screenplain/export/annotated_html.py index a566701..0690c2f 100644 --- a/screenplain/export/annotated_html.py +++ b/screenplain/export/annotated_html.py @@ -13,33 +13,71 @@ def unspace(text): paragraph_html = unspace(""" <div class="block"> %(margin)s - <div class="type type%(type)s">%(type)s</div> + <div class="type %(type)s">%(type)s</div> %(text)s </div> """) types = { - Slug: 'Slug', - Dialog: 'Dialog', - DualDialog: 'Dual', - Action: 'Action', - Transition: 'Transition', + Slug: 'slug', + Dialog: 'dialog', + DualDialog: 'dual', + Action: 'action', + Transition: 'transition', } def to_html(text): - return re.sub(' ', ' ', cgi.escape(text)) + return re.sub(' ', ' ', text.to_html()) + + +def format_dialog(dialog): + yield '<p class="character">%s</p>' % to_html(dialog.character) + + for parenthetical, text in dialog.blocks: + yield '<p class="%s">%s</p>' % ( + 'parenthetical' if parenthetical else 'dialog', + to_html(text) + ) + + +def format_dual(dual): + yield ( + '<div class="dual-dialog">' + '<div class="dual left">' + ) + for html in format_dialog(dual.left): + yield html + yield ( + '</div>' + '<div class="dual right">' + ) + for html in format_dialog(dual.right): + yield html + yield ( + '</div>' + '<br/>' + '</div>' + ) def to_annotated_html(screenplay, out): for para in screenplay: - lines = para.format() + classname = types.get(type(para)) + if isinstance(para, Dialog): + html_text = ''.join(format_dialog(para)) + elif isinstance(para, DualDialog): + html_text = ''.join(format_dual(para)) + else: + lines = para.lines + html_text = ''.join( + '<p class="%s">%s</p>' % (classname, to_html(line)) + for line in para.lines + ) + margin = '<p> </p>' * para.top_margin - html_text = ''.join( - '<p>%s</p>' % to_html(line) for line in lines - ) data = { - 'type': types.get(type(para), '?'), + 'type': classname, 'text': html_text, 'margin': margin } diff --git a/screenplain/richstring.py b/screenplain/richstring.py index 39b4999..54b5794 100644 --- a/screenplain/richstring.py +++ b/screenplain/richstring.py @@ -1,4 +1,5 @@ import re +import cgi _emphasis = re.compile( r'(?:' @@ -29,7 +30,7 @@ class RichString(object): result = '' for segment in self.segments: if isinstance(segment, basestring): - result += segment + result += cgi.escape(segment) else: result += segment.to_html() return result diff --git a/screenplain/types.py b/screenplain/types.py index 7c71b1e..460b6aa 100644 --- a/screenplain/types.py +++ b/screenplain/types.py @@ -62,10 +62,7 @@ class Dialog(object): class DualDialog(object): top_margin = 1 - def __init__(self, - character1, lines1, - character2, lines2 - ): + def __init__(self, character1, lines1, character2, lines2): self.left = Dialog(character1, lines1) self.right = Dialog(character2, lines2) |