php-collective / djot
A PHP parser for Djot, a modern light markup language
Fund package maintenance!
0.1.25
2026-04-02 02:19 UTC
Requires
- php: ^8.2
Requires (Dev)
- nikic/php-fuzzer: ^0.0.11
- php-collective/code-sniffer: dev-master
- phpstan/phpstan: ^2.1.32
- phpunit/phpunit: ^11.0 || ^12.0 || ^13.0
- dev-master
- 0.1.25
- 0.1.24
- 0.1.23
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.19
- 0.1.18
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/fix-html-to-djot-table-ref-escaping
- dev-feature/fix-html-to-djot-remaining-serialization
- dev-feature/fix-html-to-djot-container-and-list-blocks
- dev-feature/smart-quote-performance
- dev-feature/fix-html-to-djot-figure-fallback
- dev-feature/fix-semantic-span-samp-var
- dev-feature/fix-html-to-djot-inline-quotes
- dev-feature/semantic-span-roundtrip-new
- dev-feature/fix-html-to-djot-multiline-meta
- dev-feature/fix-html-to-djot-math-fallback
- dev-feature/html-to-djot-enhancements
- dev-feature/fix-html-to-djot-block-structures
- dev-feature/fix-html-to-djot-edge-cases
- dev-feature/fix-scheme-normalization-and-xhtml-footnotes
- dev-feature/fix-internal-links-and-heading-ids
- dev-feature/round-trip-edge-case-tests
- dev-feature/round-trip-edge-cases
- dev-feature/line-block-round-trip
- dev-feature/extended-round-trip-support
- dev-docs/symfony-advanced-config
- dev-docs/symfony-integration
- dev-feature/round-trip-extensions
- dev-feature/round-trip-tabs-codegroup
- dev-feature/fix-current-audit-findings
- dev-feature/extension-lifecycle-cleanup
- dev-feature/extension-roundtrip
- dev-feature/transform-prototype
- dev-feature/render-options-heading-shift
- dev-feature/plan-nonmutating-before-render
- dev-feature/clone-before-render
- dev-feature/arch-render-context
- dev-feature/fix-review-findings
- dev-feature/composition-api
- dev-code-block-tab-width-default
- dev-decouple-soft-break-from-significant-newlines
- dev-fix/tabs-extension-toc-compatibility
- dev-feature/heading-references
- dev-pr-138-review
- dev-feature/inline-footnotes
- dev-inline-footnotes
- dev-fix/div-class-merging
- dev-feature/code-group-extension
- dev-docs/cookbook-split
- dev-docs/cookbook-cleanup
- dev-feature/admonition-icons
- dev-docs/video-embeds-cookbook
- dev-feature/mermaid-extension
- dev-feature/tabs-extension
- dev-feature/admonition-extension
- dev-feature/heading-level-shift-extension
- dev-frontmatter-default-format
- dev-feature/soft-break-mode-separation
- dev-docs/replace-playground-with-syntax-reference
- dev-frontmatter-block-attributes
- dev-feature/frontmatter-extension
- dev-fix/remove-markdown-style-definition-lists
- dev-fix/definition-list-syntax-docs
- dev-fix/profile-file-api-consistency
- dev-fix/extension-render-idempotence
- dev-fix/html-attribute-escaping-and-merge
- dev-fix/strict-mode-block-style
- dev-fix/url-sanitization-whitespace-bypass
- dev-fix/paragraph-leading-whitespace
- dev-feature/line-comments
- dev-fix/inline-brace-comments
- dev-fix/attribute-source-order-v2
- dev-fix/autolink-attributes
- dev-fix/multiple-attribute-blocks
- dev-fix/attribute-edge-cases
- dev-fix/percent-in-quoted-values
- dev-fix/attribute-comment-handling
- dev-fix/attribute-source-order
- dev-fix/unquoted-attribute-value-validation
- dev-revert-105-fix/attribute-parser-dot-in-quoted-values
- dev-feature/table-header-equals-syntax
This package is auto-updated.
Last update: 2026-04-02 09:13:39 UTC
README
A PHP parser for Djot, a modern light markup language created by John MacFarlane (author of CommonMark/Pandoc).
Installation
composer require php-collective/djot
Quick Start
use Djot\DjotConverter; $converter = new DjotConverter(); $html = $converter->convert('Hello *world*!'); // Output: <p>Hello <strong>world</strong>!</p>
Features
- Block elements: Headings, paragraphs, code blocks, block quotes, lists, tables, divs, definition lists, line blocks
- Inline elements: Emphasis, strong, links, images, code, superscript, subscript, highlight, insert, delete
- Advanced: Footnotes, math expressions, symbols, block attributes, raw HTML blocks, comments
- Smart typography: Curly quotes, en/em dashes, ellipsis
- Multiple renderers: HTML, plain text, Markdown, ANSI terminal output
- Extensions: Built-in extensions for external links, TOC, heading permalinks, @mentions, autolinks, default attributes
- Extensible: Custom inline/block patterns, render events
- File support: Parse and convert files directly
Example
use Djot\DjotConverter; use Djot\Extension\ExternalLinksExtension; use Djot\Extension\DefaultAttributesExtension; $converter = new DjotConverter(); // Add extensions for common features $converter ->addExtension(new ExternalLinksExtension()) ->addExtension(new DefaultAttributesExtension([ 'table' => ['class' => 'table'], ])); $djot = <<<'DJOT' # Welcome This is _emphasized_ and *strong* text with a [link](https://example.com). | Name | Role | |-------|------------| | Alice | Developer | | Bob | Designer | > "Djot is a light markup syntax." ```php echo "Hello World"; DJOT; echo $converter->convert($djot);
Output:
<h1>Welcome</h1> <p>This is <em>emphasized</em> and <strong>strong</strong> text with a <a href="https://example.com" target="_blank" rel="noopener noreferrer">link</a>.</p> <table class="table"> <thead> <tr><th>Name</th><th>Role</th></tr> </thead> <tbody> <tr><td>Alice</td><td>Developer</td></tr> <tr><td>Bob</td><td>Designer</td></tr> </tbody> </table> <blockquote> <p>"Djot is a light markup syntax."</p> </blockquote> <pre><code class="language-php">echo "Hello World"; </code></pre>
Documentation
Full documentation is available at https://php-collective.github.io/djot-php/
- Getting Started - Installation and quick start
- Why Djot? - Comparison with Markdown
- Syntax Reference - Complete Djot syntax guide
- Extensions - Built-in extensions
- API Reference - Classes and methods
- Cookbook - Customization recipes
Demo
- Interactive Playground - Try djot-php in your browser
- Sandbox - Full-featured sandbox with all options
Security
When processing untrusted user input, enable safe mode for XSS protection:
$converter = new DjotConverter(safeMode: true); $html = $converter->convert($untrustedInput);
Safe mode automatically blocks dangerous URL schemes (javascript:, etc.), strips event handler attributes (onclick, etc.), and escapes raw HTML.
See Safe Mode for details and advanced configuration.
Implementations
- php-collective/symfony-djot - Symfony bundle with Twig filters, services, forms, and validation
- php-collective/wp-djot - WordPress plugin for Djot support
- dereuromark/cakephp-markup - CakePHP integration with Djot helper and view class
See Also
- Djot - Official Djot website with syntax reference and playground
- jgm/djot - Reference implementation in JavaScript by John MacFarlane
- JetBrains IDE support - Plugin for PhpStorm, IntelliJ IDEA, WebStorm, etc.
- djot-grammars - Syntax highlighting grammars (TextMate, highlight.js, Prism.js)