|
| 1 | +<?php |
| 2 | + |
| 3 | +require 'vendor/autoload.php'; |
| 4 | + |
| 5 | +use HtmlToAdf\ConverterManager; |
| 6 | +use HtmlToAdf\Converters\HtmlConverter; |
| 7 | +use HtmlToAdf\Converters\MarkdownConverter; |
| 8 | +use HtmlToAdf\Converters\PlainTextConverter; |
| 9 | + |
| 10 | +// Initialize the ADF Converter Manager |
| 11 | +$manager = new ConverterManager(); |
| 12 | + |
| 13 | +// Register available converters |
| 14 | +$manager->registerConverter(new HtmlConverter()); |
| 15 | +$manager->registerConverter(new MarkdownConverter()); |
| 16 | +$manager->registerConverter(new PlainTextConverter()); |
| 17 | + |
| 18 | +/** |
| 19 | + * --------------------------- |
| 20 | + * EXAMPLE 1 — HTML Conversion |
| 21 | + * --------------------------- |
| 22 | + */ |
| 23 | +$html = <<<HTML |
| 24 | +<h1>Project Documentation</h1> |
| 25 | +<p><strong>Important details</strong>, <em>notes</em>, <del>invalid info</del>, and <code>code snippets</code>.</p> |
| 26 | +<ul> |
| 27 | + <li>Real-time data processing</li> |
| 28 | + <li>API integration |
| 29 | + <ul> |
| 30 | + <li>GET /api/items</li> |
| 31 | + <li>POST /api/items</li> |
| 32 | + </ul> |
| 33 | + </li> |
| 34 | + <li>Automated testing support</li> |
| 35 | +</ul> |
| 36 | +<ol> |
| 37 | + <li>Installation |
| 38 | + <ol> |
| 39 | + <li>Run <code>composer install</code></li> |
| 40 | + <li>Copy and configure <code>.env</code></li> |
| 41 | + </ol> |
| 42 | + </li> |
| 43 | +</ol> |
| 44 | +<blockquote><strong>Note:</strong> PHP 8.1 or above is required.</blockquote> |
| 45 | +<pre><code class="language-js">fetch("https://api.example.com/data") |
| 46 | + .then(response => response.json()) |
| 47 | + .then(data => console.log(data));</code></pre> |
| 48 | +<img src="https://example.com/image.jpg" alt="Diagram" /> |
| 49 | +<table> |
| 50 | + <thead> |
| 51 | + <tr><th>Name</th><th>Role</th><th>Active</th></tr> |
| 52 | + </thead> |
| 53 | + <tbody> |
| 54 | + <tr><td>Cem</td><td>Admin</td><td>✅</td></tr> |
| 55 | + <tr><td>Ece</td><td>Editor</td><td>❌</td></tr> |
| 56 | + </tbody> |
| 57 | +</table> |
| 58 | +HTML; |
| 59 | + |
| 60 | +echo "===== HTML to ADF =====\n"; |
| 61 | +$htmlAdf = $manager->convert('html', $html); |
| 62 | +echo json_encode($htmlAdf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); |
| 63 | +echo "\n\n"; |
| 64 | + |
| 65 | +/** |
| 66 | + * ------------------------------ |
| 67 | + * EXAMPLE 2 — Markdown Conversion |
| 68 | + * ------------------------------ |
| 69 | + */ |
| 70 | +$markdown = <<<MD |
| 71 | +# Markdown Example |
| 72 | +
|
| 73 | +**Bold**, _italic_, ~~strikethrough~~, and \`inline code\` |
| 74 | +
|
| 75 | +- List item 1 |
| 76 | +- List item 2 |
| 77 | + - Nested list |
| 78 | +
|
| 79 | +> This is a blockquote |
| 80 | +
|
| 81 | +\`\`\`php |
| 82 | +echo "Hello World!"; |
| 83 | +\`\`\` |
| 84 | +MD; |
| 85 | + |
| 86 | +echo "===== Markdown to ADF =====\n"; |
| 87 | +$markdownAdf = $manager->convert('markdown', $markdown); |
| 88 | +echo json_encode($markdownAdf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); |
| 89 | +echo "\n\n"; |
| 90 | + |
| 91 | + |
| 92 | +$text = "This is a simple plain text. It will be wrapped in a paragraph node."; |
| 93 | + |
| 94 | +echo "===== Plain Text to ADF =====\n"; |
| 95 | +$textAdf = $manager->convert('text', $text); |
| 96 | +echo json_encode($textAdf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); |
| 97 | +echo "\n"; |
0 commit comments