A PHP library to convert HTML, Markdown, and Plain Text into Atlassian Document Format (ADF) — compatible with Jira & Confluence.
- Recursive HTML parsing via DOM
- Headings, Paragraphs, Emphasis, Strong, Links, Lists, Code Blocks, Tables, Images
- Markdown-to-ADF using
league/commonmark
- Plain text support
- Pluggable converter architecture
- Composer-based install
- Testable, extensible & PSR-compliant
composer require your-vendor/html-to-adf
use HtmlToAdf\ConverterManager;
use HtmlToAdf\Converters\HtmlConverter;
use HtmlToAdf\Converters\MarkdownConverter;
use HtmlToAdf\Converters\PlainTextConverter;
$manager = new ConverterManager();
$manager->registerConverter(new HtmlConverter());
$manager->registerConverter(new MarkdownConverter());
$manager->registerConverter(new PlainTextConverter());
$html = '<h2>Hello</h2><p>This is a <strong>test</strong>.</p>';
$adf = $manager->convert('html', $html);
print_r($adf);
$markdown = "## Hello\nThis is a **test**.";
$adf = $manager->convert('markdown', $markdown);
print_r($adf);
$text = "Just a simple paragraph.";
$adf = $manager->convert('text', $text);
print_r($adf);
Input:
<p>Hello <strong>world</strong>!</p>
Output:
{
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{ "type": "text", "text": "Hello " },
{
"type": "text",
"text": "world",
"marks": [{ "type": "strong" }]
},
{ "type": "text", "text": "!" }
]
}
]
}
Component | Description |
---|---|
ConverterManager |
Manages format dispatching to converters |
ConverterInterface |
Interface for pluggable format converters |
HtmlConverter |
Parses DOM and builds ADF recursively |
MarkdownConverter |
Uses CommonMark, then delegates to HTML |
PlainTextConverter |
Wraps text in paragraph ADF structure |
AdfNodeBuilder |
(Optional) Helps build consistent ADF output |
Cem Açar
[email protected]
Licensed under the MIT License.