Skip to content

Commit a6275dd

Browse files
committed
fix(web): normalizer understands tiptap's checkbox list
1 parent 39efca7 commit a6275dd

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/web/__tests__/htmlNormalizer.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,20 @@ describe('htmlNormalizer', () => {
417417
});
418418
});
419419

420+
describe('TiptapCheckboxList', () => {
421+
test("tiptap's internal checkbox list structure gets correctly parsed", () => {
422+
expect(
423+
normalizeHtml(
424+
`<ul data-type="checkboxList"><li data-checked="true" data-type="checkboxItem"><label>` +
425+
`<input type="checkbox" checked="checked"><span></span></label><div><p>first</p></div></li>` +
426+
`<li data-checked="false" data-type="checkboxItem"><label><input type="checkbox"><span></span></label><div><p>second</p></div></li></ul>`
427+
)
428+
).toBe(
429+
'<ul data-type="checkbox"><li checked>first</li><li>second</li></ul>'
430+
);
431+
});
432+
});
433+
420434
describe('BrRemappings', () => {
421435
test('inline collapses around <br> stay flat', () => {
422436
expect(

src/web/normalization/htmlNormalizer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,15 @@ function emitAttributes(el: Element, name: string): string {
251251
);
252252
case 'ul': {
253253
const val = el.getAttribute('data-type');
254-
return val === 'checkbox' ? ' data-type="checkbox"' : '';
254+
return val === 'checkbox' || val === 'checkboxList'
255+
? ' data-type="checkbox"'
256+
: '';
255257
}
256258
case 'li':
257-
return el.hasAttribute('checked') ? ' checked' : '';
259+
const isChecked =
260+
el.hasAttribute('checked') ||
261+
el.getAttribute('data-checked') === 'true';
262+
return isChecked ? ' checked' : '';
258263
case 'mention':
259264
return (
260265
emitOneAttr(el, 'id') +

0 commit comments

Comments
 (0)