From 92330238d7701d1d0c372000aa3122de6cd63c02 Mon Sep 17 00:00:00 2001 From: Martin Vilcans Date: Wed, 24 Aug 2011 22:10:29 +0200 Subject: Added annotated HTML output. (File was missing.) --- screenplain/export/annotated_html.py | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 screenplain/export/annotated_html.py diff --git a/screenplain/export/annotated_html.py b/screenplain/export/annotated_html.py new file mode 100644 index 0000000..1603e9a --- /dev/null +++ b/screenplain/export/annotated_html.py @@ -0,0 +1,54 @@ +import sys +import re +import cgi +from screenplain.parse import parse +import screenplain.parse + +def unspace(text): + text = re.sub(r'\s+', ' ', text) + text = re.sub(r'>\s+<', '><', text) + return text.strip() + +head = unspace(''' + + + + + + +''') + +paragraph_html = unspace(""" +
+

%(margin)s

+
%(type)s
+

%(text)s

+
+""") + +foot = unspace(''' + + +''') + +types = { + screenplain.parse.Slug: 'Slug', + screenplain.parse.Dialog: 'Dialog', + screenplain.parse.DualDialog: 'Dual', + screenplain.parse.Action: 'Action', + screenplain.parse.Transition: 'Transition', +} + +def to_html(text): + return re.sub(' ', '  ', cgi.escape(text)) + +def to_annotated_html(input, out): + paragraphs = parse(input) + out.write(head) + for para in paragraphs: + lines = para.format() + margin = '
' * para.top_margin + html_text = '
'.join(to_html(line) for line in lines) + data = { 'type': types.get(type(para), '?'), 'text': html_text, 'margin': margin } + out.write(paragraph_html % data) + out.write(foot) -- cgit v1.2.3