mirror of
https://github.com/friendica/friendica
synced 2025-04-25 14:30:10 +00:00
Add new Strings::performWithEscapedBlocks methods
- Add new BBCode::performWithEscapedTags method - Add tests
This commit is contained in:
parent
6665eb76f9
commit
348b71d0b0
3 changed files with 92 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue