stovak/fountain

A rewrite of Tao's PHP Parser for Fountain using php 8.2, type safety, unit testing and rendering events. The library renders using styled pseudo elements, e.g. '<screenplay />'

v2.0.1 2023-09-05 05:34 UTC

This package is auto-updated.

Last update: 2024-04-05 07:02:19 UTC


README

Fountain CI

Fountain is a simple markup syntax that allows screenplays to be written, edited, and shared in plain, human-readable text. Fountain allows you to work on your screenplay anywhere, on any computer, using any software that edits text files.

For more details on Fountain see http://fountain.io.

Getting started

The simple version for parsing a screenplay text straight into HTML:

    $input = "My fountain input text.";
    $screenplay = new \Fountain\Screenplay();
    $html = $screenplay->parse($input);

The longer version is that Fountain first creates a collection of Elements, which you may use for other purposes. Once the Fountain Elements have been parsed, the FountainTags class determines the correct HTML tags to print.

    $input = "My fountain input text.";
    // determine fountain elements
    $fountainElements = (new \Fountain\FountainParser())->parse($input);
    // parse fountain elements into html
    $html = (new \Fountain\FountainTags())->parse($fountainElements);

Listening for render events

It is possible to listen for render events. This is useful if you want to do something with the HTML before it is returned.

$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addListener('fountain.render', function (\Fountain\Event\RenderEvent $event) {
    $event->setHtml(str_replace('horse', 'cat', $event->getHtml()));
});
// Create a new screenplay programmatically...
$it = new \Fountain\Screenplay($eventDispatcher);
$it->elements()->addElement(new NewLine());
$it->elements()->addElement($headExpected);
$it->elements()->addElement(new Action());
$it->elements()->last()->setText("John goes to see a man about a horse.");
$it->elements()->addElement(new Character());
$it->elements()->last()->setText("JOHN");
$it->elements()->addElement(new Parenthetical());
$it->elements()->last()->setText("(to himself)");
$it->elements()->addElement(new Dialogue());
$it->elements()->last()->setText("I wonder if he has any horses for sale.");
// Print that screenplay...
echo (string)$it;

Mentions

The code has been built upon the previous work of these contributors.