Skip to content

Commit 2ac6e36

Browse files
committed
Update docs
1 parent ce52b14 commit 2ac6e36

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

docs/examples.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ Mutator::data('blockquote', function ($data) {
191191
});
192192
```
193193

194+
### Add SVG icons to links
195+
196+
```php
197+
use JackSleight\StatamicBardMutator\Facades\Mutator;
198+
use JackSleight\StatamicBardMutator\Support\Data;
199+
200+
Mutator::data('link', function ($info) {
201+
$node = $info->parent->item;
202+
Data::morph($node, Data::html('<svg></svg> '.e($node->text), $node->marks));
203+
});
204+
```
205+
194206
Check out the modifier [example below](examples#using-with-the-bard-modifiers) to see how you could use these in a table of contents.
195207

196208
## Using with the Bard modifiers

tests/DataPluginTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,22 @@
5757
]]);
5858
expect($this->renderTestValue($value))->toEqual('<figure class="quote"><blockquote><p>Lorem ipsum dolor sit amet</p></blockquote><figcaption><p>— Publius Vergilius Maro</p></figcaption></figure>');
5959
});
60+
61+
it('adds svgs to links', function () {
62+
Mutator::data('link', function ($info) {
63+
$node = $info->parent->item;
64+
Data::morph($node, Data::html('<svg></svg> '.e($node->text), $node->marks));
65+
});
66+
$value = $this->getTestValue([[
67+
'type' => 'paragraph',
68+
'content' => [[
69+
'type' => 'text',
70+
'text' => 'Link',
71+
'marks' => [
72+
['type' => 'link', 'attrs' => ['href' => 'https://example.com']],
73+
['type' => 'bold'],
74+
],
75+
]],
76+
]]);
77+
expect($this->renderTestValue($value))->toEqual('<p><a href="https://example.com"><strong><svg></svg> Link</strong></a></p>');
78+
});

0 commit comments

Comments
 (0)