Skip to content

Blade Usage

Directives

@djot Directive

Converts Djot markup to HTML. Safe mode is enabled by default, protecting against XSS.

blade
@djot($article->body)

The directive outputs raw HTML — the surrounding <?php echo ?> is emitted for you.

@djotRaw Directive

Converts Djot markup to HTML without safe mode. Use only for trusted content.

blade
{{-- Only use for content you fully control --}}
@djotRaw($trustedArticle->body)

This bypasses XSS protection — dangerous URLs (javascript:, data:) and raw HTML blocks are preserved. Never use with user-generated content.

@djotText Directive

Converts Djot markup to plain text. The result is HTML-escaped via Laravel's e() helper. Useful for:

  • Search indexing
  • Meta descriptions
  • Email plain text fallbacks
  • Previews/excerpts
blade
<meta name="description" content="@djotText(Str::limit($article->body, 160))">

Facade

The Djot facade exposes the same functionality for inline use:

blade
{!! Djot::toHtml($content) !!}
{!! Djot::toHtml($content, 'docs') !!}
{!! Djot::toHtmlRaw($trustedContent) !!}
{{ Djot::toText($content) }}

Remember: escapes HTML. For toHtml() / toHtmlRaw(), use {!! !!} or the directives.

Common Patterns

Conditional Rendering

blade
@if($article->body)
    <div class="content">
        @djot($article->body)
    </div>
@endif

With Default Value

blade
@djot($article->body ?? '')

Excerpt with Fallback

blade
@php($excerpt = $article->excerpt ?? Str::limit(Djot::toText($article->body), 200))
<p class="excerpt">{{ $excerpt }}</p>

User-Generated Content

The default @djot directive is safe for user content:

blade
{{-- Safe - XSS protection enabled by default --}}
@djot($comment->text)

Trusted CMS Content

For content from trusted sources (admin, editors):

blade
{{-- Quick way - use @djotRaw --}}
@djotRaw($article->body)

{{-- Or use a named converter with extensions --}}
{!! Djot::toHtml($article->body, 'docs') !!}

Inline Content

For short inline content like titles or labels:

blade
<h1>@djot($article->title)</h1>

Note: This wraps the content in <p> tags. If you need truly inline output, strip the wrapper:

blade
<h1>{!! Str::of(Djot::toHtml($article->title))->replaceMatches('#^<p>|</p>$#', '')->trim() !!}</h1>

Next Steps

Released under the MIT License.