Store original Carve source, read rendered values and validate content before saving.
$document = Carve::render($source);
$document->html;
$document->toc();
$document->meta('title');
Metadata title: Release notes. Author: Demo editor.
---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.<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>
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" />
---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.
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'));
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.
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',
]
# Reader heading
Thanks for the /clear/ explanation.# 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.
| Sample | Source | Validation 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*. |
$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.
## Imported Markdown
A **bold** word and an *italic* word.## Imported Markdown
A *bold* word and an /italic/ word.A bold word and an italic word.
> [!TIP]
> A **bold** reminder: run `php artisan carve:lint` before you commit.::: tip
A *bold* reminder: run `php artisan carve:lint` before you commit.
:::<h2>Imported HTML</h2><p>A <strong>bold</strong> word.</p>## Imported HTML
A *bold* word.
A bold word.
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