All Projects → spatie → Commonmark Highlighter

spatie / Commonmark Highlighter

Licence: mit
Highlight code blocks with league/commonmark

Projects that are alternatives of or similar to Commonmark Highlighter

Qlcommonmark
QuickLook generator for beautifully rendering CommonMark documents on macOS
Stars: ✭ 36 (-66.04%)
Mutual labels:  commonmark
Markra
A Markdown-to-JIRA syntax editor.
Stars: ✭ 64 (-39.62%)
Mutual labels:  commonmark
Marko
A markdown parser with high extensibility.
Stars: ✭ 77 (-27.36%)
Mutual labels:  commonmark
React Marker
🖍️ Highlight keywords and add colors to your text.
Stars: ✭ 45 (-57.55%)
Mutual labels:  highlight
Elm Syntax Highlight
Syntax highlighting in Elm
Stars: ✭ 61 (-42.45%)
Mutual labels:  highlight
Multihighlight
Jetbrains IDE plugin: highlight identifiers with custom colors 🖌💡
Stars: ✭ 65 (-38.68%)
Mutual labels:  highlight
Ember Highlight
Highlight a given term(s) inside the `{{highlight-terms}}` component block.
Stars: ✭ 10 (-90.57%)
Mutual labels:  highlight
Guideview
简单易用的高亮引导工具,可高度自定义。
Stars: ✭ 94 (-11.32%)
Mutual labels:  highlight
Highlightr
iOS & OSX Syntax Highlighter.
Stars: ✭ 1,116 (+952.83%)
Mutual labels:  highlight
Colorhighlight
🎨 Lightweight Color Highlight colorizer for Sublime Text
Stars: ✭ 76 (-28.3%)
Mutual labels:  highlight
Nord Highlightjs
An arctic, north-bluish clean and elegant highlight.js theme.
Stars: ✭ 49 (-53.77%)
Mutual labels:  highlight
Swiftmarkup
Parses Swift documentation comments into structured entities
Stars: ✭ 55 (-48.11%)
Mutual labels:  commonmark
Vscode Highlight
Advanced text highlighter based on regexes. Useful for todos, annotations etc.
Stars: ✭ 71 (-33.02%)
Mutual labels:  highlight
Remark Boilerplate
A boilerplate to create presentations using remark, Gulp, Stylus and more.
Stars: ✭ 41 (-61.32%)
Mutual labels:  highlight
Alfred Hl
🔆 Syntax highlight code in the clipboard
Stars: ✭ 80 (-24.53%)
Mutual labels:  highlight
Theme Bear
🐻 A VSCode dark theme 🐻
Stars: ✭ 27 (-74.53%)
Mutual labels:  highlight
Highlight.lua
a neovim syntax highlighter using treesitter
Stars: ✭ 65 (-38.68%)
Mutual labels:  highlight
Elm Markdown
Pure Elm markdown parsing and rendering
Stars: ✭ 96 (-9.43%)
Mutual labels:  commonmark
Html To Markdown
Convert HTML to Markdown with PHP
Stars: ✭ 1,293 (+1119.81%)
Mutual labels:  commonmark
Markd
Yet another markdown parser, Compliant to CommonMark specification, written in Crystal.
Stars: ✭ 73 (-31.13%)
Mutual labels:  commonmark

Highlight your markdown code blocks with league/commonmark

Latest Version Build Status Quality Score StyleCI Total Downloads

A block renderer for league/commonmark to highlight code blocks using scrivo/highlight.php.

highlight.php is a server side code highlighter written in PHP that currently supports 185 languages. It's a port of highlight.js by Ivan Sagalaev that makes full use of the language and style definitions of the original JavaScript project.

The output html is compatible with highlight.js themes, which you can explore on highlightjs.org.

What are the benefits of using this package over highlight.js?

  • Less JavaScript, which means faster page loads
  • No more flash of unstyled code blocks

This project was inspired by sixlive/parsedown-highlight.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/commonmark-highlighter

Usage

Create a custom CommonMark environment, and register the FencedCodeRenderer and IndentedCodeRender as described in the league/commonmark documentation.

use League\CommonMark\Block\Element\FencedCode;
use League\CommonMark\Block\Element\IndentedCode;
use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Environment;
use Spatie\CommonMarkHighlighter\FencedCodeRenderer;
use Spatie\CommonMarkHighlighter\IndentedCodeRenderer;

$environment = Environment::createCommonMarkEnvironment();
$environment->addBlockRenderer(FencedCode::class, new FencedCodeRenderer());
$environment->addBlockRenderer(IndentedCode::class, new IndentedCodeRenderer());

$commonMarkConverter = new CommonMarkConverter([], $environment);

echo $commonMarkConverter->convertToHtml($markdown);

The underlying highlight library recommends specifying a subset of languages for the auto-detection. You can pass an array of languages to any of the renderers.

new FencedCodeRenderer(['html', 'php', 'js']);

new IndentedCodeCodeRenderer(['html', 'php', 'js']);

Highlighting specific lines

Line numbers start at 1.

```php - Don't highlight any lines
```php{4} - Highlight just line 4
```php{4-6} - Highlight the range of lines from 4 to 6 (inclusive)
```php{1,5} - Highlight just lines 1 and 5 on their own
```php{1-3,5} - Highlight 1 through 3 and then 5 on its own
```php{5,7,2-3} - The order of lines don't matter
However, specifying 3-2 will not work.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].