You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+43-13Lines changed: 43 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,31 +49,61 @@ and run `composer install` or `composer update` afterwards. If you're not using
49
49
50
50
## Usage
51
51
52
-
Create `Shortcode` class instance, register required shortcodes handlers and pass your strings to be parsed.
52
+
**Replacement**
53
+
54
+
Create `Processor` class instance, register required shortcodes handlers and use `process()` method to dynamically replace found matches using registered callbacks:
Create instance of class `Extractor` and use its `extract()` method to get array of shortcode matches:
76
+
77
+
```php
78
+
use Thunder\Shortcode\Extractor;
79
+
80
+
$extractor = new Extractor();
81
+
$matches = $extractor->extract('something [x] other [random]sth[/random] other');
82
+
83
+
// array will contain two instances of class Match with match offsets and exact
84
+
// strings, like [10, '[x]'] and [20, '[random]sth[/random]']
85
+
var_dump($matches);
86
+
```
87
+
88
+
**Parsing**
89
+
90
+
Create instance of `Parser` class and use its `parse()` method to parse single shortcode string match into `Shortcode` instance with easy access to its name, parameters, and content (null if none present):
// will contain name "code", one argument and "something" as content.
99
+
var_dump($shortcode);
70
100
```
71
101
72
-
Edge cases:
102
+
## Edge cases
73
103
74
104
* unsupported shortcodes (no registered handler) will be ignored and left as they are,
75
-
* mismatching closing shortcode (`[code]content[/codex]`) will be ignored, opening will be interpreted as self-closing shortcode,
76
-
* overlapping shortcodes (`[code]content[inner][/code]content[/inner]`) are not supported and will be interpreted as self-closing, ending fragment will be ignored.
105
+
* mismatching closing shortcode (`[code]content[/codex]`) will be ignored, opening tag will be interpreted as self-closing shortcode,
106
+
* overlapping shortcodes (`[code]content[inner][/code]content[/inner]`) are not supported and will be interpreted as self-closing, closing tag will be ignored.
0 commit comments