Skip to content

Extension for CommonMark PHP implementation to higlight search strings in Markdown files.

License

Notifications You must be signed in to change notification settings

mindkomm/commonmark-searchhighlight-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SearchHighlight Extension

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.');

About

Extension for CommonMark PHP implementation to higlight search strings in Markdown files.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages