Blade Usage
Directives
@carve Directive
Converts Carve markup to HTML. Safe mode is enabled by default, protecting against XSS.
@carve($article->body)The directive outputs raw HTML — the surrounding <?php echo ?> is emitted for you.
@carveRaw Directive
Converts Carve markup to HTML without safe mode. Use only for trusted content.
{{-- Only use for content you fully control --}}
@carveRaw($trustedArticle->body)This disables safe mode: explicit raw-HTML passthrough (```=html blocks and `...`{=html} inline) is emitted verbatim instead of escaped. Dangerous URLs (javascript:, data:) are still sanitized in both modes. Never use @carveRaw with user-generated content - see Safe Mode.
@carveText Directive
Converts Carve 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
<meta name="description" content="@carveText(Str::limit($article->body, 160))">Facade
The Carve facade exposes the same functionality for inline use:
{!! Carve::toHtml($content) !!}
{!! Carve::toHtml($content, 'docs') !!}
{!! Carve::toHtmlRaw($trustedContent) !!}
{{ Carve::toText($content) }}Remember: escapes HTML. For toHtml() / toHtmlRaw(), use {!! !!} or the directives.
Common Patterns
Conditional Rendering
@if($article->body)
<div class="content">
@carve($article->body)
</div>
@endifWith Default Value
@carve($article->body ?? '')Excerpt with Fallback
@php($excerpt = $article->excerpt ?? Str::limit(Carve::toText($article->body), 200))
<p class="excerpt">{{ $excerpt }}</p>User-Generated Content
The default @carve directive is safe for user content:
{{-- Safe - XSS protection enabled by default --}}
@carve($comment->text)Trusted CMS Content
For content from trusted sources (admin, editors):
{{-- Quick way - use @carveRaw --}}
@carveRaw($article->body)
{{-- Or use a named converter with extensions --}}
{!! Carve::toHtml($article->body, 'docs') !!}Inline Content
For short inline content like titles or labels:
<h1>@carve($article->title)</h1>Note: This wraps the content in <p> tags. If you need truly inline output, strip the wrapper:
<h1>{!! Str::of(Carve::toHtml($article->title))->replaceMatches('#^<p>|</p>$#', '')->trim() !!}</h1>Next Steps
- Service Usage - use the converter in PHP code
- Safe Mode - understand XSS protection