CommonMark
If your app renders Markdown (a blog, a wiki, a CMS), this extension lets content authors embed icons directly in their writing. No PHP, no template tags, just a short inline syntax.
This is a separate package:
composer require frostybee/swarm-icons-commonmarkWire it up
Section titled “Wire it up”Register the extension with your League CommonMark environment. Pass the same IconManager you use everywhere else:
use Frostybee\SwarmIcons\CommonMark\IconExtension;use League\CommonMark\Environment\Environment;use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;use League\CommonMark\MarkdownConverter;
$environment = new Environment();$environment->addExtension(new CommonMarkCoreExtension());$environment->addExtension(new IconExtension($manager));
$converter = new MarkdownConverter($environment);The syntax
Section titled “The syntax”Embed an icon inline with :icon[prefix:name]:
Click :icon[heroicons:home] to go home.That renders the heroicons:home icon right inside the paragraph text.
Adding attributes
Section titled “Adding attributes”Pass attributes as space-separated key="value" pairs after the icon name:
:icon[heroicons:user class="w-6 h-6"] Profile:icon[tabler:star fill="currentColor"] FavoriteAccessible icons
Section titled “Accessible icons”Add aria-label to make an icon meaningful to screen readers:
:icon[heroicons:home aria-label="Home"] HomeIcons go through the same rendering pipeline as swarm_icon(): global defaults, prefix defaults, suffix attributes, and ARIA rules all apply.
A real-world example
Section titled “A real-world example”This is where the syntax really shines for documentation or help content where authors write Markdown and shouldn’t need to touch PHP:
## Getting Started
1. Click :icon[heroicons:plus-circle] **New Project** to create a project2. Use :icon[heroicons:cog-6-tooth] **Settings** to configure options3. Click :icon[heroicons:check-circle] **Save** when doneThe icons render inline, right alongside the text. Authors can reference any icon set you’ve configured: they just need to know the prefix:name.
See also
Section titled “See also”- Fluent API: the
Iconvalue object and its methods - Accessibility: decorative vs meaningful icons and ARIA attributes