PHPackages                             spatie/sidecar-shiki - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/sidecar-shiki

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/sidecar-shiki
====================

Run Shiki highlighting with Sidecar

1.3.0(1y ago)3610.2k1[1 PRs](https://github.com/spatie/sidecar-shiki/pulls)MITPHPPHP ^8.1CI passing

Since Jun 24Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/spatie/sidecar-shiki)[ Packagist](https://packagist.org/packages/spatie/sidecar-shiki)[ Docs](https://github.com/spatie/sidecar-shiki)[ RSS](/packages/spatie-sidecar-shiki/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (7)Dependencies (15)Versions (11)Used By (0)

Run Shiki highlighting with Sidecar
===================================

[](#run-shiki-highlighting-with-sidecar)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f789b1cfcd309bfc7180c561a92b9bc8fa4922001596cbcbfbafd2b56a52434b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f736964656361722d7368696b692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/sidecar-shiki)[![GitHub Tests Action Status](https://camo.githubusercontent.com/0ccea0ae2194d76b6d94989015767f0bec49f587dc2cae0b83731895cecde424/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f736964656361722d7368696b692f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/spatie/sidecar-shiki/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/78cecaf839871274a6c2e94b4880bceb637a71b0ac03b2a828990dbe7e836727/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f736964656361722d7368696b692f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/spatie/sidecar-shiki/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/94c67b9cde675e6b06e49b5bf749bfe0ce7285d26705da425b0c807d0a9b65e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f736964656361722d7368696b692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/sidecar-shiki)

[Shiki](https://github.com/shikijs/shiki) is a beautiful syntax highlighter powered by the same language engine that many code editors use. This package allows you to run [Shiki](https://github.com/shikijs/shiki) on AWS Lambda through [Sidecar](https://github.com/hammerstonedev/sidecar).

You won't need to install Node, or any of Shiki's dependencies, on your server.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/286f722749beafa15de8b39840a60b49c18c00a3dba6b06f3f21b9b25a8f6710/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f736964656361722d7368696b692e6a70673f743d31)](https://spatie.be/github-ad-click/sidecar-shiki)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Requirements
------------

[](#requirements)

This package requires that `hammerstone/sidecar` has been installed in your Laravel application.

Follow the [Sidecar installation](https://hammerstone.dev/sidecar/docs/main/installation) and [configuration](https://hammerstone.dev/sidecar/docs/main/configuration) instructions.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/sidecar-shiki
```

Optionally, you can publish the config file with:

```
php artisan vendor:publish --tag="sidecar-shiki-config"
```

Register the `HighlightFunction::class` in your `sidecar.php` config file.

```
/*
 * All of your function classes that you'd like to deploy go here.
 */
'functions' => [
    \Spatie\SidecarShiki\Functions\HighlightFunction::class,
],
```

Deploy the Lambda function by running:

```
php artisan sidecar:deploy --activate
```

See [Sidecar documentation](https://hammerstone.dev/sidecar/docs/main/functions/deploying) for details.

Usage
-----

[](#usage)

You can highlight code by calling the `\Spatie\SidecarShiki\SidecarShiki::highlight()` function.

```
use Spatie\SidecarShiki\SidecarShiki;

SidecarShiki::highlight(
    code: '',
    language: 'php',
    theme: 'github-light',
);
```

The output is this chunk of HTML rendered through AWS Lambda which will output beautifully in the browser:

```
&lt;?php echo &quot;Hello World&quot;; ?&gt;
```

### Marking lines as highlighted, added, deleted or focus

[](#marking-lines-as-highlighted-added-deleted-or-focus)

```
use Spatie\SidecarShiki\SidecarShiki;

// Highlighting lines 1 and 4,5,6
SidecarShiki::highlight(
    code: $code,
    language: 'php',
    highlightLines: [1, '4-6'],
);

// Marking line 1 as added
SidecarShiki::highlight(
    code: $code,
    language: 'php',
    addLines: [1],
);

// Marking line 1 as deleted
SidecarShiki::highlight(
    code: $code,
    language: 'php',
    deleteLines: [1],
);

// Marking line 1 as focus
SidecarShiki::highlight(
    code: $code,
    language: 'php',
    focusLines: [1],
);
```

You can then target these classes in your own CSS to color these lines how you want.

### Using the Commonmark HighlightCodeExtension

[](#using-the-commonmark-highlightcodeextension)

Here's how we can create a function that can convert markdown to HTML with all code snippets highlighted. Inside the function we'll create a new MarkdownConverter that uses the HighlightCodeExtension provided by this package.

The `$theme` argument on `HighlightCodeExtension` expects the name of [one of the many themes](https://github.com/shikijs/shiki/blob/master/docs/themes.md) that Shiki supports.

```
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Spatie\SidecarShiki\Commonmark\HighlightCodeExtension;

function convertToHtml(string $markdown, string $theme): string
{
    $environment = (new Environment())
        ->addExtension(new CommonMarkCoreExtension())
        ->addExtension(new HighlightCodeExtension($theme));

    $markdownConverter = new MarkdownConverter(environment: $environment);

    return $markdownConverter->convertToHtml($markdown);
}
```

Testing
-------

[](#testing)

The testsuite makes connections to AWS and runs the deployed Lambda function. In order to run the testsuite, you will need an active [AWS account](https://aws.amazon.com/).

We can use the native `sidecar:configure` artisan command to create the necessary AWS credentials for Sidecar. First copy the testbench.example.yaml file to testbench.yaml. Then run `./vendor/bin/testbench sidecar:configure` to start the Sidecar setup process. (You only have to do the setup once)

```
cp testbench.yaml.example testbench.yaml
cp .env.example .env
./vendor/bin/testbench sidecar:configure
```

After finishing the Sidecar setup process, you will have received a couple of SIDECAR\_\* environment variables. Add these credentials to both `.env` and `testbench.yaml`.

Now we can deploy our local `HighlightFunction` to AWS Lambda. Run the following command in your terminal, before executing the testsuite.

```
./vendor/bin/testbench sidecar-shiki:setup
```

After the successful deployment, you can run the testsuite.

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Rias Van der Veken](https://github.com/riasvdv)
- [All Contributors](../../contributors)

Special thanks to Stefan Zweifel for his [sidecar-browsershot](https://github.com/stefanzweifel/sidecar-browsershot) package as a big help in how to test this.

Alternatives
------------

[](#alternatives)

If you don't want to install and handle Shiki yourself, take a look at [Torchlight](https://torchlight.dev), which can highlight your code with minimal setup.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance66

Regular maintenance activity

Popularity29

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~119 days

Recently: every ~178 days

Total

7

Last Release

701d ago

Major Versions

0.3.0 → 1.02022-06-27

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (18 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (10 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (5 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (4 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![timvandijck](https://avatars.githubusercontent.com/u/4528796?v=4)](https://github.com/timvandijck "timvandijck (2 commits)")

---

Tags

aws-lambdahighlightingshikisidecarspatielaravelshikicommonmarksidecarhighlighter

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/spatie-sidecar-shiki/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-sidecar-shiki/health.svg)](https://phpackages.com/packages/spatie-sidecar-shiki)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[wnx/sidecar-browsershot

A Sidecar function to run Browsershot on Lambda.

2331.5M5](/packages/wnx-sidecar-browsershot)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[spatie/laravel-support-bubble

A non-intrusive support chat bubble that can be displayed on any page

391173.6k](/packages/spatie-laravel-support-bubble)[spatie/laravel-rdap

Perform RDAP queries in a Laravel app

72108.3k2](/packages/spatie-laravel-rdap)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
