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 />'
Requires
- php: >=8.2
- ext-ctype: *
- monolog/monolog: ^3.4
- psr/log: ^3.0
- symfony/event-dispatcher: ^6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.23
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-12-05 08:21:46 UTC
README
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.