Skip to content

Commit 55f892a

Browse files
author
Genert Org
committed
New feature and tests
1 parent 5810a34 commit 55f892a

File tree

6 files changed

+172
-110
lines changed

6 files changed

+172
-110
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,27 @@ $bbCode->except('bold')->convertToHtml('[b]Bold[/b] [i]italic[/i]');
9898
$bbCode->except(['bold'])->convertToHtml('[b]Bold[/b] [i]italic[/i]');
9999
```
100100

101+
### `addParser(string $name, string $pattern, string $replace)`
102+
Add regex based BBCode parser to translate found pattern to desired one.
103+
104+
Example:
105+
```php
106+
use Genert\BBCode\BBCode;
107+
108+
$bbCode = new BBCode();
109+
110+
// Add "[link target=http://example.com]Example[/link]" parser.
111+
$bbCode->addParser(
112+
'custom-link',
113+
'/\[link target\=(.*?)\](.*?)\[\/link\]/s',
114+
'<a href="$1">$2</a>'
115+
);
116+
117+
// Output: '<a href="www.yourlinkhere.com">Text to be displayed</a>.'
118+
$bbCode->convertToHtml('[link target=www.yourlinkhere.com]Text to be displayed[/link].');
119+
```
120+
121+
101122
## Laravel installation
102123

103124
Once BBCode is installed, you need to register the service provider. Open up `config/app.php` and add the following to the `providers` key.

0 commit comments

Comments
 (0)