Flarum 自定义 bbcode 以支持 asciinema
安装依赖
composer require s9e/text-formatter
配置 extend.php
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Extend;
use Flarum\Frontend\Document;
use s9e\TextFormatter\Configurator;
$asciinema = (new Extend\Formatter)
->configure(function (Configurator $configurator) {
$bbcode = $configurator->BBCodes->add('recode');
$tag = $configurator->tags->add('recode');
$tag->template = '<script src="https://record.example.com/a/{@id}.js" ' .
'id="asciicast-{@id}" ' .
'data-autoplay="{@auto}" ' .
'data-start-at="{@start}" ' .
'data-speed="{@speed}" ' .
'data-idle-time-limit="{@idle}" ' .
'data-poster="{@poster}" ' .
'async="true"></script>';
$attribute = $tag->attributes->add('id');
$attribute->filterChain->append('#alnum');
$attribute->required = true;
$attribute = $tag->attributes->add('auto');
$attribute->filterChain->append('#choice')->setValues([0, 1]);
$attribute->defaultValue = 1;
$attribute = $tag->attributes->add('start');
$attribute->filterChain->append('#uint');
$attribute->defaultValue = 0;
$attribute = $tag->attributes->add('speed');
$attribute->filterChain->append('#uint');
$attribute->defaultValue = 2;
$attribute = $tag->attributes->add('idle');
$attribute->filterChain->append('#choice')->setValues([0, 1]);
$attribute->defaultValue = 1;
$attribute = $tag->attributes->add('poster');
$attribute->defaultValue = '';
});
return [
$asciinema,
];
使用
[recode id=1][/recode]
相关教程:https://s9etextformatter.readthedocs.io/