Create prosemirror structs and HTML conversion logic

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-03-26 18:54:42 +04:00
parent 339cc142b5
commit 79a4e7c781
6 changed files with 1953 additions and 0 deletions

95
pkg/prosemirror/testdata/document.html vendored Normal file
View File

@@ -0,0 +1,95 @@
<h1>Heading 1</h1>
<p>This is a paragraph <strong>with some bold</strong> and <em>some italic </em>and some <u>underlined text</u>.<br>It
contains a line break, and some <s>strikethrough.</s><br>There&#39;s some <code>inline code</code>. And a <a
href="https://getprobo.com" target="_blank" rel="noopener noreferrer nofollow">link</a></p>
<h2>Heading 2</h2>
<p>A simple paragraph.</p>
<pre><code>code block</code></pre>
<h3>Heading 3</h3>
<ul>
<li>
<p>ul <strong>list</strong> item 1</p>
</li>
<li>
<p>ul <em>list</em> item 2</p>
</li>
<li>
<p>ul <a href="https://google.com" target="_blank" rel="noopener noreferrer nofollow">list</a> item 3</p>
</li>
</ul>
<hr>
<ol>
<li>
<p>ol list <u>item</u> 1</p>
</li>
<li>
<p>ol list <code>item</code> 2</p>
</li>
<li>
<p>ol list <s>item</s> 3</p>
</li>
</ol>
<hr>
<blockquote>
<p>Blockquote<br>Line <strong>break</strong></p>
</blockquote>
<hr>
<table>
<tr>
<th>
<p>th 1</p>
</th>
<th>
<p>th 2</p>
</th>
<th>
<p>th 3</p>
</th>
<th style="min-width: 61px">
<p>th 4</p>
</th>
</tr>
<tr>
<td>
<p>td <em>11</em></p>
</td>
<td>
<p>td <strong>12</strong></p>
</td>
<td>
<p>td <s>13</s></p>
</td>
<td style="min-width: 61px">
<ul>
<li>
<p>1</p>
</li>
<li>
<p>2</p>
</li>
</ul>
</td>
</tr>
<tr>
<td>
<p>td <u>21</u></p>
</td>
<td>
<p>td <a href="https://example.org" target="_blank" rel="noopener noreferrer nofollow">22</a></p>
</td>
<td>
<p>td <code>23</code></p>
</td>
<td style="min-width: 61px">
<ol>
<li>
<p>A</p>
</li>
<li>
<p>B</p>
</li>
</ol>
</td>
</tr>
</table>
<p></p>

754
pkg/prosemirror/testdata/document.json vendored Normal file
View File

@@ -0,0 +1,754 @@
{
"type": "doc",
"content": [
{
"type": "heading",
"attrs": {
"level": 1
},
"content": [
{
"type": "text",
"text": "Heading 1"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "This is a paragraph "
},
{
"type": "text",
"marks": [
{
"type": "bold"
}
],
"text": "with some bold"
},
{
"type": "text",
"text": " and "
},
{
"type": "text",
"marks": [
{
"type": "italic"
}
],
"text": "some italic "
},
{
"type": "text",
"text": "and some "
},
{
"type": "text",
"marks": [
{
"type": "underline"
}
],
"text": "underlined text"
},
{
"type": "text",
"text": "."
},
{
"type": "hardBreak"
},
{
"type": "text",
"text": "It contains a line break, and some "
},
{
"type": "text",
"marks": [
{
"type": "strike"
}
],
"text": "strikethrough."
},
{
"type": "hardBreak"
},
{
"type": "text",
"text": "There's some "
},
{
"type": "text",
"marks": [
{
"type": "code"
}
],
"text": "inline code"
},
{
"type": "text",
"text": ". And a "
},
{
"type": "text",
"marks": [
{
"type": "link",
"attrs": {
"href": "https://getprobo.com",
"target": "_blank",
"rel": "noopener noreferrer nofollow",
"class": null,
"title": null
}
}
],
"text": "link"
}
]
},
{
"type": "heading",
"attrs": {
"level": 2
},
"content": [
{
"type": "text",
"text": "Heading 2"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "A simple paragraph."
}
]
},
{
"type": "codeBlock",
"attrs": {
"language": null
},
"content": [
{
"type": "text",
"text": "code block"
}
]
},
{
"type": "heading",
"attrs": {
"level": 3
},
"content": [
{
"type": "text",
"text": "Heading 3"
}
]
},
{
"type": "bulletList",
"content": [
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "ul "
},
{
"type": "text",
"marks": [
{
"type": "bold"
}
],
"text": "list"
},
{
"type": "text",
"text": " item 1"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "ul "
},
{
"type": "text",
"marks": [
{
"type": "italic"
}
],
"text": "list"
},
{
"type": "text",
"text": " item 2"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "ul "
},
{
"type": "text",
"marks": [
{
"type": "link",
"attrs": {
"href": "https://google.com",
"target": "_blank",
"rel": "noopener noreferrer nofollow",
"class": null,
"title": null
}
}
],
"text": "list"
},
{
"type": "text",
"text": " item 3"
}
]
}
]
}
]
},
{
"type": "horizontalRule"
},
{
"type": "orderedList",
"attrs": {
"start": 1,
"type": null
},
"content": [
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "ol list "
},
{
"type": "text",
"marks": [
{
"type": "underline"
}
],
"text": "item"
},
{
"type": "text",
"text": " 1"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "ol list "
},
{
"type": "text",
"marks": [
{
"type": "code"
}
],
"text": "item"
},
{
"type": "text",
"text": " 2"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "ol list "
},
{
"type": "text",
"marks": [
{
"type": "strike"
}
],
"text": "item"
},
{
"type": "text",
"text": " 3"
}
]
}
]
}
]
},
{
"type": "horizontalRule"
},
{
"type": "blockquote",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Blockquote"
},
{
"type": "hardBreak"
},
{
"type": "text",
"text": "Line "
},
{
"type": "text",
"marks": [
{
"type": "bold"
}
],
"text": "break"
}
]
}
]
},
{
"type": "horizontalRule"
},
{
"type": "table",
"content": [
{
"type": "tableRow",
"content": [
{
"type": "tableHeader",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "th 1"
}
]
}
]
},
{
"type": "tableHeader",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "th 2"
}
]
}
]
},
{
"type": "tableHeader",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "th 3"
}
]
}
]
},
{
"type": "tableHeader",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": [
61
]
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "th 4"
}
]
}
]
}
]
},
{
"type": "tableRow",
"content": [
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "td "
},
{
"type": "text",
"marks": [
{
"type": "italic"
}
],
"text": "11"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "td "
},
{
"type": "text",
"marks": [
{
"type": "bold"
}
],
"text": "12"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "td "
},
{
"type": "text",
"marks": [
{
"type": "strike"
}
],
"text": "13"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": [
61
]
},
"content": [
{
"type": "bulletList",
"content": [
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "1"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "2"
}
]
}
]
}
]
}
]
}
]
},
{
"type": "tableRow",
"content": [
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "td "
},
{
"type": "text",
"marks": [
{
"type": "underline"
}
],
"text": "21"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "td "
},
{
"type": "text",
"marks": [
{
"type": "link",
"attrs": {
"href": "https://example.org",
"target": "_blank",
"rel": "noopener noreferrer nofollow",
"class": null,
"title": null
}
}
],
"text": "22"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": null
},
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "td "
},
{
"type": "text",
"marks": [
{
"type": "code"
}
],
"text": "23"
}
]
}
]
},
{
"type": "tableCell",
"attrs": {
"colspan": 1,
"rowspan": 1,
"colwidth": [
61
]
},
"content": [
{
"type": "orderedList",
"attrs": {
"start": 1,
"type": null
},
"content": [
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "A"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "B"
}
]
}
]
}
]
}
]
}
]
}
]
},
{
"type": "paragraph"
}
]
}