Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,34 @@ function serializeBlock<
}
}

if (ret.contentDOM && block.content) {
const ic = serializeInlineContentExternalHTML(
editor,
block.content as any, // TODO
serializer,
{ ...options, blockType: block.type },
);
if (ret.contentDOM) {
if (block.content) {
const ic = serializeInlineContentExternalHTML(
editor,
block.content as any, // TODO
serializer,
{ ...options, blockType: block.type },
);

ret.contentDOM.appendChild(ic);
ret.contentDOM.appendChild(ic);
}

// Blocks with empty inline content (e.g. an empty paragraph) serialize to
// an element with no children (e.g. `<p></p>`), which is ignored when the
// HTML is parsed back into blocks. To make these blocks survive such a
// round trip, we fill their content with a non-breaking space.
//
// Only applies to blocks that hold inline content: containers (columns,
// tables) fill their `contentDOM` with child blocks later on, and code
// blocks would turn the placeholder into literal content.
const blockNodeType = editor.pmSchema.nodes[block.type as any];
if (
blockNodeType?.inlineContent &&
!blockNodeType.spec.code &&
ret.contentDOM.childNodes.length === 0
) {
ret.contentDOM.appendChild(doc.createTextNode(" "));
}
}

let listType = undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="bn-block-group" data-node-type="blockGroup">
<div class="bn-block-outer" data-node-type="blockOuter" data-id="1">
<div class="bn-block" data-node-type="blockContainer" data-id="1">
<div class="bn-block-content" data-content-type="paragraph">
<p class="bn-inline-content">Before</p>
</div>
</div>
</div>
<div class="bn-block-outer" data-node-type="blockOuter" data-id="2">
<div class="bn-block" data-node-type="blockContainer" data-id="2">
<div class="bn-block-content" data-content-type="paragraph">
<p class="bn-inline-content">
<span class="ProseMirror-trailingBreak" style="display: inline-block;"></span>
</p>
</div>
</div>
</div>
<div class="bn-block-outer" data-node-type="blockOuter" data-id="3">
<div class="bn-block" data-node-type="blockContainer" data-id="3">
<div class="bn-block-content" data-content-type="paragraph">
<p class="bn-inline-content">After</p>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ <h2 style="background-color: rgb(221, 235, 241); color: rgb(223, 171, 1); text-a
>Paragraph</p>
<ul>
<li data-nesting-level="1">
<p class="bn-inline-content"></p>
<p class="bn-inline-content">&nbsp;</p>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p></p>
<p>&nbsp;</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>Before</p>
<p>&nbsp;</p>
<p>After</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Before



After
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"attrs": {
"id": "1",
},
"content": [
{
"attrs": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"content": [
{
"text": "Before",
"type": "text",
},
],
"type": "paragraph",
},
],
"type": "blockContainer",
},
{
"attrs": {
"id": "2",
},
"content": [
{
"attrs": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"type": "paragraph",
},
],
"type": "blockContainer",
},
{
"attrs": {
"id": "3",
},
"content": [
{
"attrs": {
"backgroundColor": "default",
"textAlignment": "left",
"textColor": "default",
},
"content": [
{
"text": "After",
"type": "text",
},
],
"type": "paragraph",
},
],
"type": "blockContainer",
},
]
19 changes: 19 additions & 0 deletions tests/src/unit/core/formatConversion/export/exportTestInstances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ export const exportTestInstancesBlockNoteHTML: TestInstance<
},
executeTest: testExportBlockNoteHTML,
},
{
testCase: {
name: "paragraph/emptyBetween",
content: [
{
type: "paragraph",
content: "Before",
},
{
type: "paragraph",
},
{
type: "paragraph",
content: "After",
},
],
},
executeTest: testExportBlockNoteHTML,
},
{
testCase: {
name: "paragraph/basic",
Expand Down
Loading