Static preview. Server-backed interactions are available only in a local checkout.

Authoring in Laravel

Store original Carve source, read rendered values and validate content before saving.

Rendered values and metadata

$document = Carve::render($source);
$document->html;
$document->toc();
$document->meta('title');

Metadata title: Release notes. Author: Demo editor.

Original source

---json
{"title": "Release notes", "author": "Demo editor"}
---

## Release notes

Store the /source/ and render it when needed.

### Review checklist

- Check the original markup.
- Read the rendered output.

Rendered HTML

<section id="Release-notes">
  <h2>Release notes <a href="#Release-notes" class="heading-anchor" aria-label="Permalink">#</a></h2>
  <p>Store the <em>source</em> and render it when needed.</p>
  <section id="Review-checklist">
    <h3>Review checklist <a href="#Review-checklist" class="heading-anchor" aria-label="Permalink">#</a></h3>
    <ul>
      <li>Check the original markup.</li>
      <li>Read the rendered output.</li>
    </ul>
  </section>
</section>

Collected headings

Eloquent cast and Blade component

AsCarve keeps source in the model attribute and returns a RenderedCarve value when read. This example uses an unsaved model.

use MarkupCarve\LaravelCarve\Casts\AsCarve;

protected function casts(): array
{
    return ['body' => AsCarve::class];
}

$post = new CarvePost(['body' => $source]);
<x-carve :source="$post->body" class="rendered" />

Stored attribute

---json
{"title": "Release notes", "author": "Demo editor"}
---

## Release notes

Store the /source/ and render it when needed.

### Review checklist

- Check the original markup.
- Read the rendered output.

Component output

Release notes #

Store the source and render it when needed.

Review checklist #

  • Check the original markup.
  • Read the rendered output.

Static document views

A .crv view renders a static document. View variables are not interpolated. With includes enabled, the file must be inside the trusted include root.

view()->file(resource_path('carve/authoring-guide.crv'));

A static Carve view #

This document lives under the configured include root. Laravel renders it through its .crv view engine.

Use a Blade component when the source comes from a model or a variable.

Comment preset and validation

The comment profile uses strict safe mode and the comment preset. Disallowed markup becomes text for rendering; validation rejects it before saving.

'comment' => [
    'safe_mode' => 'strict',
    'preset' => 'comment',
    'on_disallowed' => 'to_text',
]

Source

# Reader heading

Thanks for the /clear/ explanation.

Restricted output

# Reader heading

Thanks for the clear explanation.

ValidCarve::preset('comment')->maxLength(80)->lint()

The limit counts characters. Eighty accented characters pass; 81 exceed the limit.

SampleSourceValidation result
Comment Thanks for the /clear/ explanation. Accepted
Heading # A heading is not comment markup Rejected

The body is not valid Carve markup: markup is not allowed by the comment preset

Character boundary éééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé Accepted
Character limit ééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééééé Rejected

The body is not valid Carve markup: must not exceed 80 characters

Markdown spelling Use **bold** in Markdown. Rejected

The body is not valid Carve markup: `**bold**` renders as literal asterisks, not bold. Carve writes strong as *bold*.

Import Markdown and HTML

$source = Carve::fromMarkdown($markdown);
$source = Carve::fromHtml($html);
$document = Carve::render($source);

Imports return Carve source. The examples render it through the safe default converter. A GitHub alert blockquote becomes an admonition.

Markdown

Input

## Imported Markdown

A **bold** word and an *italic* word.

Carve source

## Imported Markdown

A *bold* word and an /italic/ word.

Imported Markdown #

A bold word and an italic word.

GitHub alert

Input

> [!TIP]
> A **bold** reminder: run `php artisan carve:lint` before you commit.

Carve source

::: tip
A *bold* reminder: run `php artisan carve:lint` before you commit.
:::

HTML

Input

<h2>Imported HTML</h2><p>A <strong>bold</strong> word.</p>

Carve source

## Imported HTML

A *bold* word.

Imported HTML #

A bold word.

Lint and Artisan tools

Carve::lint('Use **bold** in Markdown.');

A %% carve-lint-disable-next-line comment silences the named rule on the next line. The comment renders nothing.

Carve::lint('%% carve-lint-disable-next-line markdown-strong-double-star
Use **bold** in Markdown.');

0 findings.

Run these commands in a local checkout. They render, convert or lint files on disk.

php artisan carve:render resources/carve/authoring-guide.crv --format=html
php artisan carve:render resources/carve/authoring-guide.crv --format=text
php artisan carve:convert README.md --output=storage/app/readme.crv
php artisan carve:lint resources/carve