https://github.com/php-collective/djot-php
A PHP parser for Djot, a modern light markup language
https://github.com/php-collective/djot-php
djot language markdown markdown-language markup
Last synced: 3 months ago
JSON representation
A PHP parser for Djot, a modern light markup language
- Host: GitHub
- URL: https://github.com/php-collective/djot-php
- Owner: php-collective
- License: mit
- Created: 2025-11-27T11:54:20.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-12-21T11:34:14.000Z (6 months ago)
- Last Synced: 2025-12-23T03:09:16.128Z (6 months ago)
- Topics: djot, language, markdown, markdown-language, markup
- Language: PHP
- Homepage:
- Size: 621 KB
- Stars: 15
- Watchers: 0
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-djot - php-collective/djot-php - PHP implementation with extensions and security features. (Parsers & Libraries / PHP)
- fucking-awesome-php - Djot - A PHP parser for 🌎 [Djot](djot.net/), a modern light markup language (successor of Markdown). (Table of Contents / Markup and CSS)
- awesome-php - Djot - A PHP parser for [Djot](https://djot.net/), a modern light markup language (successor of Markdown). (Table of Contents / Markup and CSS)
README
# Djot PHP
[](https://github.com/php-collective/djot-php/actions)
[](https://codecov.io/gh/php-collective/djot-php)
[](https://packagist.org/packages/php-collective/djot)
[](https://packagist.org/packages/php-collective/djot)
[](https://phpstan.org/)
[](https://php.net)
[](LICENSE)
A PHP parser for [Djot](https://djot.net/), a modern light markup language created by John MacFarlane (author of CommonMark/Pandoc).
## Installation
```bash
composer require php-collective/djot
```
## Quick Start
```php
use Djot\DjotConverter;
$converter = new DjotConverter();
$html = $converter->convert('Hello *world*!');
// Output:
Hello world!
```
## 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
```php
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:
```html
Welcome
This is emphasized and strong text with a link.
NameRole
AliceDeveloper
BobDesigner
"Djot is a light markup syntax."
echo "Hello World";
```
## Documentation
Full documentation is available at **https://php-collective.github.io/djot-php/**
- [Getting Started](https://php-collective.github.io/djot-php/guide/) - Installation and quick start
- [Why Djot?](https://php-collective.github.io/djot-php/guide/why-djot) - Comparison with Markdown
- [Syntax Reference](https://php-collective.github.io/djot-php/guide/syntax) - Complete Djot syntax guide
- [Extensions](https://php-collective.github.io/djot-php/extensions/) - Built-in extensions
- [API Reference](https://php-collective.github.io/djot-php/reference/api) - Classes and methods
- [Cookbook](https://php-collective.github.io/djot-php/cookbook/) - Customization recipes
## Demo
- [Interactive Playground](https://php-collective.github.io/djot-php/playground) - Try djot-php in your browser
- [Sandbox](https://sandbox.dereuromark.de/sandbox/djot) - Full-featured sandbox with all options
## Security
When processing untrusted user input, enable safe mode for XSS protection:
```php
$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](https://php-collective.github.io/djot-php/guide/safe-mode) for details and advanced configuration.
## Implementations
- [php-collective/symfony-djot](https://github.com/php-collective/symfony-djot) - Symfony bundle with Twig filters, services, forms, and validation
- [php-collective/wp-djot](https://github.com/php-collective/wp-djot) - WordPress plugin for Djot support
- [dereuromark/cakephp-markup](https://github.com/dereuromark/cakephp-markup) - CakePHP integration with Djot helper and view class
## See Also
- [Djot](https://djot.net/) - Official Djot website with syntax reference and playground
- [jgm/djot](https://github.com/jgm/djot) - Reference implementation in JavaScript by John MacFarlane
- [JetBrains IDE support](https://github.com/php-collective/djot-intellij) - Plugin for PhpStorm, IntelliJ IDEA, WebStorm, etc.
- [djot-grammars](https://github.com/php-collective/djot-grammars) - Syntax highlighting grammars (TextMate, highlight.js, Prism.js)