Parsing Fountain files - lmparppei/BeatPlugins GitHub Wiki
Most plugin API methods are wrappers for the parser associated with current document. However, you can access the actual parser, too, and create new parser instances when needed.
Parser of the host document can be accessed through Beat.currentParser
:
let parser = Beat.currentParser
for (let line of parser.lines) {
//...
}
You can also create a new, static parser to parse external Fountain files, and access its line and scene objects.
let parser = Beat.parser(stringToParse)
for (let line of parser.lines) {
// ...
}
Parser methods
There are some property/method inconsistencies between the "overlaid" Beat parser API and the core parser object. Most notably, .lines
, .outline
and .scenes
are properties and not functions. Most property/method names are still identical.
parser.lines
— line objects (note: property, not a method)
parser.outline
— all scene objects, including synopsis lines and sections (note: property, not a method)
parser.scenes
— scene objects only (note: property, not a method)
parser.titlePage
— title page elements
parser.linesInRange({ location: x, length: y })
— get all lines in the selected range (note: parameter has to be a range object)
parser.lineAtPosition(index)
— get line item at given character index
parser.sceneAtPosition(index)
— get outline item at given character index