- What is php-collective/djot and how does it differ from Markdown?
- php-collective/djot is a PHP implementation of Djot, the lightweight markup language created by John MacFarlane, the author of CommonMark and Pandoc. It parses Djot source and renders clean HTML, offering more consistent and unambiguous syntax with fewer edge cases than Markdown. It also ships richer built-in features such as attributes, footnotes, definition lists, math, tables, and lists.
- How do I install php-collective/djot in a Laravel application?
- Install it with Composer using composer require php-collective/djot. It is a pure-PHP, MIT-licensed library with PSR-4 autoloading, no framework coupling, and no known heavy transitive dependencies; expect PHP 8.x plus ext-mbstring. There is no service provider, facade, Blade directive, or config file, so you write a thin wrapper yourself, typically a singleton binding and a small DjotRenderer service in a service provider.
- Which Laravel and PHP versions does php-collective/djot support?
- Because the package is framework-agnostic, it works with any Laravel version running on PHP 8.x with the mbstring extension available. Laravel version constraints do not really apply since there is no Laravel-specific integration code. Your real compatibility check is your PHP runtime and your own wrapper code.
- How do I convert Djot markup to HTML in PHP?
- Create the parser or renderer object and pass your Djot source string to its render method to get HTML back; the API is simple and dependency-free. In Laravel, wrap that call behind your own DjotRenderer service with a cached render contract so controllers and Blade views stay clean. Note that the package has both a fast HTML path and an authoritative parser path, so snapshot-test your output to catch any divergence.
- Is php-collective/djot safe for untrusted user-submitted content?
- Not by default; it is a parser and renderer, not a sanitizer. Safe defaults exist on the Markdown import path, where raw HTML stays inert unless trustedRawHtml is set to true, and resolved mention and tag URLs pass a URL-safety check. For comments, profiles, and other user-generated input you should still add an explicit HTML sanitization layer before output.
- How should I cache Djot-rendered HTML in Laravel?
- Rendering is a pure string-to-string operation, so cache the resulting HTML keyed by a hash of the source, the render options, and the exact package version. Including the pinned version in the cache key matters because patch releases have changed rendered HTML in the past. That way an upgrade automatically invalidates stale cached markup.
- Can I customize the HTML output or inspect the Djot AST?
- Yes. Parsing is AST-based, so you can inspect, transform, or render documents your own way rather than accepting the default HTML. Version 0.1.34 also adds a real extension surface, with MentionsExtension accepting resolver and tagResolver closures plus a shared resolverContext. That gives you a supported hook model instead of a hardcoded renderer.
- How do I migrate existing Markdown content to Djot?
- Version 0.1.34 ships a MarkdownToDjot importer that preserves references, entities, pointy destinations, and link titles, and there is a Markdown output path as well, so moving to Djot is not a one-way door. For large corpora, plan an editorial migration and diff the newly rendered HTML against your existing output before switching over.
- How stable is php-collective/djot for production use?
- It is pre-1.0 with a small maintainer pool, no commercial backing, and very few downstream dependents, so adopting it means being an early adopter. Patch releases have already changed rendered HTML, and the fast HTML path once had to fall back to the authoritative parser for emphasis marker seams. Pin exact versions and gate every bump behind a rendering-diff or conformance test against the official Djot spec suite.
- What are the alternatives to php-collective/djot for Laravel projects?
- The main alternatives are league/commonmark and erusev/parsedown for Markdown, or the reference Djot implementations in Lua and JavaScript. Choose Djot when you control the author and want unambiguous syntax with better footnotes, attributes, math, and tables. Stay on CommonMark if a large ecosystem and a long production track record matter more than syntax consistency.