protected static function ListTagPlugin::splitContent in Extensible BBCode 8.3
Same name and namespace in other branches
- 4.0.x standard/src/Plugin/XBBCode/ListTagPlugin.php \Drupal\xbbcode_standard\Plugin\XBBCode\ListTagPlugin::splitContent()
Split the tag's children into list items.
Any instance of [*] in the top-level text will be used as a delimiter.
Parameters
\Drupal\xbbcode\Parser\Tree\ElementInterface[] $children: The tag's child elements in the parse tree.
Return value
\Drupal\xbbcode\Parser\Tree\NodeElementInterface[] A sequence of nodes, each containing a part of the parse tree.
1 call to ListTagPlugin::splitContent()
- ListTagPlugin::buildElement in standard/
src/ Plugin/ XBBCode/ ListTagPlugin.php - Build a render array from the tag.
File
- standard/
src/ Plugin/ XBBCode/ ListTagPlugin.php, line 139
Class
- ListTagPlugin
- Renders a list.
Namespace
Drupal\xbbcode_standard\Plugin\XBBCodeCode
protected static function splitContent(array $children) : array {
[
$token,
$text,
] = static::encodeTree($children);
// Trim, and strip linebreaks before newlines.
$trimmed = preg_replace('/<br\\s*\\/?>\\n/', "\n", $text);
$breaks = $trimmed !== $text;
$text = trim($trimmed);
// Split on [*] at the start of lines.
$items = preg_split('/^\\s*\\[\\*]\\s*/m', $text);
array_shift($items);
foreach ($items as $i => $item) {
$item = trim($item);
if ($breaks) {
$item = nl2br($item);
}
$items[$i] = static::decodeTree($item, $children, $token);
}
return $items;
}