Jacobdo
Jacobdo

Reputation: 2021

Show blade code snippet inside a laravel blade view

I am creating documentation for my blade based components in a laravel project and would like to display syntax highlighted blade code snippets as part of the documentation a la something like this:

Desired result

I have installed graham-campbell/markdown package and I try use it inside a .blade.php file as follows:

enter image description here

(Do not mind the escape character)

However, the output I get is as follows:

Actual output

Upvotes: 2

Views: 2248

Answers (2)

tomcaptain
tomcaptain

Reputation: 31

I came across the same problem, this worked for me:

@verbatim

  {{ blade code }}
  @directive 
    blade code 
  @enddirective

@endverbatim

Upvotes: 0

Salim Djerbouh
Salim Djerbouh

Reputation: 11044

You can wrap the Blade in a @verbatim directive and use Highlight JS with a style you like

<p>You can use the laravel code template like this</p>

@markdown
```php
@verbatim
@include('components.inputs.text', [
   'name' => 'input_name',
   'label' => 'testing',
])
@endverbatim
```
@endmarkdown
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/a11y-dark.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js"></script>
<script>
    hljs.initHighlightingOnLoad();
</script>

Result

enter image description here

Hope this helps

Upvotes: 6

Related Questions