General usage | laravel-markdown | Spatie

 SPATIE

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-markdown](https://spatie.be/docs/laravel-markdown/v1)  Usage-in-blade  General usage

 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)

 General usage
=============

###  On this page

1. [ The Blade directive ](#content-the-blade-directive)

Use the `x-markdown` Blade component to render markdown to HTML.

This chunk of markdown...

```

# My title

This is a [link to our website](https://spatie.be)

```php
echo 'Hello world';
```

```

... will be converted to this chunk of HTML:

```

    My title
    This is a link to our website
    echo &#39;Hello world&#39;;

```

*Note:* If you're outputting the Markdown through blade, rather than direct input, you will need to use the unescaped blade statement to prevent Laravel's XSS protection stripping the tags:

```
{!! $article->content !!}
```

The Blade directive
-----------------------------------------------------------------------------------------------------------------

Alternatively, you could use the `@markdown` Blade directive to render markdown to HTML.

This chunk of markdown...

```
@markdown
# My title
This is a [link to our website](https://spatie.be)
```php
echo 'Hello world';
```
@endmarkdown
```

... will be converted to this chunk of HTML:

```

    My title
    This is a link to our website
    echo &#39;Hello world&#39;;

```

You can also use variables or strings as argument

```
@markdown($article->content)
@markdown('[link to our website](https://spatie.be)')
```
