xen3r0 / adf-converter
A PHP toolkit to parse the Atlassian Document Format (ADF) and export it to HTML or Markdown
Requires
- php: ^8.2
- ext-dom: *
- ext-json: *
- league/commonmark: ^2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.85
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^10.0
README
A PHP toolkit to parse the Atlassian Document Format (ADF) — the rich-text format used by Jira and Confluence — and convert it to and from HTML and Markdown.
It parses any of the three formats into a typed node tree (an AST) and exports that tree back out, so every combination below is supported:
| From ↓ / To → | ADF (JSON) | HTML | Markdown |
|---|---|---|---|
| ADF | — | ✅ | ✅ |
| HTML | ✅ | ✅ | ✅ |
| Markdown | ✅ | ✅ | ✅ |
Requirements
- PHP >= 8.2
- Extensions:
ext-dom,ext-json
Installation
composer require xen3r0/adf-converter
Quick start
Convert an ADF document (for example the body you get back from the Jira API)
to HTML:
use Xen3r0\Adf\Parser\Adf\AdfParser; use Xen3r0\Adf\Exporter\Html\HtmlExporter; $adf = '{"version":1,"type":"doc","content":[ {"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Hello"}]}, {"type":"paragraph","content":[{"type":"text","text":"world"}]} ]}'; $document = (new AdfParser())->parse($adf); echo (new HtmlExporter())->export($document); // <h1>Hello</h1><p>world</p>
Turn user-written Markdown into an ADF document ready to send to Jira:
use Xen3r0\Adf\Parser\Markdown\MarkdownParser; $document = (new MarkdownParser())->parse("# Title\n\nsome **bold** text"); echo json_encode($document); // valid ADF JSON
Documentation
- Getting started — installation and the core flow
- Parsing — the ADF, HTML and Markdown parsers
- Exporting — the HTML and Markdown exporters, and the AST
- Supported elements — node and mark reference
- Security — how untrusted input is made safe
- Development — running the tests, linters and CI locally
Security
All exported HTML and Markdown is hardened against XSS: dangerous URL schemes
(javascript:, data:, …) are stripped from links, and text content is
escaped. See docs/security.md for details. To report a
vulnerability, please open a security advisory.
License
Released under the MIT License. Copyright © Manuel Santisteban.