Add new Strings::performWithEscapedBlocks methods

- Add new BBCode::performWithEscapedTags method
- Add tests
This commit is contained in:
Hypolite Petovan 2020-06-04 19:25:48 -04:00
parent 6665eb76f9
commit 348b71d0b0
3 changed files with 92 additions and 0 deletions

View file

@ -2163,4 +2163,22 @@ class BBCode
return $ret;
}
/**
* Perform a custom function on a text after having escaped blocks enclosed in the provided tag list.
*
* @param string $text
* @param array $tagList A list of tag names, e.g ['noparse', 'nobb', 'pre']
* @param callable $callback
* @return string
* @throws Exception
*@see Strings::performWithEscapedBlocks
*
*/
public static function performWithEscapedTags(string $text, array $tagList, callable $callback)
{
$tagList = array_map('preg_quote', $tagList);
return Strings::performWithEscapedBlocks($text, '#\[(?:' . implode('|', $tagList) . ').*?\[/(?:' . implode('|', $tagList) . ')]#ism', $callback);
}
}