Skip to content

Commit 1202d05

Browse files
committed
Fixed list item props in external HTML
1 parent 5a7a42b commit 1202d05

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,40 @@ function serializeBlock<
117117
].implementation.toExternalHTML({ ...block, props } as any, editor as any);
118118

119119
const elementFragment = doc.createDocumentFragment();
120-
if (ret.dom.classList.contains("bn-block-content")) {
121-
const blockContentDataAttributes = [
122-
...attrs,
123-
...Array.from(ret.dom.attributes),
124-
].filter(
125-
(attr) =>
126-
attr.name.startsWith("data") &&
127-
attr.name !== "data-content-type" &&
128-
attr.name !== "data-file-block" &&
129-
attr.name !== "data-node-view-wrapper" &&
130-
attr.name !== "data-node-type" &&
131-
attr.name !== "data-id" &&
132-
attr.name !== "data-index" &&
133-
attr.name !== "data-editable"
134-
);
135120

136-
// ret.dom = ret.dom.firstChild! as any;
137-
for (const attr of blockContentDataAttributes) {
138-
(ret.dom.firstChild! as HTMLElement).setAttribute(attr.name, attr.value);
121+
let listType = undefined;
122+
if (orderedListItemBlockTypes.has(block.type!)) {
123+
listType = "OL";
124+
} else if (unorderedListItemBlockTypes.has(block.type!)) {
125+
listType = "UL";
126+
}
127+
128+
const blockContentDataAttributes = [
129+
...attrs,
130+
...Array.from(ret.dom.attributes),
131+
].filter(
132+
(attr) =>
133+
attr.name.startsWith("data") &&
134+
attr.name !== "data-content-type" &&
135+
attr.name !== "data-file-block" &&
136+
attr.name !== "data-node-view-wrapper" &&
137+
attr.name !== "data-node-type" &&
138+
attr.name !== "data-id" &&
139+
attr.name !== "data-index" &&
140+
attr.name !== "data-editable"
141+
);
142+
143+
if (ret.dom.classList.contains("bn-block-content")) {
144+
if (!listType) {
145+
for (const attr of blockContentDataAttributes) {
146+
(ret.dom.firstChild! as HTMLElement).setAttribute(
147+
attr.name,
148+
attr.value
149+
);
150+
}
139151
}
140152

141-
addAttributesAndRemoveClasses(ret.dom.firstChild! as HTMLElement);
153+
addAttributesAndRemoveClasses(ret.dom.firstChild as HTMLElement);
142154
elementFragment.append(...Array.from(ret.dom.childNodes));
143155
} else {
144156
elementFragment.append(ret.dom);
@@ -155,13 +167,6 @@ function serializeBlock<
155167
ret.contentDOM.appendChild(ic);
156168
}
157169

158-
let listType = undefined;
159-
if (orderedListItemBlockTypes.has(block.type!)) {
160-
listType = "OL";
161-
} else if (unorderedListItemBlockTypes.has(block.type!)) {
162-
listType = "UL";
163-
}
164-
165170
if (listType) {
166171
if (fragment.lastChild?.nodeName !== listType) {
167172
const list = doc.createElement(listType);
@@ -172,6 +177,9 @@ function serializeBlock<
172177
fragment.append(list);
173178
}
174179
const li = doc.createElement("li");
180+
for (const attr of blockContentDataAttributes) {
181+
li.setAttribute(attr.name, attr.value);
182+
}
175183
li.append(elementFragment);
176184
fragment.lastChild!.appendChild(li);
177185
} else {

tests/src/unit/core/clipboard/copy/__snapshots__/text/html/basicBlocksWithProps.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<p data-text-color="red">Paragraph 1</p>
22
<h2 data-level="2">Heading 1</h2>
33
<ol start="2">
4-
<li>
5-
<p data-start="2">Numbered List Item 1</p>
4+
<li data-start="2">
5+
<p>Numbered List Item 1</p>
66
</li>
77
</ol>
88
<ul>
9-
<li>
10-
<p data-background-color="red">Bullet List Item 1</p>
9+
<li data-background-color="red">
10+
<p>Bullet List Item 1</p>
1111
</li>
12-
<li>
13-
<input type="checkbox" checked="" data-checked="true" />
12+
<li data-checked="true">
13+
<input type="checkbox" checked="" />
1414
<p class="bn-inline-content">Check List Item 1</p>
1515
</li>
1616
</ul>

tests/src/unit/core/formatConversion/export/__snapshots__/html/lists/basic.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<input type="checkbox" />
2020
<p class="bn-inline-content">Check List Item 1</p>
2121
</li>
22-
<li>
23-
<input type="checkbox" checked="" data-checked="true" />
22+
<li data-checked="true">
23+
<input type="checkbox" checked="" />
2424
<p class="bn-inline-content">Check List Item 2</p>
2525
</li>
2626
</ul>

tests/src/unit/core/formatConversion/export/__snapshots__/html/lists/nested.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<input type="checkbox" />
1616
<p class="bn-inline-content">Check List Item 1</p>
1717
</li>
18-
<li>
19-
<input type="checkbox" checked="" data-checked="true" />
18+
<li data-checked="true">
19+
<input type="checkbox" checked="" />
2020
<p class="bn-inline-content">Check List Item 2</p>
2121
</li>
2222
</ul>

0 commit comments

Comments
 (0)