PHPackages                             markup-carve/laravel-carve - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. markup-carve/laravel-carve

ActiveLibrary[Templating &amp; Views](/categories/templating)

markup-carve/laravel-carve
==========================

Laravel integration for markup-carve/carve-php — Blade directives, services, validation, and caching

0.1.4(2w ago)026MITPHPPHP ^8.2CI passing

Since Jul 9Pushed 4d agoCompare

[ Source](https://github.com/markup-carve/laravel-carve)[ Packagist](https://packagist.org/packages/markup-carve/laravel-carve)[ Docs](https://github.com/markup-carve/laravel-carve)[ RSS](/packages/markup-carve-laravel-carve/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (6)Dependencies (16)Versions (8)Used By (0)

Laravel Carve
=============

[](#laravel-carve)

[![CI](https://github.com/markup-carve/laravel-carve/actions/workflows/ci.yml/badge.svg)](https://github.com/markup-carve/laravel-carve/actions/workflows/ci.yml)[![PHP](https://camo.githubusercontent.com/38efa44dc8e84ab6999109f813628b6d2732a4ae37bd4322bdb64d9af605237c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d61726b75702d63617276652f6c61726176656c2d6361727665)](https://packagist.org/packages/markup-carve/laravel-carve)[![License](https://camo.githubusercontent.com/b88d155c8488d9254a14234d5eaeae231d6d020b7cb3d5e9696ff202f8a57fa3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61726b75702d63617276652f6c61726176656c2d6361727665)](LICENSE)

[Carve](https://github.com/markup-carve/carve-php) markup language integration for Laravel — Blade directives, services, validation, and caching.

Installation
------------

[](#installation)

```
composer require markup-carve/laravel-carve
```

The service provider and `Carve` facade alias are auto-discovered via Laravel's package discovery.

Optionally publish the config:

```
php artisan vendor:publish --tag=carve-config
```

Usage
-----

[](#usage)

### Blade Directives

[](#blade-directives)

```
{{-- Safe by default - XSS protection enabled --}}
@carve($article->body)

{{-- For trusted content only - no XSS protection --}}
@carveRaw($trustedContent)

{{-- Plain text output (escaped) --}}
@carveText($article->body)
```

### Facade

[](#facade)

```
use MarkupCarve\LaravelCarve\Facades\Carve;

$html = Carve::toHtml($source);
$text = Carve::toText($source);
$md   = Carve::toMarkdown($source);
$ansi = Carve::toAnsi($source); // terminal output
$raw  = Carve::toHtmlRaw($trustedSource);
```

### Dependency Injection

[](#dependency-injection)

```
use MarkupCarve\LaravelCarve\Service\CarveConverterInterface;
use MarkupCarve\LaravelCarve\Service\CarveManager;

class ArticleController
{
    public function __construct(
        private CarveConverterInterface $carve,
        private CarveManager $manager,
    ) {}

    public function show(Article $article): View
    {
        return view('article.show', [
            'html' => $this->carve->toHtml($article->body),
            'text' => $this->carve->toText($article->body),
            'docs' => $this->manager->toHtml($article->body, 'docs'),
        ]);
    }
}
```

Configuration
-------------

[](#configuration)

```
// config/carve.php
return [
    'converters' => [
        // Default has safe_mode: true (XSS protection enabled)
        'default' => [
            'safe_mode' => true,
            'symbols' => [],
            'source_lines' => false,
        ],

        // For trusted content (admin, CMS)
        'trusted' => [
            'safe_mode' => false,
        ],
    ],
    'cache' => [
        'enabled' => false,
        'store' => null,
    ],
];
```

`symbols` maps `:name:` shortcodes to trusted raw HTML. Symbol values are inserted without escaping, so never populate this option from user input. Set `source_lines` to `true` to add 1-based `data-source-line` attributes to rendered blocks for editor preview scroll-sync. Both options are configured per converter profile.

### Multiple Converter Profiles

[](#multiple-converter-profiles)

Use different configurations for different contexts:

```
{{-- Default is safe --}}
@carve($comment->body)

{{-- Use named converter for trusted content --}}
{!! Carve::toHtml($article->body, 'trusted') !!}

{{-- Or use @carveRaw for quick trusted rendering --}}
@carveRaw($article->body)
```

### Safe Mode

[](#safe-mode)

Safe mode is *enabled by default* for XSS protection. Disable only for trusted content:

```
'converters' => [
    'trusted' => [
        'safe_mode' => false,
    ],
],
```

### Extensions

[](#extensions)

Enable [carve-php extensions](https://github.com/markup-carve/carve-php) per converter:

```
'converters' => [
    'default' => [
        'extensions' => [
            ['type' => 'autolink'],
            ['type' => 'smart_quotes'],
            [
                'type' => 'heading_permalinks',
                'symbol' => '#',
                'position' => 'after',
            ],
        ],
    ],
    'with_mentions' => [
        'extensions' => [
            [
                'type' => 'mentions',
                'user_url_template' => 'https://github.com/{username}',
            ],
            'table_of_contents',
        ],
    ],
],
```

Available extensions:

- `admonition` - Admonition blocks (note, tip, warning, danger, etc.)
- `autolink` - Auto-convert URLs to clickable links
- `citations` - Bracketed citations with an in-document bibliography (numbered or author-date)
- `code_callouts` - Numbered callout markers on fenced-code lines with a bound explanation list
- `code_group` - Transform code-group divs into tabbed interfaces
- `color_swatch` - Inline color swatches for CSS color tokens via the `color` role
- `default_attributes` - Add default attributes to elements by type
- `details` - Render `::: details` blocks as native ``/`` widgets
- `external_links` - Configure external link behavior (target, rel)
- `fenced_render` - Emit fenced blocks of a chosen language as client-rendered hydration elements
- `frontmatter` - Parse YAML/TOML/JSON frontmatter blocks
- `glossary` - Glossary definition lists with linked term references
- `heading_level_shift` - Shift heading levels up/down
- `heading_numbers` - Auto-number sections and rewrite heading cross-references
- `heading_permalinks` - Add anchor links to headings
- `heading_reference` - Link to headings with `[text](#heading)` syntax
- `index` - Collect `:index[term]` markers into a sorted index block
- `inline_footnotes` - Convert spans with class to inline footnotes
- `list_table` - Author tables as nested lists (`::: list-table`) with block content in cells
- `math_block` - Render `math` fenced code blocks as display math
- `mentions` - Convert @username to profile links
- `mermaid` - Render Mermaid diagram code blocks
- `plantuml` - Render PlantUML/`puml` diagram code blocks (needs a client renderer; see below)
- `semantic_span` - Convert spans to ``, ``, `` elements
- `smart_quotes` - Convert straight quotes to typographic quotes
- `spoiler` - Hidden spoiler content revealed on interaction
- `tab_normalize` - Expand tabs in code content to spaces at render time
- `table_of_contents` - Generate TOC from headings
- `tabs` - Tabbed content blocks (CSS or ARIA mode)
- `toc_placement` - Render the TOC exactly where a `::: toc` block appears
- `wikilinks` - Support `[[Page Name]]` wiki-style links

See [Extensions documentation](https://markup-carve.github.io/laravel-carve/extensions/) for detailed configuration options.

### Client-side diagram rendering

[](#client-side-diagram-rendering)

The diagram extensions emit a `` hydration element; the browser turns it into a picture. Mermaid, WaveDrom, Vega-Lite and Chart each render once you load their library. **Graphviz and D2** render fully offline with the WebAssembly helpers from [`@markup-carve/carve-grammars`](https://github.com/markup-carve/carve-grammars)(no server, no external call):

```
import { renderDiagrams } from '@markup-carve/carve-grammars/diagrams'

await renderDiagrams(document.querySelector('.carve-content')) // graphviz + d2, offline
```

**PlantUML** is the exception - it has no practical in-browser renderer and needs a [Kroki](https://kroki.io) server:

```
import { renderKrokiDiagrams } from '@markup-carve/carve-grammars/diagrams/kroki'

await renderKrokiDiagrams(document.querySelector('.carve-content'), {
    server: 'https://kroki.internal', // your own instance
})
```

> ⚠️ **Privacy / GDPR:** the default Kroki server is the public `https://kroki.io`, so the PlantUML source is sent to a **third party outside your domain**. For sensitive content, or to stay offline, point `server` at a self-hosted or localhost Kroki so no data leaves your control, and disclose the external call to end users where required. For a build-time / SSR pipeline, render diagrams server-side instead so no client JS ships.

### Validation Rule

[](#validation-rule)

Validate that a field contains valid Carve markup:

```
use MarkupCarve\LaravelCarve\Rules\ValidCarve;

$request->validate([
    'body' => ['required', 'string', new ValidCarve()],
]);
```

Documentation
-------------

[](#documentation)

Full documentation: **[markup-carve.github.io/laravel-carve](https://markup-carve.github.io/laravel-carve/)**

- [Installation](https://markup-carve.github.io/laravel-carve/guide/installation)
- [Configuration](https://markup-carve.github.io/laravel-carve/guide/configuration)
- [Blade Usage](https://markup-carve.github.io/laravel-carve/guide/blade-usage)
- [Service Usage](https://markup-carve.github.io/laravel-carve/guide/service-usage)
- [Validation](https://markup-carve.github.io/laravel-carve/guide/validation)
- [Safe Mode](https://markup-carve.github.io/laravel-carve/guide/safe-mode)
- [Extensions](https://markup-carve.github.io/laravel-carve/extensions/)
- [Caching](https://markup-carve.github.io/laravel-carve/guide/caching)
- [Carve Syntax](https://markup-carve.github.io/laravel-carve/guide/carve-syntax)

Demo Application
----------------

[](#demo-application)

A full runnable demo app lives at [laravel-carve-demo](https://github.com/markup-carve/laravel-carve-demo): the Blade directives, facade and service usage, form validation, safe-mode comparison, static render mode, plain text extraction and the extension set.

[![laravel-carve demo](https://raw.githubusercontent.com/markup-carve/laravel-carve-demo/main/docs/screenshots/blade-directive.png)](https://github.com/markup-carve/laravel-carve-demo)

What is Carve?
--------------

[](#what-is-carve)

[Carve](https://github.com/markup-carve/carve) is a post-Markdown lightweight markup language. It builds on the foundations of [Djot](https://github.com/jgm/djot), John MacFarlane's post-Markdown project, and offers cleaner syntax and more features than Markdown while being easier to parse.

Learn more about Carve syntax at [github.com/markup-carve/carve](https://github.com/markup-carve/carve).

Ecosystem
---------

[](#ecosystem)

This package is part of the [Carve organization](https://github.com/markup-carve) - the spec with its conformance corpus, three byte-identical reference implementations (JS, PHP, Rust), editor plugins, and framework integrations. See [awesome-carve](https://github.com/markup-carve/awesome-carve) for a curated list of everything Carve.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance98

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

5

Last Release

15d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39854?v=4)[Mark Scherer](/maintainers/dereuromark)[@dereuromark](https://github.com/dereuromark)

---

Top Contributors

[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (30 commits)")

---

Tags

carvelaravelmarkuplaravelparserpackageblademarkupcarve

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/markup-carve-laravel-carve/health.svg)

```
[![Health](https://phpackages.com/badges/markup-carve-laravel-carve/health.svg)](https://phpackages.com/packages/markup-carve-laravel-carve)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[moonshine/moonshine

Laravel administration panel

1.3k268.2k90](/packages/moonshine-moonshine)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

731189.9k16](/packages/tallstackui-tallstackui)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k31.8M163](/packages/laravel-cashier)[blade-ui-kit/blade-icons

A package to easily make use of icons in your Laravel Blade views.

2.5k46.0M465](/packages/blade-ui-kit-blade-icons)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
