Installation &amp; setup | laravel-markdown | Spatie

 SPATIE

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-markdown](https://spatie.be/docs/laravel-markdown/v1)  Installation &amp; setup

 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)

 Installation &amp; setup
========================

You can install the package via composer:

```
composer require spatie/laravel-markdown
```

To enable the code highlighting feature, you'll need to install the JavaScript package [`shiki`](https://github.com/shikijs/shiki) in your project. You can install it via npm...

```
npm install shiki
```

... or Yarn.

```
yarn add shiki
```

Make sure you have installed Node 10 or higher.

Optionally, You can publish the config file with:

```
php artisan vendor:publish --provider="Spatie\LaravelMarkdown\MarkdownServiceProvider" --tag="markdown-config"
```

This is the contents of the published config file:

```
return [
    'code_highlighting' => [
        /*
         * To highlight code, we'll use Shiki under the hood. Make sure it's installed.
         *
         * More info: https://spatie.be/docs/laravel-markdown/v1/installation-setup
         */
        'enabled' => true,

        /*
         * The name of or path to a Shiki theme
         *
         * More info: https://github.com/shikijs/shiki/blob/main/docs/themes.md
         */
        'theme' => 'github-light',
    ],

    /*
     * When enabled, anchor links will be added to all titles
     */
    'add_anchors_to_headings' => true,

    /*
     * These options will be passed to the league/commonmark package which is
     * used under the hood to render markdown.
     *
     * More info: https://spatie.be/docs/laravel-markdown/v1/using-the-blade-component/passing-options-to-commonmark
     */
    'commonmark_options' => [],

    /*
     * Rendering markdown to HTML can be resource intensive. By default
     * we'll cache the results.
     *
     * You can specify the name of a cache store here. When set to `null`
     * the default cache store will be used. If you do not want to use
     * caching set this value to `false`.
     */
    'cache_store' => null,

    /*
     * When cache_store is enabled, this value will be used to determine
     * how long the cache will be valid. If you set this to `null` the
     * cache will never expire.
     *
     */
    'cache_duration' => null,

    /*
     * This class will convert markdown to HTML
     *
     * You can change this to a class of your own to greatly
     * customize the rendering process
     *
     * More info: https://spatie.be/docs/laravel-markdown/v1/advanced-usage/customizing-the-rendering-process
     */
    'renderer_class' => Spatie\LaravelMarkdown\MarkdownRenderer::class,

    /*
     * These extensions should be added to the markdown environment. A valid
     * extension implements League\CommonMark\Extension\ExtensionInterface
     *
     * More info: https://commonmark.thephpleague.com/2.4/extensions/overview/
     */
    'extensions' => [
        //
    ],

    /*
     * These block renderers should be added to the markdown environment. A valid
     * renderer implements League\CommonMark\Renderer\NodeRendererInterface;
     *
     * More info: https://commonmark.thephpleague.com/2.4/customization/rendering/
     */
    'block_renderers' => [
        // ['class' => FencedCode::class, 'renderer' => MyCustomCodeRenderer::class, 'priority' => 0]
    ],

    /*
     * These inline renderers should be added to the markdown environment. A valid
     * renderer implements League\CommonMark\Renderer\NodeRendererInterface;
     *
     * More info: https://commonmark.thephpleague.com/2.4/customization/rendering/
     */
    'inline_renderers' => [
        // ['class' => FencedCode::class, 'renderer' => MyCustomCodeRenderer::class, 'priority' => 0]
    ],

    /*
     * These inline parsers should be added to the markdown environment. A valid
     * parser implements League\CommonMark\Renderer\InlineParserInterface;
     *
     * More info: https://commonmark.thephpleague.com/2.4/customization/inline-parsing/
     */
    'inline_parsers' => [
        // ['parser' => MyCustomInlineParser::class, 'priority' => 0]
    ],
];
```
