Skip to content

Commit

Permalink
Merge pull request #3591 from depressedX/main
Browse files Browse the repository at this point in the history
Fix @udecode/plate-markdown deserializing list with indented block element
  • Loading branch information
zbeyens authored Sep 29, 2024
2 parents 898c967 + 40cd0d7 commit 2f74e50
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/few-pans-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-markdown': patch
---

Fix @udecode/plate-markdown deserializing list with indented block element
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,63 @@ describe('deserializeMdIndentList', () => {

expect(deserializeMd(editor, input)).toEqual(output);
});

it('should deserialize list with indented block element', () => {
const input = `
- 1
- 2
- 2.1
\`\`\`
2.2 code
\`\`\`
`.trim();
const output = [
{
children: [
{
text: '1',
},
],
indent: 1,
listStyleType: 'disc',
type: 'p',
},
{
children: [
{
text: '2',
},
],
indent: 1,
listStyleType: 'disc',
type: 'p',
},
{
children: [
{
text: '2.1',
},
],
indent: 2,
listStyleType: 'disc',
type: 'p',
},
{
children: [
{
children: [
{
text: '2.2 code',
},
],
type: 'code_line',
},
],
indent: 2,
type: 'code_block',
},
];

expect(deserializeMd(editor, input)).toEqual(output);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { TDescendant, TElement, TText } from '@udecode/plate-common';
import type { MdastNode, RemarkElementRules } from './types';

import { remarkTransformElementChildren } from './remarkTransformElementChildren';
import { remarkTransformNode } from './remarkTransformNode';

// FIXME: underline, subscript superscript not yet supported by remark-slate
export const remarkDefaultElementRules: RemarkElementRules = {
Expand Down Expand Up @@ -82,7 +83,21 @@ export const remarkDefaultElementRules: RemarkElementRules = {
});

subLists.forEach((subList) => {
parseListItems(subList, listItems, indent + 1);
if (subList.type === 'list') {
parseListItems(subList, listItems, indent + 1);
} else {
const result = remarkTransformNode(subList, options) as
| TElement
| TElement[];

if (Array.isArray(result)) {
listItems.push(
...result.map((v) => ({ ...v, indent: indent + 1 }))
);
} else {
listItems.push({ ...result, indent: indent + 1 });
}
}
});
});

Expand Down

0 comments on commit 2f74e50

Please sign in to comment.