fountain

package module
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 12 Imported by: 7 modules, 7 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fountain

fountain is a Go package and three small command line programs for working with Fountain formatted screenplays, the plain text format many screenwriting programs read and write. The package parses a document into title page and script elements, pretty prints it, and renders it as HTML, JSON or YAML.

The package

doc, err := fountain.Parse(src)            // or fountain.ParseFile("script.fountain")
for _, e := range doc.Elements {
    switch e.Type {
    case fountain.SceneHeadingType:
        fmt.Println(e.SceneNumber, e.Content) // 12A INT. KITCHEN - DAY #12A#
    case fountain.BoneyardType:
        fmt.Println(fountain.BoneyardText(e.Content))
    }
}
fmt.Println(doc.String())                  // pretty printed Fountain
fmt.Println(doc.ToHTML())                  // HTML
data, _ := doc.ToJSON()                    // or doc.ToYAML()

A Fountain has a TitlePage and Elements; each Element has a Type (SceneHeadingType, ActionType, CharacterType, DialogueType, ParentheticalType, TransitionType, NoteType, BoneyardType, SectionType, SynopsisType and the rest), a Name, its Content, and, on a scene heading, the SceneNumber.

  • Scene numbers. A heading that ends in a number written between hashes, INT. KITCHEN - DAY #12A#, has SceneNumber "12A". Content keeps the heading as written.
  • Boneyards. Cut material between /* and */, on one line or across several, is one BoneyardType element. BoneyardText returns the text between the delimiters.
  • Output options. The package variables MaxWidth, AsHTMLPage, InlineCSS, LinkCSS, CSS, ShowSection, ShowSynopsis and ShowNotes control String and ToHTML.

The runnable example in example_test.go is the one above in miniature, and is checked by go test.

The programs

fountain2json : a Fountain to JSON converter, useful for building reports. The JSON has the element fields above, scene_number included.

fountainfmt : a Fountain pretty printer

fountain2html : a Fountain to HTML converter

Install

Get a release from GitHub, or see INSTALL.md, which also covers installing from source. To use the package in a Go program:

go get github.com/rsdoiel/fountain

Build and test

You need Go 1.27.4 or later. Pandoc and GNU Make are only needed for the man pages and the website, and cmt (CMTools) only to regenerate version.go, about.md and CITATION.cff from codemeta.json.

make          # build the programs into bin/ and the man pages into man/
make test     # go test ./...
make check    # gofmt -l and go vet; rewrites nothing

get-optional-testdata.bash downloads the larger sample screenplays from fountain.io into testdata/; see testdata.md. make generate runs cmt; make release builds the distribution zips from a committed, pushed tree (it does not run generate), and release.bash then drafts the GitHub release.

Release notes

1.0.3. Boneyards are parsed as BoneyardType elements. A one-line boneyard used to read as Action, and the lines of a multi-line one as Character, Dialogue and Action. Scene headings carry their number in Element.SceneNumber, the JSON output has scene_number, and BoneyardText is new. Go 1.26.4 or later is required. These were added for the knowledge module, which reads Fountain scenes and keeps story metadata in one-line boneyards.

Known limitations

The parser is line based. The open items are in TODO.md: a character line such as DOG in sample-05 is read as dialogue, and parentheticals scattered through dialogue in sample-07 can turn dialogue into Action. A boneyard is written into HTML output as a boneyard element rather than hidden.

  • fdx, osf and scripttool convert between Fountain, Final Draft, Open Screenplay Format and FadeIn.
  • knowledge ingests Fountain files as documents, one section per scene.

Reference materials

fountain is licensed under the GNU Affero General Public License, version 3 or (at your option) any later version; see LICENSE.

Documentation

Overview

Package fountain is a Golang package supporting Fountain screenplay markup.

css.go manages setting up CSS for either inline style elements or links.

Package fountain supports encoding/decoding fountain formatted screenplays.

@author R. S. Doiel, <rsdoiel@gmail.com>

Copyright (C) 2017-2026 R. S. Doiel

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Package fountain support encoding/decoding fountain screenplay markup

scrippets.go manages fetching and inlining or generating links to John August's scrippets.css

Index

Examples

Constants

View Source
const (

	// GeneralTextType - not specific formatting, treat as plain text
	GeneralTextType = iota
	// EmptyType An empty line(s), block of whitepace, can occur on title page or script page(s)
	EmptyType
	// TitlePageType - something that only happens on the title page.
	// NOTE: Title page elents have a .Name value which is my best guess about the content.
	TitlePageType
	// SceneHeadingType - exists in the script pages, it is for scene headings
	SceneHeadingType
	// ActionType - designates an action block in the script page(s)
	ActionType
	// CharacterType - designates a CHARACTER heading for dialog
	CharacterType
	// DialogueType - holds a block of dialogue
	DialogueType
	// ParentheticalType - holds any parenthetical statement after CharacterType and before DialogueType
	ParentheticalType
	// TransitionType - scene transition instructions, these are minimal in most scripts now, e.g. FADE IN:, FADE TO BLACK:, THE END.
	TransitionType
	// ShotType - Goes in the screen heading line
	ShotType
	// LyricType - holds lyrics to be sung
	LyricType
	// NoteType - holds a script note
	NoteType
	// BoneyardType - blocks of cut material that haven't been removed
	BoneyardType
	// SectionType - is a markdown like title/heading, not normally display in output but used for navigation in text
	SectionType
	// SynopsisType - used as internal documentation, not normally displayed in output
	SynopsisType

	// UnderlineStyle - show underlined, in CSS "text-decoration:underline;"
	UnderlineStyle
	// ItalicStyle - show as italics (e.g. <i>, <em> in HTML)
	ItalicStyle
	// BoldStyle - show as boldface or strong (e.g. <b>, <strong> in HTML)
	BoldStyle
	// AllCapsStyle - will transform the text to uppercase, could also trigger CSS "text-transform: uppercase;"
	AllCapsStyle
	// Strikethrough - generates strikethrough in CSS
	Strikethrough

	// CenterAlignment - center text or block
	CenterAlignment
	// LeftAlignment - left align text or block
	LeftAlignment
	// RightAlignment - right align text of block
	RightAlignment

	// PageFeed - inject a page feed or <hr> in HTML
	PageFeed
)
View Source
const (
	// Version number of release
	Version = "1.0.5"

	// ReleaseDate, the date version.go was generated
	ReleaseDate = "2026-11-28"

	// ReleaseHash, the Git hash when version.go was generated
	ReleaseHash = "cc3550b"
	LicenseText = `` /* 34526-byte string literal not displayed */

)

Variables

View Source
var (

	// MaxWidth used to set width for Fountain text output in String()
	MaxWidth = 64
	// AsHTMLPage if true generate the HTML header and footer blocks
	AsHTMLPage = false
	// InlineCSS sets behavior of including style elements with CSS in ToHTML()
	InlineCSS = false
	// LinkCSS sets behavior of including link element pointing to CSS file in ToHTML()
	LinkCSS = false
	// CSS holds the filename to use generating CSS links or reading
	// in a customized version of the CSS. Defaults to "fountain.css".
	CSS = "fountain.css"
	// ShowSection - preserve section markers in output (e.g. when pretty printing a working draft)
	ShowSection = false
	// ShowSynopsis - preserve synopsis in output (e.g. when pretty printing a working draft)
	ShowSynopsis = false
	// ShowNotes - preserve notes in output (e.g. when pretty printing a working draft)
	ShowNotes = false

	// Pretty Print - will pretty print for output (e.g. when turning into
	// JSON, use MarshalIndent)
	PrettyPrint = false
)
View Source
var (
	// SourceCSS is a default CSS to use when rendering
	SourceCSS = `` /* 3262-byte string literal not displayed */

)

Functions

func BoneyardText added in v1.0.3

func BoneyardText(content string) string

BoneyardText returns the text inside a boneyard element's content, without the /* and */ delimiters and trimmed. Content that is not a boneyard is returned unchanged.

fountain.BoneyardText("/* story: pov=Anna */") // "story: pov=Anna"

func CharacterName added in v0.0.6

func CharacterName(element *Element) string

CharacterName takes an element of type Character and trims spaces, removes parenthetical (e.g. `(O.S.)`) and returns a string of the character name(s). NOTE: characters in the form of "JANE AND JOE" will be returned as "JANE AND JOE".

func FmtHelp added in v1.0.1

func FmtHelp(src string, appName string, version string, releaseDate string, releaseHash string) string

FmtHelp lets you process a text block with simple curly brace markup.

func Run added in v0.0.2

func Run(input []byte) ([]byte, error)

Run takes a byte split and returns an HTML fragment appropriate to use as a Scrippet with John Augusts' CSS https://fountain.io/_css/scrippets.css

Types

type Element

type Element struct {
	Type    int    `json:"type" yaml:"type"`
	Name    string `json:"name,omitempty" yaml:"name,omitempty"`
	Content string `json:"content" yaml:"content"`
	// SceneNumber is the number written at the end of a scene heading
	// ("INT. KITCHEN - DAY #12A#" has "12A"), empty for any other element
	// and for a heading with no number. Content keeps the heading as
	// written, number included.
	SceneNumber string `json:"scene_number,omitempty" yaml:"scene_number,omitempty"`
}

Element holds the parsed token in either the title page of the document or scene list parts.

func (*Element) String

func (element *Element) String() string

String() considers elem.Type and formatting output as string

func (*Element) ToHTML added in v0.0.2

func (element *Element) ToHTML() string

ToHTML considers elem.Type and formatting output

func (*Element) TypeName

func (element *Element) TypeName() string

TypeName returns the string describing the type of Fountain Element.

type Fountain

type Fountain struct {
	TitlePage []*Element
	Elements  []*Element
}

Fountain is the document container. It is the type returned by Parse() and ParseFile()

screenplay, _ := ParseFile("screenplay.fountain")
fmt.Println(screenplay.String())

func Parse

func Parse(src []byte) (*Fountain, error)

Parse takes []byte and returns a Fountain struct and error

Example

Parse reads a Fountain document. A scene heading carries its scene number and a boneyard is its own element.

package main

import (
	"fmt"

	"github.com/rsdoiel/fountain"
)

func main() {
	src := []byte("Title: The Long Fire\n\nINT. KITCHEN - DAY #12A#\n\n/* cut: Anna waits */\n\nAnna enters.\n")
	doc, err := fountain.Parse(src)
	if err != nil {
		panic(err)
	}
	for _, e := range doc.Elements {
		switch e.Type {
		case fountain.SceneHeadingType:
			fmt.Printf("scene %s: %s\n", e.SceneNumber, e.Content)
		case fountain.BoneyardType:
			fmt.Printf("boneyard: %s\n", fountain.BoneyardText(e.Content))
		case fountain.ActionType:
			fmt.Printf("action: %s\n", e.Content)
		}
	}
}
Output:
scene 12A: INT. KITCHEN - DAY #12A#
boneyard: cut: Anna waits
action: Anna enters.

func ParseFile

func ParseFile(fname string) (*Fountain, error)

ParseFile takes a filename and returns a Fountain struct and error

func (*Fountain) String

func (doc *Fountain) String() string

String return a Fountain formatted document as a string

func (*Fountain) ToHTML added in v0.0.2

func (doc *Fountain) ToHTML() string

ToHTML converts a Fountain document based on the Options prvided. @param opt *Options a populate struct of options this package supports @return string of HTML

func (*Fountain) ToJSON added in v0.0.3

func (doc *Fountain) ToJSON() ([]byte, error)

ToJSON renders a Fountain type documents into a JSON serialized data structure.

func (*Fountain) ToYAML added in v1.0.1

func (doc *Fountain) ToYAML() ([]byte, error)

ToYAML renders a Fountain type document into a YAML serialized data structure.

Directories

Path Synopsis
cmd
fountain2html command
fountain2html is part of fountain, a Go package for Fountain screenplays.
fountain2html is part of fountain, a Go package for Fountain screenplays.
fountain2json command
fountain2json is part of fountain, a Go package for Fountain screenplays.
fountain2json is part of fountain, a Go package for Fountain screenplays.
fountainfmt command
fountainfmt is part of fountain, a Go package for Fountain screenplays.
fountainfmt is part of fountain, a Go package for Fountain screenplays.
internal
cli
Package cli holds the command line behavior of fountain2html, fountain2json and fountainfmt so that plain go test covers it.
Package cli holds the command line behavior of fountain2html, fountain2json and fountainfmt so that plain go test covers it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址