Renderer Module¶
Renderers for Fountain documents.
This module provides renderers for converting parsed Fountain documents into various output formats. The primary renderers are HTMLRenderer for web display and FountainRenderer for round-trip conversion back to Fountain markup.
- Classes:
HTMLRenderer: Converts Fountain documents to HTML with screenplay formatting. FountainRenderer: Converts Fountain documents back to Fountain markup format.
Example
Basic rendering of a Fountain document to HTML:
>>> from fountain.parser import FountainParser
>>> from fountain.renderer import HTMLRenderer
>>> parser = FountainParser()
>>> doc = parser.parse("INT. HOUSE - DAY\n\nAction here.")
>>> renderer = HTMLRenderer()
>>> html = renderer.render(doc)
>>> '<div class="fountain-scene-heading">INT. HOUSE - DAY</div>' in html
True
- class fountain.renderer.HTMLRenderer[source]¶
Bases:
objectRenders Fountain documents as HTML with screenplay formatting.
The HTMLRenderer converts parsed Fountain documents into HTML with proper screenplay formatting, including CSS styles that follow industry-standard screenplay layout conventions. It handles all Fountain element types and preserves formatting marks like bold, italic, and underline.
The renderer provides three output modes:
render(doc)— Pure HTML fragment for embedding (no CSS)render_page(doc)— Standalone HTML with embedded CSSget_css()— Raw CSS string for external stylesheet use
- CSS Classes Generated:
fountain-script: Main container for the entire screenplay
fountain-title-page: Container for title page metadata
fountain-script-body: Container for the main screenplay content
fountain-scene-heading: Scene headers (INT/EXT)
fountain-action: Action/description paragraphs
fountain-character: Character names before dialogue
fountain-dialogue: Spoken dialogue text
fountain-parenthetical: Stage directions within dialogue
fountain-transition: Scene transitions (CUT TO:, etc.)
fountain-dual-dialogue: Container for simultaneous dialogue
fountain-page-break: Page break markers
fountain-centered: Centered text
fountain-lyrics: Song lyrics with special formatting
Notes, sections, synopses, and boneyard are writer tools. They are hidden from the formatted output by default and emit no markup, so no CSS classes are generated for them.
Example
Render a simple screenplay to HTML:
>>> from fountain.parser import FountainParser >>> from fountain.renderer import HTMLRenderer >>> parser = FountainParser() >>> doc = parser.parse('''Title: My Screenplay ... Author: Jane Doe ... ... INT. COFFEE SHOP - DAY ... ... JOHN enters, looking tired. ... ... JOHN ... I need coffee. ... ''') >>> renderer = HTMLRenderer() >>> html = renderer.render(doc) >>> '<h1 class="fountain-title">My Screenplay</h1>' in html True >>> '<div class="fountain-character">JOHN</div>' in html True
- render(document)[source]¶
Render a FountainDocument as an HTML fragment.
Returns a pure HTML fragment suitable for embedding in web pages, documentation systems, or any context where CSS is managed externally. Use
render_page()for standalone HTML with embedded CSS.- Parameters:
document (FountainDocument) – The FountainDocument to render, containing parsed elements and optional title page metadata.
- Returns:
An HTML fragment string containing the screenplay markup wrapped in a
<div class="fountain-script">container. Does not include<style>tags or CSS.- Return type:
Example
>>> from fountain.parser import FountainParser >>> parser = FountainParser() >>> doc = parser.parse("INT. ROOM - DAY\n\nAction here.") >>> renderer = HTMLRenderer() >>> html = renderer.render(doc) >>> '<div class="fountain-script">' in html True >>> '<style>' not in html True
- render_page(document)[source]¶
Render a FountainDocument as a standalone HTML page with embedded CSS.
Returns a complete HTML string with a
<style>block and the screenplay fragment. Suitable for saving as a self-contained HTML file.- Parameters:
document (FountainDocument) – The FountainDocument to render.
- Returns:
A complete HTML string with embedded CSS styling followed by the screenplay markup.
- Return type:
Example
>>> from fountain.parser import FountainParser >>> parser = FountainParser() >>> doc = parser.parse("INT. ROOM - DAY\n\nAction here.") >>> renderer = HTMLRenderer() >>> html = renderer.render_page(doc) >>> '<style>' in html True >>> '<div class="fountain-script">' in html True
- get_css()[source]¶
Return the raw CSS string for screenplay formatting.
Returns the CSS rules without
<style>tags, so consumers can inject the styles however they need (e.g., into an external stylesheet, a<link>tag, or a build system’s CSS pipeline).- Returns:
A string containing CSS rules for all Fountain element types.
- Return type:
Example
>>> renderer = HTMLRenderer() >>> css = renderer.get_css() >>> '.fountain-script' in css True >>> '<style>' not in css True
- class fountain.renderer.FountainRenderer[source]¶
Bases:
objectRenders FountainDocument back to Fountain markup format.
The FountainRenderer provides round-trip conversion from parsed Fountain documents back to Fountain markup text. This is useful for programmatic manipulation of screenplays, formatting cleanup, or conversion workflows.
- Round-Trip Capabilities:
Preserves every element type and its order through parse -> render -> parse: scene headings, action, character cues, parentheticals, dialogue, transitions, dual dialogue, lyrics, sections, synopses, and notes all keep their types
Preserves the blank-line boundaries between structural blocks, so a character cue is not merged into the preceding action on re-parse (requirements A4, A4b, A4c)
Maintains title page metadata fields
Handles forced elements (scenes, action, transitions)
Preserves scene numbers and character extensions
Re-emits inline emphasis markers (
**,*,_,***) from the formatting spans, escaping literal*,_, and\characters
- Round-Trip Limitations:
Exact whitespace formatting may differ from original
Comments in boneyard sections are maintained but may be reformatted
Line breaks within elements are preserved but spacing may normalize
Original capitalization in scene headings is preserved
The renderer attempts to produce valid Fountain markup that will parse back to an equivalent document structure, though the exact text representation may differ from the original due to normalization during parsing.
Example
Basic round-trip conversion:
>>> from fountain.parser import FountainParser >>> from fountain.renderer import FountainRenderer >>> parser = FountainParser() >>> original = "INT. HOUSE - DAY\n\nJohn enters.\n\nJOHN\nHello!" >>> doc = parser.parse(original) >>> renderer = FountainRenderer() >>> fountain_text = renderer.render(doc) >>> # Re-parse to verify round-trip >>> doc2 = parser.parse(fountain_text) >>> len(doc.elements) == len(doc2.elements) True
- render(document)[source]¶
Render a FountainDocument as Fountain markup.
Converts a parsed Fountain document back into Fountain markup text format. This enables round-trip conversion and programmatic screenplay manipulation.
- Parameters:
document (FountainDocument) – The FountainDocument to render, containing parsed elements and optional title page metadata.
- Returns:
A string containing valid Fountain markup that represents the document. The output can be saved as a .fountain file or parsed again.
- Return type:
Example
>>> from fountain.parser import FountainParser >>> parser = FountainParser() >>> doc = parser.parse("Title: My Script\n\nFADE IN:") >>> renderer = FountainRenderer() >>> fountain = renderer.render(doc) >>> fountain.startswith("Title: My Script") True >>> "FADE IN:" in fountain True
The renderer module provides classes for converting documents to different output formats.