Skip to content

Commit 4327ea9

Browse files
wesortjacksleight
andauthored
Add docs example to wrap headings (#25)
Co-authored-by: Jack Sleight <[email protected]>
1 parent b3e426a commit 4327ea9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/examples.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,25 @@ Mutator::html('paragraph', function ($value, $data) {
129129
});
130130
```
131131

132+
### Wrap all heading text with permalink anchors and add a class
133+
134+
```php
135+
use JackSleight\StatamicBardMutator\Facades\Mutator;
136+
137+
Mutator::html('heading', function ($value, $data) {
138+
$slug = str_slug(collect($data->content)->implode('text', ''));
139+
$value[2] = ['a', [
140+
'id' => $slug,
141+
'href' => '#'.$slug,
142+
'class' => 'hover:underline',
143+
], 0];
144+
return $value;
145+
});
146+
```
147+
132148
## Data Mutators
133149

134-
### Add permalink anchors to all headings
150+
### Add permalink anchors before all heading text
135151

136152
```php
137153
use JackSleight\StatamicBardMutator\Facades\Mutator;

0 commit comments

Comments
 (0)