我正在尝试将快捷代码添加到所见即所得中。我在用这个图书馆。我正试图将其解析为引导程序中的手风琴:
[panel]
[header]
Heading goes here
[/header]
[content] Content goes here [/content]
[header]
Heading goes here
[/header]
[content] Content goes here [/content]
[/panel]
我的代码看起来像:
use Thunder'Shortcode'HandlerContainer'HandlerContainer;
use Thunder'Shortcode'Parser'RegularParser;
use Thunder'Shortcode'Processor'Processor;
use Thunder'Shortcode'Shortcode'ShortcodeInterface;
function processAgendaContent($content)
{
$handlers = new HandlerContainer();
$handlers->add('panel', function(ShortcodeInterface $s) {
return "<div class='"panel panel-default'">";
});
$handlers->add('header', function(ShortcodeInterface $s) {
return '
<h4 class="panel-title">
<a href="#collapse1" target="_blank" role="button" data-toggle="collapse" aria-expanded="true" aria-controls="collapse1" class="btn-collapse">
' . $s->getContent() . '</a>
</h4>';
});
$processor = new Processor(new RegularParser(), $handlers);
echo $processor->process($content);
我现在的问题是,当我试图解析时,它解析的是开始标记,而不是结束标记,因此我认为getContent()不起作用。知道我做错了什么吗?感谢
我是Shortcode库的作者。要解决您的问题,请将panel
短代码处理程序主体更改为:
return '<div class="panel panel-default">'.$s->getContent().'</div>';
每个短代码处理程序都控制从整个短代码文本返回的内容。您只是返回了一个简单的字符串,并且没有在任何地方包含其内容,这就是为什么[panel]
封装的整个文本被丢弃的原因。
我希望这有助于更好地了解这个图书馆是如何运作的,如果你有更多的问题,我很乐意在这里回答。