PHP code example of php-collective / laravel-djot

1. Go to this page and download the library: Download php-collective/laravel-djot 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/ */

    

php-collective / laravel-djot example snippets


use PhpCollective\LaravelDjot\Facades\Djot;

$html = Djot::toHtml($source);
$text = Djot::toText($source);
$raw  = Djot::toHtmlRaw($trustedSource);

use PhpCollective\LaravelDjot\Service\DjotConverterInterface;
use PhpCollective\LaravelDjot\Service\DjotManager;

class ArticleController
{
    public function __construct(
        private DjotConverterInterface $djot,
        private DjotManager $manager,
    ) {}

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

// config/djot.php
return [
    'converters' => [
        // Default has safe_mode: true (XSS protection enabled)
        'default' => [
            'safe_mode' => true,
        ],

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

'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 PhpCollective\LaravelDjot\Rules\ValidDjot;

$request->validate([
    'body' => ['
bash
composer 
bash
php artisan vendor:publish --tag=djot-config