markup-carve / symfony-carve
Symfony bundle to render Carve markup to HTML via carve-php.
Package info
github.com/markup-carve/symfony-carve
Type:symfony-bundle
pkg:composer/markup-carve/symfony-carve
Fund package maintenance!
Requires
- php: ^8.2
- markup-carve/carve-php: ^0.1.1
- symfony/config: ^6.4 || ^7.0
- symfony/dependency-injection: ^6.4 || ^7.0
- symfony/http-kernel: ^6.4 || ^7.0
Requires (Dev)
- php-collective/code-sniffer: ^0.3.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.5 || ^11.0
- symfony/framework-bundle: ^6.4 || ^7.0
- symfony/twig-bundle: ^6.4 || ^7.0
- twig/twig: ^3.0
Suggests
- symfony/twig-bundle: To use the {{ value|carve }} Twig filter and carve() function
README
Symfony bundle that renders Carve markup to HTML using carve-php.
Carve is "Djot minus the footguns": a lightweight markup language with consistent, unambiguous syntax.
Installation
composer require markup-carve/symfony-carve
Register the bundle (Symfony Flex does this automatically; otherwise add it to config/bundles.php):
return [ // ... MarkupCarve\SymfonyCarve\CarveBundle::class => ['all' => true], ];
Usage
Service
use MarkupCarve\SymfonyCarve\CarveRenderer; public function show(CarveRenderer $carve): Response { $html = $carve->render('# Hello *world*'); return new Response($html); }
Twig
{# filter #} {{ article.body|carve }} {# function #} {{ carve('# Inline /snippet/') }}
Output is marked safe, so Twig does not double-escape it. The renderer sanitizes input according to the configured safe mode before that point.
Configuration
# config/packages/carve.yaml carve: safe_mode: true # sanitize HTML (default: true) raw_html: strip # strip | escape | allow (default: strip)
| Key | Type | Default | Description |
|---|---|---|---|
safe_mode |
bool | true |
Enable HTML sanitization. Keep this on for untrusted input. |
raw_html |
enum | strip |
How raw HTML is handled when safe_mode is on: strip, escape, allow. |
Setting safe_mode: false disables sanitization entirely. Only do this for fully trusted input.
Demo
A full runnable demo app lives at symfony-carve-demo: the Twig filter and function, the CarveRenderer service, a live editor, a safe-mode comparison, and a syntax gallery.
License
MIT
