Skip to content

Configuration

Default Configuration

The package works out of the box with sensible defaults. Safe mode is enabled by default for security.

Full Configuration Reference

php
// config/djot.php
return [
    'converters' => [
        'default' => [
            'safe_mode' => true,             // XSS protection (enabled by default)
            'significant_newlines' => false, // Markdown-like line break handling
            'soft_break_mode' => null,       // newline, space or br
            'xhtml' => false,                // XHTML-compatible output
            'extensions' => [],
        ],

        // Add custom profiles as needed
        'trusted' => [
            'safe_mode' => false,
        ],
    ],
    'cache' => [
        'enabled' => false,
        'store' => null, // null = default cache store
    ],
];

Converter Options

OptionTypeDefaultDescription
safe_modebooltrueXSS protection - disable only for trusted content
significant_newlinesboolfalseAllow blocks to interrupt paragraphs without blank lines (markdown-like behavior)
soft_break_modestringnullHow to render soft breaks: newline, space, or br
xhtmlboolfalseOutput XHTML-compatible markup (self-closing tags)
extensionsarray[]Djot extensions to enable for this profile

Converter Profiles

You can define multiple converter profiles for different contexts. Each profile is resolved as its own DjotConverter instance.

Example: Default Safe + Trusted Converter

php
'converters' => [
    // Default is safe
    'default' => [
        'safe_mode' => true,
    ],

    // For trusted admin/editor content
    'trusted' => [
        'safe_mode' => false,
    ],

    // For documentation with extensions
    'docs' => [
        'safe_mode' => false,
        'extensions' => [
            'table_of_contents',
            'heading_permalinks',
        ],
    ],
],

Using Profiles in Blade

blade
{{-- Uses 'default' profile (safe mode) --}}
@djot($comment->text)

{{-- Uses 'trusted' profile (no safe mode) --}}
{!! Djot::toHtml($article->body, 'trusted') !!}

{{-- Quick way for trusted content --}}
@djotRaw($article->body)

Using Profiles in Services

php
use PhpCollective\LaravelDjot\Service\DjotManager;

class ContentService
{
    public function __construct(
        private DjotManager $djot,
    ) {}

    public function renderComment(string $text): string
    {
        return $this->djot->toHtml($text); // default profile
    }

    public function renderArticle(string $text): string
    {
        return $this->djot->toHtml($text, 'trusted');
    }
}

Container Bindings

The package registers the following bindings:

BindingDescription
PhpCollective\LaravelDjot\Service\DjotManagerMulti-profile manager (singleton)
djotAlias for DjotManager
PhpCollective\LaravelDjot\Service\DjotConverterInterfaceDefault converter instance

Next Steps

Released under the MIT License.