This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/_sakura/components/BBcodeDefinitions/Lists.php

48 lines
1,010 B
PHP
Raw Normal View History

<?php
/*
* List BBcode
* https://gist.github.com/jbowens/5646994
*/
namespace Sakura\BBcodeDefinitions;
use JBBCode\Parser;
use JBBCode\CodeDefinition;
use JBBCode\ElementNode;
/**
* Implements a [list] code definition that provides the following syntax:
*
* [list]
* [*] first item
* [*] second item
* [*] third item
* [/list]
*
*/
class Lists extends CodeDefinition
{
public function __construct()
{
$this->parseContent = true;
$this->useOption = false;
$this->setTagName('list');
$this->nestLimit = -1;
}
public function asHtml(ElementNode $el)
{
$bodyHtml = '';
foreach ($el->getChildren() as $child) {
$bodyHtml .= $child->getAsHTML();
}
$listPieces = explode('[*]', $bodyHtml);
unset($listPieces[0]);
$listPieces = array_map(function($li) {
return '<li>'.$li.'</li>';
}, $listPieces);
return '<ul>'.implode('', $listPieces).'</ul>';
}
}