Configuring code highlighting | laravel-markdown | Spatie

 SPATIE

  Laravel Markdown
===================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-markdown](https://spatie.be/docs/laravel-markdown/v1)  Rendering-markdown  Configuring code highlighting

 Version   v1

 Other versions for crawler [v1](https://spatie.be/docs/laravel-markdown/v1)

- [ Introduction ](https://spatie.be/docs/laravel-markdown/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-markdown/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-markdown/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-markdown/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-markdown/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-markdown/v1/changelog)
- [ Resources and alternatives ](https://spatie.be/docs/laravel-markdown/v1/resources-and-alternatives)
- [ About us ](https://spatie.be/docs/laravel-markdown/v1/about-us)

Usage in Blade
--------------

- [ General usage ](https://spatie.be/docs/laravel-markdown/v1/usage-in-blade/general-usage)
- [ Configuring code highlighting ](https://spatie.be/docs/laravel-markdown/v1/usage-in-blade/configuring-code-highlighting)
- [ Rendering anchors ](https://spatie.be/docs/laravel-markdown/v1/usage-in-blade/rendering-anchors)
- [ Passing options to Commonmark ](https://spatie.be/docs/laravel-markdown/v1/usage-in-blade/passing-options-to-commonmark)
- [ ](https://spatie.be/docs/laravel-markdown/v1/usage-in-blade/adding-custom-attributes)

Rendering markdown
------------------

- [ General usage ](https://spatie.be/docs/laravel-markdown/v1/rendering-markdown/general-usage)
- [ Configuring code highlighting ](https://spatie.be/docs/laravel-markdown/v1/rendering-markdown/configuring-code-highlighting)
- [ Rendering anchors ](https://spatie.be/docs/laravel-markdown/v1/rendering-markdown/rendering-anchors)
- [ Passing options to Commonmark ](https://spatie.be/docs/laravel-markdown/v1/rendering-markdown/passing-options-to-commonmark)

Advanced usage
--------------

- [ Highlighting lines ](https://spatie.be/docs/laravel-markdown/v1/advanced-usage/highlighting-lines)
- [ Caching results ](https://spatie.be/docs/laravel-markdown/v1/advanced-usage/caching-results)
- [ Customizing the rendering process ](https://spatie.be/docs/laravel-markdown/v1/advanced-usage/customizing-the-rendering-process)

 Configuring code highlighting
=============================

###  On this page

1. [ Configuring a theme ](#content-configuring-a-theme)
2. [ Disabling code highlighting ](#content-disabling-code-highlighting)

By default, [Shiki PHP](https://github.com/spatie/shiki-php) is used to highlight 100+ languages, including PHP, JS, Blade, [and many more](https://github.com/shikijs/shiki/blob/main/docs/languages.md).

In the `code_highlighting.theme` value op the `markdown` config file you can specify the default theme to be used. This value can be [one of the themes](https://github.com/shikijs/shiki/blob/main/docs/themes.md) that Shiki supports out of the box.

Configuring a theme
-----------------------------------------------------------------------------------------------------------------

Shiki [supports](https://github.com/shikijs/shiki/blob/main/docs/themes.md) any [VSCode themes](https://code.visualstudio.com/docs/getstarted/themes).

You can use a custom theme using the absolute path to a theme in as the value for `code_highlighting.theme`.

Alternatively, you can pass a theme to `highlightTheme`

```
$html = app(Spatie\LaravelMarkdown\MarkdownRenderer::class)
   ->highlightTheme('github-dark')
   ->toHtml($markdown);
```

Disabling code highlighting
-----------------------------------------------------------------------------------------------------------------------------------------

Code highlighting can be disabled globally, by setting the `code_highlighting.enabled` key in the `markdown` config file to `false`.

Alternatively, you call `disableHighlighting()`.

```
$html = app(Spatie\LaravelMarkdown\MarkdownRenderer::class)
   ->disableHighlighting()
   ->toHtml($markdown);
```
