mindkomm / commonmark-searchhighlight-extension
Extension for CommonMark PHP implementation to highlight search strings in Markdown files
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 0
Open Issues: 0
pkg:composer/mindkomm/commonmark-searchhighlight-extension
Requires
- php: ^5.5|^7.0
- league/commonmark: ^1.0
This package is auto-updated.
Last update: 2025-09-22 11:44:48 UTC
README
SearchHighlight is an extension for the CommonMark PHP implementation and can be used to highlight Markdown text that matches a search string.
The extension adds a <span class="search-highlight">
around the strings that match the search string.
Example for "something":
Installation
This project can be installed via Composer:
composer require mindkomm/commonmark-searchhighlight-extension
Usage
use League\CommonMark\Environment; use League\CommonMark\CommonMarkConverter; use Mind\CommonMark\SearchHighlightExtension\SearchHighlightExtension; $searchstring = 'Your search string'; $config = []; $environment = Environment::createCommonMarkEnvironment(); if (!empty($searchstring)) { // Pass the search string to the constructor. $environment->addExtension(new SearchHighlightExtension($searchstring)); } $converter = new CommonMarkConverter($config, $environment); echo $converter->convertToHtml('A text that contains your search string.');