aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vilcans <martin@librador.com>2011-08-24 22:10:29 +0200
committerMartin Vilcans <martin@librador.com>2011-08-24 22:10:29 +0200
commit92330238d7701d1d0c372000aa3122de6cd63c02 (patch)
treebe0da653c060481bb6e9ed75ad906a86fc632355
parent6bf4f9ca6a68d32069db919cc81a555283d6f429 (diff)
downloadscreenplain-92330238d7701d1d0c372000aa3122de6cd63c02.tar.gz
Added annotated HTML output.
(File was missing.)
-rw-r--r--screenplain/export/annotated_html.py54
1 files changed, 54 insertions, 0 deletions
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('''
+<!doctype html>
+<html>
+ <head>
+ <link rel="stylesheet" href="/style.css">
+ </head>
+ <body>
+''')
+
+paragraph_html = unspace("""
+<div class="block">
+ <p>%(margin)s</p>
+ <div class="type type%(type)s">%(type)s</div>
+ <p>%(text)s</p>
+</div>
+""")
+
+foot = unspace('''
+ </body>
+</html>
+''')
+
+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(' ', '&nbsp; ', cgi.escape(text))
+
+def to_annotated_html(input, out):
+ paragraphs = parse(input)
+ out.write(head)
+ for para in paragraphs:
+ lines = para.format()
+ margin = '<br>' * para.top_margin
+ html_text = '<br>'.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)