PHP code example of markup-carve / laravel-carve
1. Go to this page and download the library: Download markup-carve/laravel-carve library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
markup-carve / laravel-carve example snippets
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);
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'),
]);
}
}
// config/carve.php
return [
'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,
],
];
// config/carve.php
'HtmlFileWithReport('/srv/app/content/book/main.crv');
$html = $report['value'];
$warnings = $report['warnings'];
$dependencies = $report['dependencies'];
'converters' => [
'trusted' => [
'safe_mode' => false,
],
],
'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',
],
],
],
use MarkupCarve\LaravelCarve\Rules\ValidCarve;
$request->validate([
'body' => ['bash
php artisan vendor:publish --tag=carve-config