Contents

qiyangdev/swiftfountain

SwiftFountain is a modern Swift library for parsing [Fountain](https://fountain.io/syntax/) screenplay text and producing data structures that are directly usable for syntax highlighting in SwiftUI.

Features

  • Parse Fountain source into line-level semantic kinds (sceneHeading, dialogue, transition, etc.)
  • Emit UTF-16 based source ranges for each line and highlight span
  • Extract title-page metadata and note payloads
  • Detect note ([[...]]) and boneyard (/.../) regions for editor highlighting
  • Provide an optional SwiftUI 26+ demo view for attributed-text editing

Installation (SwiftPM)

Add the package dependency in Xcode or in Package.swift:

dependencies: [
    .package(url: "https://github.com/wangqiyangX/SwiftFountain.git", from: "0.1.0")
]

Quick Start

import SwiftFountain

let parser = FountainParser()
let document = parser.parse("""
INT. OFFICE - DAY

ALICE
Hello.
""")

for line in document.lines {
    print(line.lineNumber, line.kind, line.range)
}

for highlight in document.highlights {
    print(highlight.kind, highlight.range)
}

Public API

Core parser model:

  • FountainParser
  • FountainDocument
  • FountainLine, FountainLineKind
  • FountainHighlight, FountainHighlightKind
  • SourceRange
  • TitlePageEntry

SwiftUI demo components (26+):

  • FountainHighlightDemoView
  • FountainHighlightTheme

SwiftUI Demo View

FountainHighlightDemoView uses TextEditor with AttributedString and is gated to:

  • iOS 26+
  • macOS 26+
  • tvOS 26+
  • watchOS 26+

The parser itself is platform-agnostic and available wherever Foundation is available.

Development

Run tests:

swift test

License

MIT. See LICENSE.

Package Metadata

Repository: qiyangdev/swiftfountain

Default branch: main

README: README.md