public function ReadmehelpMarkdown::convertLeadingNumberDotSpace in README Help 8
Wraps leading "NUMBER. " text lines into ordered list tag.
Parameters
string $text: The string to be filtered.
Return value
string The HTML source with ordered lists.
1 call to ReadmehelpMarkdown::convertLeadingNumberDotSpace()
- ReadmehelpMarkdown::process in src/
Plugin/ Filter/ ReadmehelpMarkdown.php - Performs the filter processing.
File
- src/
Plugin/ Filter/ ReadmehelpMarkdown.php, line 253
Class
- ReadmehelpMarkdown
- Provides a filter for markdown.
Namespace
Drupal\readmehelp\Plugin\FilterCode
public function convertLeadingNumberDotSpace($text) {
return preg_replace_callback('/(?(DEFINE)(?<emptyline>(\\n\\n)))(\\n\\d\\.\\ )(.*?)(?&emptyline)/s', function ($matches) {
$match = '';
if ($match = !empty($matches[0]) ? $matches[0] : '') {
$match = preg_replace('/(^|\\n)\\d\\.\\ /s', '<LISTITEM>', $match);
$items = '';
foreach (explode('<LISTITEM>', $match) as $item) {
if ($item = trim($item)) {
$items .= "<li>{$item}</li>";
}
}
$match = $items ? "\n<ol class=\"ol\">{$items}</ol>\n" : $match;
}
return $match;
}, $text);
}