diff options
-rw-r--r-- | screenplain/export/html.py | 26 | ||||
-rw-r--r-- | screenplain/main.py | 11 |
2 files changed, 33 insertions, 4 deletions
diff --git a/screenplain/export/html.py b/screenplain/export/html.py index 860deff..d0850c0 100644 --- a/screenplain/export/html.py +++ b/screenplain/export/html.py @@ -67,8 +67,23 @@ def _read_file(filename): return stream.read() -def convert(screenplay, out, annotated=False): +def convert(screenplay, out, bare=False): + """Convert the screenplay into HTML, written to the file-like object `out`. + The output will be a complete HTML document unless `bare` is true. + + """ + if bare: + convert_bare(screenplay, out) + else: + convert_full(screenplay, out) + + +def convert_full(screenplay, out): + """Convert the screenplay into a complete HTML document, + written to the file-like object `out`. + + """ css = _read_file('default.css') out.write( '<!DOCTYPE html>\n' @@ -84,7 +99,7 @@ def convert(screenplay, out, annotated=False): '<body>' '<div class="screenplay">\n' ) - convert_body_html(screenplay, out) + convert_bare(screenplay, out) out.write( '</div>' '</body>' @@ -92,7 +107,12 @@ def convert(screenplay, out, annotated=False): ) -def convert_body_html(screenplay, out): +def convert_bare(screenplay, out): + """Convert the screenplay into HTML, written to the file-like object `out`. + Does not create a complete HTML document, as it doesn't include + <html>, <body>, etc. + + """ for para in screenplay: if isinstance(para, Slug): # Slugs are h2 tags not inside a div diff --git a/screenplain/main.py b/screenplain/main.py index 2e7ee77..b6d8aea 100644 --- a/screenplain/main.py +++ b/screenplain/main.py @@ -22,6 +22,15 @@ def main(args): help=('Set what kind of file to create. FORMAT can be any of ' + ', '.join(output_formats)) ) + parser.add_option( + '--bare', + action='store_true', + dest='bare', + help=( + 'For HTML output, only output the actual screenplay, ' + 'not a complete HTML document.' + ) + ) options, args = parser.parse_args(args) if len(args) != 2: parser.error('Expected input-file and output-file arguments') @@ -59,7 +68,7 @@ def main(args): to_fdx(screenplay, output) elif options.output_format == 'html': from screenplain.export.html import convert - convert(screenplay, output) + convert(screenplay, output, bare=options.bare) finally: output.close() |