Skip to content

Commit 0ced7f2

Browse files
committed
Reverted serializeBlocksExternalHTML.ts
1 parent a6389c7 commit 0ced7f2

File tree

4 files changed

+36
-44
lines changed

4 files changed

+36
-44
lines changed

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

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

119119
const elementFragment = doc.createDocumentFragment();
120-
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-
143120
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-
}
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+
);
135+
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);
151139
}
152140

153-
addAttributesAndRemoveClasses(ret.dom.firstChild as HTMLElement);
141+
addAttributesAndRemoveClasses(ret.dom.firstChild! as HTMLElement);
154142
elementFragment.append(...Array.from(ret.dom.childNodes));
155143
} else {
156144
elementFragment.append(ret.dom);
@@ -167,6 +155,13 @@ function serializeBlock<
167155
ret.contentDOM.appendChild(ic);
168156
}
169157

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+
170165
if (listType) {
171166
if (fragment.lastChild?.nodeName !== listType) {
172167
const list = doc.createElement(listType);
@@ -177,9 +172,6 @@ function serializeBlock<
177172
fragment.append(list);
178173
}
179174
const li = doc.createElement("li");
180-
for (const attr of blockContentDataAttributes) {
181-
li.setAttribute(attr.name, attr.value);
182-
}
183175
li.append(elementFragment);
184176
fragment.lastChild!.appendChild(li);
185177
} 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 data-start="2">
5-
<p>Numbered List Item 1</p>
4+
<li>
5+
<p data-start="2">Numbered List Item 1</p>
66
</li>
77
</ol>
88
<ul>
9-
<li data-background-color="red">
10-
<p>Bullet List Item 1</p>
9+
<li>
10+
<p data-background-color="red">Bullet List Item 1</p>
1111
</li>
12-
<li data-checked="true">
13-
<input type="checkbox" checked="" />
12+
<li>
13+
<input type="checkbox" checked="" data-checked="true" />
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 data-checked="true">
23-
<input type="checkbox" checked="" />
22+
<li>
23+
<input type="checkbox" checked="" data-checked="true" />
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 data-checked="true">
19-
<input type="checkbox" checked="" />
18+
<li>
19+
<input type="checkbox" checked="" data-checked="true" />
2020
<p class="bn-inline-content">Check List Item 2</p>
2121
</li>
2222
</ul>

0 commit comments

Comments
 (0)