Fountain Library

repository·master·Indexed 20 days ago

https://github.com/nyousefi/fountain

An Objective-C library for parsing and writing Fountain-formatted screenplays. It features FNScript for script lifecycle management, FastFountainParser for high-performance line-by-line parsing, and FountainWriter for converting script data back to plain-text NSStrings.

Tokens
680
Snippets
1
Records
6
Agent score
21%

What's inside Fountain

  1. Integrate Fountain using FNScript

    master

    For most applications, FNScript is the recommended entry point for Fountain support. It manages the lifecycle of reading and writing Fountain files and maintains the script content in a generic data model.

    • Script Content: Represented as an NSArray of FNElements.
    • Title Page: Represented as an NSArray of NSDictionary items.

    FNScript uses FastFountainParser by default for high performance.

  2. Use FastFountainParser for high-performance parsing

    master

    FastFountainParser is a redesigned line-by-line parser that is approximately 10 times faster than the legacy FountainParser. It achieves this by having less reliance on regular expressions.

    It is the default parser used by FNScript. If you specifically need the older behavior, you can still access the legacy parser by using the FNParserTypeRegex option on the appropriate methods.

  3. Understand the Fountain data model and text styling

    master

    The Fountain data model (represented by FNElement) is designed to be generic.

    Important: Text Styling The parser and data model do not handle text styling (such as bold, italic, or underline). The parser retains the styling markup and passes it along. It is the responsibility of the downstream consumer (the UI or print engine) to handle the rendering and cleanup of styling markup.

    If you need to handle styling manually, the package includes FountainRegexes to assist with this.

  4. Install Fountain into your Xcode project

    master

    To integrate Fountain into your project, follow these steps:

    1. Copy all files located in the Fountain group into your Xcode project.
    2. Add the -licucore linker flag to your project to support RegexKitLite.

    Note on RegexKitLite: If you prefer not to use RegexKitLite, you must manually remove its references in FountainParser.m and FountainWriter.m. While the provided regular expressions are generally compatible with standard regex implementations, you may need to adjust them for a different library.

    # Add this linker flag to your project settings
    -licucore
  5. Reference: Fountain Components

    master

    The following components make up the Fountain library:

    • FNScript: High-level wrapper for reading/writing files and holding script content (FNElements and title page NSDictionarys).
    • FNElement: The core data model for individual script elements.
    • FastFountainParser: High-performance, line-by-line parser (default).
    • FountainWriter: Provides methods to convert FNScript to NSString.
    • FountainParser: Legacy parser providing class methods to read title pages and script bodies separately.
    • FountainRegexes: A collection of regular expressions used for parsing and text styling.