stovak / fountain

使用php 8.2,类型安全,单元测试和渲染事件重写了Tao的PHP解析器。该库使用样式伪元素渲染,例如 '<screenplay />'。

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

This package is auto-updated.

Last update: 2024-09-05 07:53:21 UTC


README

Fountain CI

Fountain是一种简单的标记语法,允许将剧本以纯文本形式编写、编辑和共享。Fountain允许您在任何电脑上使用任何编辑文本文件的软件处理剧本。

有关Fountain的更多详细信息,请参阅http://fountain.io

入门指南

直接将剧本文本解析成HTML的简单版本

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

更详细的版本是,Fountain首先创建一系列元素,您可以用它们进行其他目的。一旦Fountain元素被解析,FountainTags类将确定正确的HTML标签进行打印。

    $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);

监听渲染事件

可以监听渲染事件。如果您想在HTML返回之前对其进行处理,这很有用。

$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;

提及

代码基于以下贡献者的前期工作构建。