@thomasjahoda-forks/tiptap-extension-list 3.0.7 → 3.18.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bullet-list/index.cjs +19 -0
- package/dist/bullet-list/index.cjs.map +1 -1
- package/dist/bullet-list/index.js +19 -0
- package/dist/bullet-list/index.js.map +1 -1
- package/dist/index.cjs +413 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +422 -8
- package/dist/index.js.map +1 -1
- package/dist/item/index.cjs +61 -0
- package/dist/item/index.cjs.map +1 -1
- package/dist/item/index.js +62 -1
- package/dist/item/index.js.map +1 -1
- package/dist/keymap/index.d.cts +2 -2
- package/dist/keymap/index.d.ts +2 -2
- package/dist/kit/index.cjs +413 -5
- package/dist/kit/index.cjs.map +1 -1
- package/dist/kit/index.js +422 -8
- package/dist/kit/index.js.map +1 -1
- package/dist/ordered-list/index.cjs +189 -0
- package/dist/ordered-list/index.cjs.map +1 -1
- package/dist/ordered-list/index.js +189 -0
- package/dist/ordered-list/index.js.map +1 -1
- package/dist/task-item/index.cjs +53 -5
- package/dist/task-item/index.cjs.map +1 -1
- package/dist/task-item/index.d.cts +1 -1
- package/dist/task-item/index.d.ts +1 -1
- package/dist/task-item/index.js +60 -6
- package/dist/task-item/index.js.map +1 -1
- package/dist/task-list/index.cjs +91 -0
- package/dist/task-list/index.cjs.map +1 -1
- package/dist/task-list/index.js +92 -1
- package/dist/task-list/index.js.map +1 -1
- package/package.json +5 -5
- package/src/bullet-list/bullet-list.ts +25 -0
- package/src/item/list-item.ts +82 -1
- package/src/ordered-list/ordered-list.ts +72 -0
- package/src/ordered-list/utils.ts +234 -0
- package/src/task-item/task-item.ts +87 -8
- package/src/task-list/task-list.ts +105 -1
|
@@ -50,6 +50,25 @@ var BulletList = import_core.Node.create({
|
|
|
50
50
|
renderHTML({ HTMLAttributes }) {
|
|
51
51
|
return ["ul", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
52
52
|
},
|
|
53
|
+
markdownTokenName: "list",
|
|
54
|
+
parseMarkdown: (token, helpers) => {
|
|
55
|
+
if (token.type !== "list" || token.ordered) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
type: "bulletList",
|
|
60
|
+
content: token.items ? helpers.parseChildren(token.items) : []
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
renderMarkdown: (node, h) => {
|
|
64
|
+
if (!node.content) {
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
return h.renderChildren(node.content, "\n");
|
|
68
|
+
},
|
|
69
|
+
markdownOptions: {
|
|
70
|
+
indentsContent: true
|
|
71
|
+
},
|
|
53
72
|
addCommands() {
|
|
54
73
|
return {
|
|
55
74
|
toggleBulletList: () => ({ commands, chain }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bullet-list/index.ts","../../src/bullet-list/bullet-list.ts"],"sourcesContent":["export * from './bullet-list.js'\n","import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface BulletListOptions {\n /**\n * The node name for the list items\n * @default 'listItem'\n * @example 'paragraph'\n */\n itemTypeName: string\n\n /**\n * HTML attributes to add to the bullet list element\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting the list\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting the list\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n bulletList: {\n /**\n * Toggle a bullet list\n */\n toggleBulletList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a bullet list to a dash or asterisk.\n */\nexport const bulletListInputRegex = /^\\s*([-+*])\\s$/\n\n/**\n * This extension allows you to create bullet lists.\n * This requires the ListItem extension\n * @see https://tiptap.dev/api/nodes/bullet-list\n * @see https://tiptap.dev/api/nodes/list-item.\n */\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [{ tag: 'ul' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList:\n () =>\n ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain()\n .toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n .updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName))\n .run()\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => {\n return this.editor.getAttributes(TextStyleName)\n },\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyD;AAEzD,IAAM,eAAe;AACrB,IAAM,gBAAgB;AA8Cf,IAAM,uBAAuB;AAQ7B,IAAM,aAAa,iBAAK,OAA0B;AAAA,EACvD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,cAAc;AAAA,MACd,gBAAgB,CA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IACH;AACA,WAAO,CAAC,SAAS;AAAA,EACnB;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/bullet-list/index.ts","../../src/bullet-list/bullet-list.ts"],"sourcesContent":["export * from './bullet-list.js'\n","import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface BulletListOptions {\n /**\n * The node name for the list items\n * @default 'listItem'\n * @example 'paragraph'\n */\n itemTypeName: string\n\n /**\n * HTML attributes to add to the bullet list element\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting the list\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting the list\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n bulletList: {\n /**\n * Toggle a bullet list\n */\n toggleBulletList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a bullet list to a dash or asterisk.\n */\nexport const bulletListInputRegex = /^\\s*([-+*])\\s$/\n\n/**\n * This extension allows you to create bullet lists.\n * This requires the ListItem extension\n * @see https://tiptap.dev/api/nodes/bullet-list\n * @see https://tiptap.dev/api/nodes/list-item.\n */\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [{ tag: 'ul' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n markdownTokenName: 'list',\n\n parseMarkdown: (token, helpers) => {\n if (token.type !== 'list' || (token as any).ordered) {\n return []\n }\n\n return {\n type: 'bulletList',\n content: token.items ? helpers.parseChildren(token.items) : [],\n }\n },\n\n renderMarkdown: (node, h) => {\n if (!node.content) {\n return ''\n }\n\n return h.renderChildren(node.content, '\\n')\n },\n\n markdownOptions: {\n indentsContent: true,\n },\n\n addCommands() {\n return {\n toggleBulletList:\n () =>\n ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain()\n .toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n .updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName))\n .run()\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => {\n return this.editor.getAttributes(TextStyleName)\n },\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyD;AAEzD,IAAM,eAAe;AACrB,IAAM,gBAAgB;AA8Cf,IAAM,uBAAuB;AAQ7B,IAAM,aAAa,iBAAK,OAA0B;AAAA,EACvD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,cAAc;AAAA,MACd,gBAAgB,CAAC;AAAA,MACjB,WAAW;AAAA,MACX,gBAAgB;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,EAEP,UAAU;AACR,WAAO,GAAG,KAAK,QAAQ,YAAY;AAAA,EACrC;AAAA,EAEA,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,UAAM,6BAAgB,KAAK,Q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AA,QACxB,gBAAgB,KAAK,QAAQ;AAAA,QAC7B,eAAe,MAAM;AACnB,iBAAO,KAAK,OAAO,cAAc,aAAa;AAAA,QAChD;AAAA,QACA,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AACA,WAAO,CAAC,SAAS;AAAA,EACnB;AACF,CAAC;","names":[]}
|
|
@@ -23,6 +23,25 @@ var BulletList = Node.create({
|
|
|
23
23
|
renderHTML({ HTMLAttributes }) {
|
|
24
24
|
return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
25
25
|
},
|
|
26
|
+
markdownTokenName: "list",
|
|
27
|
+
parseMarkdown: (token, helpers) => {
|
|
28
|
+
if (token.type !== "list" || token.ordered) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
type: "bulletList",
|
|
33
|
+
content: token.items ? helpers.parseChildren(token.items) : []
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
renderMarkdown: (node, h) => {
|
|
37
|
+
if (!node.content) {
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
return h.renderChildren(node.content, "\n");
|
|
41
|
+
},
|
|
42
|
+
markdownOptions: {
|
|
43
|
+
indentsContent: true
|
|
44
|
+
},
|
|
26
45
|
addCommands() {
|
|
27
46
|
return {
|
|
28
47
|
toggleBulletList: () => ({ commands, chain }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bullet-list/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface BulletListOptions {\n /**\n * The node name for the list items\n * @default 'listItem'\n * @example 'paragraph'\n */\n itemTypeName: string\n\n /**\n * HTML attributes to add to the bullet list element\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting the list\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting the list\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n bulletList: {\n /**\n * Toggle a bullet list\n */\n toggleBulletList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a bullet list to a dash or asterisk.\n */\nexport const bulletListInputRegex = /^\\s*([-+*])\\s$/\n\n/**\n * This extension allows you to create bullet lists.\n * This requires the ListItem extension\n * @see https://tiptap.dev/api/nodes/bullet-list\n * @see https://tiptap.dev/api/nodes/list-item.\n */\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [{ tag: 'ul' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList:\n () =>\n ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain()\n .toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n .updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName))\n .run()\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => {\n return this.editor.getAttributes(TextStyleName)\n },\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n"],"mappings":";AAAA,SA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AAA,QACN,MAAM,KAAK;AAAA,QACX,WAAW,KAAK,QAAQ;AAAA,QACxB,gBAAgB,KAAK,QAAQ;AAAA,QAC7B,eAAe,MAAM;AACnB,iBAAO,KAAK,OAAO,cAAc,aAAa;AAAA,QAChD;AAAA,QACA,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AACA,WAAO,CAAC,SAAS;AAAA,EACnB;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/bullet-list/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface BulletListOptions {\n /**\n * The node name for the list items\n * @default 'listItem'\n * @example 'paragraph'\n */\n itemTypeName: string\n\n /**\n * HTML attributes to add to the bullet list element\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting the list\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting the list\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n bulletList: {\n /**\n * Toggle a bullet list\n */\n toggleBulletList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a bullet list to a dash or asterisk.\n */\nexport const bulletListInputRegex = /^\\s*([-+*])\\s$/\n\n/**\n * This extension allows you to create bullet lists.\n * This requires the ListItem extension\n * @see https://tiptap.dev/api/nodes/bullet-list\n * @see https://tiptap.dev/api/nodes/list-item.\n */\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [{ tag: 'ul' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n markdownTokenName: 'list',\n\n parseMarkdown: (token, helpers) => {\n if (token.type !== 'list' || (token as any).ordered) {\n return []\n }\n\n return {\n type: 'bulletList',\n content: token.items ? helpers.parseChildren(token.items) : [],\n }\n },\n\n renderMarkdown: (node, h) => {\n if (!node.content) {\n return ''\n }\n\n return h.renderChildren(node.content, '\\n')\n },\n\n markdownOptions: {\n indentsContent: true,\n },\n\n addCommands() {\n return {\n toggleBulletList:\n () =>\n ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain()\n .toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n .updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName))\n .run()\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => {\n return this.editor.getAttributes(TextStyleName)\n },\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB,MAAM,yBAAyB;AAEzD,IAAM,eAAe;AACrB,IAAM,gBAAgB;AA8Cf,IAAM,uBAAuB;AAQ7B,IAAM,aAAa,KAAK,OAA0B;AAAA,EACvD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,cAAc;AAAA,MACd,gBAAgB,CAAC;AAAA,MACjB,WAAW;AAAA,MACX,gBAAgB;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,EAEP,UAAU;AACR,WAAO,GAAG,KAAK,QAAQ,YAAY;AAAA,EACrC;AAAA,EAEA,YAAY;A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Q,aAAa,KAAK,QAAQ,gBAAgB;AACzD,kBAAY,kBAAkB;AAAA,QAC5B,MAAM;AAAA,QACN,MAAM,KAAK;AAAA,QACX,WAAW,KAAK,QAAQ;AAAA,QACxB,gBAAgB,KAAK,QAAQ;AAAA,QAC7B,eAAe,MAAM;AACnB,iBAAO,KAAK,OAAO,cAAc,aAAa;AAAA,QAChD;AAAA,QACA,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AACA,WAAO,CAAC,SAAS;AAAA,EACnB;AACF,CAAC;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -59,6 +59,25 @@ var BulletList = import_core.Node.create({
|
|
|
59
59
|
renderHTML({ HTMLAttributes }) {
|
|
60
60
|
return ["ul", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
61
61
|
},
|
|
62
|
+
markdownTokenName: "list",
|
|
63
|
+
parseMarkdown: (token, helpers) => {
|
|
64
|
+
if (token.type !== "list" || token.ordered) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
type: "bulletList",
|
|
69
|
+
content: token.items ? helpers.parseChildren(token.items) : []
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
renderMarkdown: (node, h) => {
|
|
73
|
+
if (!node.content) {
|
|
74
|
+
return "";
|
|
75
|
+
}
|
|
76
|
+
return h.renderChildren(node.content, "\n");
|
|
77
|
+
},
|
|
78
|
+
markdownOptions: {
|
|
79
|
+
indentsContent: true
|
|
80
|
+
},
|
|
62
81
|
addCommands() {
|
|
63
82
|
return {
|
|
64
83
|
toggleBulletList: () => ({ commands, chain }) => {
|
|
@@ -118,6 +137,67 @@ var ListItem = import_core2.Node.create({
|
|
|
118
137
|
renderHTML({ HTMLAttributes }) {
|
|
119
138
|
return ["li", (0, import_core2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
120
139
|
},
|
|
140
|
+
markdownTokenName: "list_item",
|
|
141
|
+
parseMarkdown: (token, helpers) => {
|
|
142
|
+
if (token.type !== "list_item") {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
let content = [];
|
|
146
|
+
if (token.tokens && token.tokens.length > 0) {
|
|
147
|
+
const hasParagraphTokens = token.tokens.some((t) => t.type === "paragraph");
|
|
148
|
+
if (hasParagraphTokens) {
|
|
149
|
+
content = helpers.parseChildren(token.tokens);
|
|
150
|
+
} else {
|
|
151
|
+
const firstToken = token.tokens[0];
|
|
152
|
+
if (firstToken && firstToken.type === "text" && firstToken.tokens && firstToken.tokens.length > 0) {
|
|
153
|
+
const inlineContent = helpers.parseInline(firstToken.tokens);
|
|
154
|
+
content = [
|
|
155
|
+
{
|
|
156
|
+
type: "paragraph",
|
|
157
|
+
content: inlineContent
|
|
158
|
+
}
|
|
159
|
+
];
|
|
160
|
+
if (token.tokens.length > 1) {
|
|
161
|
+
const remainingTokens = token.tokens.slice(1);
|
|
162
|
+
const additionalContent = helpers.parseChildren(remainingTokens);
|
|
163
|
+
content.push(...additionalContent);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
content = helpers.parseChildren(token.tokens);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (content.length === 0) {
|
|
171
|
+
content = [
|
|
172
|
+
{
|
|
173
|
+
type: "paragraph",
|
|
174
|
+
content: []
|
|
175
|
+
}
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
type: "listItem",
|
|
180
|
+
content
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
renderMarkdown: (node, h, ctx) => {
|
|
184
|
+
return (0, import_core2.renderNestedMarkdownContent)(
|
|
185
|
+
node,
|
|
186
|
+
h,
|
|
187
|
+
(context) => {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
if (context.parentType === "bulletList") {
|
|
190
|
+
return "- ";
|
|
191
|
+
}
|
|
192
|
+
if (context.parentType === "orderedList") {
|
|
193
|
+
const start = ((_b = (_a = context.meta) == null ? void 0 : _a.parentAttrs) == null ? void 0 : _b.start) || 1;
|
|
194
|
+
return `${start + context.index}. `;
|
|
195
|
+
}
|
|
196
|
+
return "- ";
|
|
197
|
+
},
|
|
198
|
+
ctx
|
|
199
|
+
);
|
|
200
|
+
},
|
|
121
201
|
addKeyboardShortcuts() {
|
|
122
202
|
return {
|
|
123
203
|
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
@@ -408,6 +488,138 @@ var import_core12 = require("@tiptap/core");
|
|
|
408
488
|
|
|
409
489
|
// src/ordered-list/ordered-list.ts
|
|
410
490
|
var import_core9 = require("@tiptap/core");
|
|
491
|
+
|
|
492
|
+
// src/ordered-list/utils.ts
|
|
493
|
+
var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/;
|
|
494
|
+
var INDENTED_LINE_REGEX = /^\s/;
|
|
495
|
+
function collectOrderedListItems(lines) {
|
|
496
|
+
const listItems = [];
|
|
497
|
+
let currentLineIndex = 0;
|
|
498
|
+
let consumed = 0;
|
|
499
|
+
while (currentLineIndex < lines.length) {
|
|
500
|
+
const line = lines[currentLineIndex];
|
|
501
|
+
const match = line.match(ORDERED_LIST_ITEM_REGEX);
|
|
502
|
+
if (!match) {
|
|
503
|
+
break;
|
|
504
|
+
}
|
|
505
|
+
const [, indent, number, content] = match;
|
|
506
|
+
const indentLevel = indent.length;
|
|
507
|
+
let itemContent = content;
|
|
508
|
+
let nextLineIndex = currentLineIndex + 1;
|
|
509
|
+
const itemLines = [line];
|
|
510
|
+
while (nextLineIndex < lines.length) {
|
|
511
|
+
const nextLine = lines[nextLineIndex];
|
|
512
|
+
const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX);
|
|
513
|
+
if (nextMatch) {
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
if (nextLine.trim() === "") {
|
|
517
|
+
itemLines.push(nextLine);
|
|
518
|
+
itemContent += "\n";
|
|
519
|
+
nextLineIndex += 1;
|
|
520
|
+
} else if (nextLine.match(INDENTED_LINE_REGEX)) {
|
|
521
|
+
itemLines.push(nextLine);
|
|
522
|
+
itemContent += `
|
|
523
|
+
${nextLine.slice(indentLevel + 2)}`;
|
|
524
|
+
nextLineIndex += 1;
|
|
525
|
+
} else {
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
listItems.push({
|
|
530
|
+
indent: indentLevel,
|
|
531
|
+
number: parseInt(number, 10),
|
|
532
|
+
content: itemContent.trim(),
|
|
533
|
+
raw: itemLines.join("\n")
|
|
534
|
+
});
|
|
535
|
+
consumed = nextLineIndex;
|
|
536
|
+
currentLineIndex = nextLineIndex;
|
|
537
|
+
}
|
|
538
|
+
return [listItems, consumed];
|
|
539
|
+
}
|
|
540
|
+
function buildNestedStructure(items, baseIndent, lexer) {
|
|
541
|
+
var _a;
|
|
542
|
+
const result = [];
|
|
543
|
+
let currentIndex = 0;
|
|
544
|
+
while (currentIndex < items.length) {
|
|
545
|
+
const item = items[currentIndex];
|
|
546
|
+
if (item.indent === baseIndent) {
|
|
547
|
+
const contentLines = item.content.split("\n");
|
|
548
|
+
const mainText = ((_a = contentLines[0]) == null ? void 0 : _a.trim()) || "";
|
|
549
|
+
const tokens = [];
|
|
550
|
+
if (mainText) {
|
|
551
|
+
tokens.push({
|
|
552
|
+
type: "paragraph",
|
|
553
|
+
raw: mainText,
|
|
554
|
+
tokens: lexer.inlineTokens(mainText)
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
const additionalContent = contentLines.slice(1).join("\n").trim();
|
|
558
|
+
if (additionalContent) {
|
|
559
|
+
const blockTokens = lexer.blockTokens(additionalContent);
|
|
560
|
+
tokens.push(...blockTokens);
|
|
561
|
+
}
|
|
562
|
+
let lookAheadIndex = currentIndex + 1;
|
|
563
|
+
const nestedItems = [];
|
|
564
|
+
while (lookAheadIndex < items.length && items[lookAheadIndex].indent > baseIndent) {
|
|
565
|
+
nestedItems.push(items[lookAheadIndex]);
|
|
566
|
+
lookAheadIndex += 1;
|
|
567
|
+
}
|
|
568
|
+
if (nestedItems.length > 0) {
|
|
569
|
+
const nextIndent = Math.min(...nestedItems.map((nestedItem) => nestedItem.indent));
|
|
570
|
+
const nestedListItems = buildNestedStructure(nestedItems, nextIndent, lexer);
|
|
571
|
+
tokens.push({
|
|
572
|
+
type: "list",
|
|
573
|
+
ordered: true,
|
|
574
|
+
start: nestedItems[0].number,
|
|
575
|
+
items: nestedListItems,
|
|
576
|
+
raw: nestedItems.map((nestedItem) => nestedItem.raw).join("\n")
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
result.push({
|
|
580
|
+
type: "list_item",
|
|
581
|
+
raw: item.raw,
|
|
582
|
+
tokens
|
|
583
|
+
});
|
|
584
|
+
currentIndex = lookAheadIndex;
|
|
585
|
+
} else {
|
|
586
|
+
currentIndex += 1;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return result;
|
|
590
|
+
}
|
|
591
|
+
function parseListItems(items, helpers) {
|
|
592
|
+
return items.map((item) => {
|
|
593
|
+
if (item.type !== "list_item") {
|
|
594
|
+
return helpers.parseChildren([item])[0];
|
|
595
|
+
}
|
|
596
|
+
const content = [];
|
|
597
|
+
if (item.tokens && item.tokens.length > 0) {
|
|
598
|
+
item.tokens.forEach((itemToken) => {
|
|
599
|
+
if (itemToken.type === "paragraph" || itemToken.type === "list" || itemToken.type === "blockquote" || itemToken.type === "code") {
|
|
600
|
+
content.push(...helpers.parseChildren([itemToken]));
|
|
601
|
+
} else if (itemToken.type === "text" && itemToken.tokens) {
|
|
602
|
+
const inlineContent = helpers.parseChildren([itemToken]);
|
|
603
|
+
content.push({
|
|
604
|
+
type: "paragraph",
|
|
605
|
+
content: inlineContent
|
|
606
|
+
});
|
|
607
|
+
} else {
|
|
608
|
+
const parsed = helpers.parseChildren([itemToken]);
|
|
609
|
+
if (parsed.length > 0) {
|
|
610
|
+
content.push(...parsed);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
return {
|
|
616
|
+
type: "listItem",
|
|
617
|
+
content
|
|
618
|
+
};
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/ordered-list/ordered-list.ts
|
|
411
623
|
var ListItemName2 = "listItem";
|
|
412
624
|
var TextStyleName2 = "textStyle";
|
|
413
625
|
var orderedListInputRegex = /^(\d+)\.\s$/;
|
|
@@ -450,6 +662,63 @@ var OrderedList = import_core9.Node.create({
|
|
|
450
662
|
const { start, ...attributesWithoutStart } = HTMLAttributes;
|
|
451
663
|
return start === 1 ? ["ol", (0, import_core9.mergeAttributes)(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", (0, import_core9.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
452
664
|
},
|
|
665
|
+
markdownTokenName: "list",
|
|
666
|
+
parseMarkdown: (token, helpers) => {
|
|
667
|
+
if (token.type !== "list" || !token.ordered) {
|
|
668
|
+
return [];
|
|
669
|
+
}
|
|
670
|
+
const startValue = token.start || 1;
|
|
671
|
+
const content = token.items ? parseListItems(token.items, helpers) : [];
|
|
672
|
+
if (startValue !== 1) {
|
|
673
|
+
return {
|
|
674
|
+
type: "orderedList",
|
|
675
|
+
attrs: { start: startValue },
|
|
676
|
+
content
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
type: "orderedList",
|
|
681
|
+
content
|
|
682
|
+
};
|
|
683
|
+
},
|
|
684
|
+
renderMarkdown: (node, h) => {
|
|
685
|
+
if (!node.content) {
|
|
686
|
+
return "";
|
|
687
|
+
}
|
|
688
|
+
return h.renderChildren(node.content, "\n");
|
|
689
|
+
},
|
|
690
|
+
markdownTokenizer: {
|
|
691
|
+
name: "orderedList",
|
|
692
|
+
level: "block",
|
|
693
|
+
start: (src) => {
|
|
694
|
+
const match = src.match(/^(\s*)(\d+)\.\s+/);
|
|
695
|
+
const index = match == null ? void 0 : match.index;
|
|
696
|
+
return index !== void 0 ? index : -1;
|
|
697
|
+
},
|
|
698
|
+
tokenize: (src, _tokens, lexer) => {
|
|
699
|
+
var _a;
|
|
700
|
+
const lines = src.split("\n");
|
|
701
|
+
const [listItems, consumed] = collectOrderedListItems(lines);
|
|
702
|
+
if (listItems.length === 0) {
|
|
703
|
+
return void 0;
|
|
704
|
+
}
|
|
705
|
+
const items = buildNestedStructure(listItems, 0, lexer);
|
|
706
|
+
if (items.length === 0) {
|
|
707
|
+
return void 0;
|
|
708
|
+
}
|
|
709
|
+
const startValue = ((_a = listItems[0]) == null ? void 0 : _a.number) || 1;
|
|
710
|
+
return {
|
|
711
|
+
type: "list",
|
|
712
|
+
ordered: true,
|
|
713
|
+
start: startValue,
|
|
714
|
+
items,
|
|
715
|
+
raw: lines.slice(0, consumed).join("\n")
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
markdownOptions: {
|
|
720
|
+
indentsContent: true
|
|
721
|
+
},
|
|
453
722
|
addCommands() {
|
|
454
723
|
return {
|
|
455
724
|
toggleOrderedList: () => ({ commands, chain }) => {
|
|
@@ -489,7 +758,7 @@ var OrderedList = import_core9.Node.create({
|
|
|
489
758
|
|
|
490
759
|
// src/task-item/task-item.ts
|
|
491
760
|
var import_core10 = require("@tiptap/core");
|
|
492
|
-
var inputRegex = /^\s*(\[([( |x])?\])\s$/;
|
|
761
|
+
var inputRegex = /^\s*((\[([( |x])?\])|\.)\s$/;
|
|
493
762
|
var TaskItem = import_core10.Node.create({
|
|
494
763
|
name: "taskItem",
|
|
495
764
|
addOptions() {
|
|
@@ -547,6 +816,27 @@ var TaskItem = import_core10.Node.create({
|
|
|
547
816
|
["div", 0]
|
|
548
817
|
];
|
|
549
818
|
},
|
|
819
|
+
parseMarkdown: (token, h) => {
|
|
820
|
+
const content = [];
|
|
821
|
+
if (token.tokens && token.tokens.length > 0) {
|
|
822
|
+
content.push(h.createNode("paragraph", {}, h.parseInline(token.tokens)));
|
|
823
|
+
} else if (token.text) {
|
|
824
|
+
content.push(h.createNode("paragraph", {}, [h.createNode("text", { text: token.text })]));
|
|
825
|
+
} else {
|
|
826
|
+
content.push(h.createNode("paragraph", {}, []));
|
|
827
|
+
}
|
|
828
|
+
if (token.nestedTokens && token.nestedTokens.length > 0) {
|
|
829
|
+
const nestedContent = h.parseChildren(token.nestedTokens);
|
|
830
|
+
content.push(...nestedContent);
|
|
831
|
+
}
|
|
832
|
+
return h.createNode("taskItem", { checked: token.checked || false }, content);
|
|
833
|
+
},
|
|
834
|
+
renderMarkdown: (node, h) => {
|
|
835
|
+
var _a;
|
|
836
|
+
const checkedChar = ((_a = node.attrs) == null ? void 0 : _a.checked) ? "x" : " ";
|
|
837
|
+
const prefix = `- [${checkedChar}] `;
|
|
838
|
+
return (0, import_core10.renderNestedMarkdownContent)(node, h, prefix);
|
|
839
|
+
},
|
|
550
840
|
addKeyboardShortcuts() {
|
|
551
841
|
const shortcuts = {
|
|
552
842
|
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
@@ -567,13 +857,14 @@ var TaskItem = import_core10.Node.create({
|
|
|
567
857
|
const checkboxStyler = document.createElement("span");
|
|
568
858
|
const checkbox = document.createElement("input");
|
|
569
859
|
const content = document.createElement("div");
|
|
570
|
-
const updateA11Y = () => {
|
|
860
|
+
const updateA11Y = (currentNode) => {
|
|
571
861
|
var _a, _b;
|
|
572
|
-
checkbox.ariaLabel = ((_b = (_a = this.options.a11y) == null ? void 0 : _a.checkboxLabel) == null ? void 0 : _b.call(_a,
|
|
862
|
+
checkbox.ariaLabel = ((_b = (_a = this.options.a11y) == null ? void 0 : _a.checkboxLabel) == null ? void 0 : _b.call(_a, currentNode, checkbox.checked)) || `Task item checkbox for ${currentNode.textContent || "empty task item"}`;
|
|
573
863
|
};
|
|
574
|
-
updateA11Y();
|
|
864
|
+
updateA11Y(node);
|
|
575
865
|
checkboxWrapper.contentEditable = "false";
|
|
576
866
|
checkbox.type = "checkbox";
|
|
867
|
+
checkbox.contentEditable = "false";
|
|
577
868
|
checkbox.addEventListener("mousedown", (event) => event.preventDefault());
|
|
578
869
|
checkbox.addEventListener("change", (event) => {
|
|
579
870
|
if (!editor.isEditable && !this.options.onReadOnlyChecked) {
|
|
@@ -626,6 +917,7 @@ var TaskItem = import_core10.Node.create({
|
|
|
626
917
|
Object.entries(HTMLAttributes).forEach(([key, value]) => {
|
|
627
918
|
listItem.setAttribute(key, value);
|
|
628
919
|
});
|
|
920
|
+
let prevRenderedAttributeKeys = new Set(Object.keys(HTMLAttributes));
|
|
629
921
|
return {
|
|
630
922
|
dom: listItem,
|
|
631
923
|
contentDOM: content,
|
|
@@ -635,7 +927,32 @@ var TaskItem = import_core10.Node.create({
|
|
|
635
927
|
}
|
|
636
928
|
listItem.dataset.checked = updatedNode.attrs.checked;
|
|
637
929
|
checkbox.checked = updatedNode.attrs.checked;
|
|
638
|
-
updateA11Y();
|
|
930
|
+
updateA11Y(updatedNode);
|
|
931
|
+
const extensionAttributes = editor.extensionManager.attributes;
|
|
932
|
+
const newHTMLAttributes = (0, import_core10.getRenderedAttributes)(updatedNode, extensionAttributes);
|
|
933
|
+
const newKeys = new Set(Object.keys(newHTMLAttributes));
|
|
934
|
+
const staticAttrs = this.options.HTMLAttributes;
|
|
935
|
+
prevRenderedAttributeKeys.forEach((key) => {
|
|
936
|
+
if (!newKeys.has(key)) {
|
|
937
|
+
if (key in staticAttrs) {
|
|
938
|
+
listItem.setAttribute(key, staticAttrs[key]);
|
|
939
|
+
} else {
|
|
940
|
+
listItem.removeAttribute(key);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
Object.entries(newHTMLAttributes).forEach(([key, value]) => {
|
|
945
|
+
if (value === null || value === void 0) {
|
|
946
|
+
if (key in staticAttrs) {
|
|
947
|
+
listItem.setAttribute(key, staticAttrs[key]);
|
|
948
|
+
} else {
|
|
949
|
+
listItem.removeAttribute(key);
|
|
950
|
+
}
|
|
951
|
+
} else {
|
|
952
|
+
listItem.setAttribute(key, value);
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
prevRenderedAttributeKeys = newKeys;
|
|
639
956
|
return true;
|
|
640
957
|
}
|
|
641
958
|
};
|
|
@@ -679,6 +996,97 @@ var TaskList = import_core11.Node.create({
|
|
|
679
996
|
renderHTML({ HTMLAttributes }) {
|
|
680
997
|
return ["ul", (0, import_core11.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
|
|
681
998
|
},
|
|
999
|
+
parseMarkdown: (token, h) => {
|
|
1000
|
+
return h.createNode("taskList", {}, h.parseChildren(token.items || []));
|
|
1001
|
+
},
|
|
1002
|
+
renderMarkdown: (node, h) => {
|
|
1003
|
+
if (!node.content) {
|
|
1004
|
+
return "";
|
|
1005
|
+
}
|
|
1006
|
+
return h.renderChildren(node.content, "\n");
|
|
1007
|
+
},
|
|
1008
|
+
markdownTokenizer: {
|
|
1009
|
+
name: "taskList",
|
|
1010
|
+
level: "block",
|
|
1011
|
+
start(src) {
|
|
1012
|
+
var _a;
|
|
1013
|
+
const index = (_a = src.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)) == null ? void 0 : _a.index;
|
|
1014
|
+
return index !== void 0 ? index : -1;
|
|
1015
|
+
},
|
|
1016
|
+
tokenize(src, tokens, lexer) {
|
|
1017
|
+
const parseTaskListContent = (content) => {
|
|
1018
|
+
const nestedResult = (0, import_core11.parseIndentedBlocks)(
|
|
1019
|
+
content,
|
|
1020
|
+
{
|
|
1021
|
+
itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,
|
|
1022
|
+
extractItemData: (match) => ({
|
|
1023
|
+
indentLevel: match[1].length,
|
|
1024
|
+
mainContent: match[4],
|
|
1025
|
+
checked: match[3].toLowerCase() === "x"
|
|
1026
|
+
}),
|
|
1027
|
+
createToken: (data, nestedTokens) => ({
|
|
1028
|
+
type: "taskItem",
|
|
1029
|
+
raw: "",
|
|
1030
|
+
mainContent: data.mainContent,
|
|
1031
|
+
indentLevel: data.indentLevel,
|
|
1032
|
+
checked: data.checked,
|
|
1033
|
+
text: data.mainContent,
|
|
1034
|
+
tokens: lexer.inlineTokens(data.mainContent),
|
|
1035
|
+
nestedTokens
|
|
1036
|
+
}),
|
|
1037
|
+
// Allow recursive nesting
|
|
1038
|
+
customNestedParser: parseTaskListContent
|
|
1039
|
+
},
|
|
1040
|
+
lexer
|
|
1041
|
+
);
|
|
1042
|
+
if (nestedResult) {
|
|
1043
|
+
return [
|
|
1044
|
+
{
|
|
1045
|
+
type: "taskList",
|
|
1046
|
+
raw: nestedResult.raw,
|
|
1047
|
+
items: nestedResult.items
|
|
1048
|
+
}
|
|
1049
|
+
];
|
|
1050
|
+
}
|
|
1051
|
+
return lexer.blockTokens(content);
|
|
1052
|
+
};
|
|
1053
|
+
const result = (0, import_core11.parseIndentedBlocks)(
|
|
1054
|
+
src,
|
|
1055
|
+
{
|
|
1056
|
+
itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,
|
|
1057
|
+
extractItemData: (match) => ({
|
|
1058
|
+
indentLevel: match[1].length,
|
|
1059
|
+
mainContent: match[4],
|
|
1060
|
+
checked: match[3].toLowerCase() === "x"
|
|
1061
|
+
}),
|
|
1062
|
+
createToken: (data, nestedTokens) => ({
|
|
1063
|
+
type: "taskItem",
|
|
1064
|
+
raw: "",
|
|
1065
|
+
mainContent: data.mainContent,
|
|
1066
|
+
indentLevel: data.indentLevel,
|
|
1067
|
+
checked: data.checked,
|
|
1068
|
+
text: data.mainContent,
|
|
1069
|
+
tokens: lexer.inlineTokens(data.mainContent),
|
|
1070
|
+
nestedTokens
|
|
1071
|
+
}),
|
|
1072
|
+
// Use the recursive parser for nested content
|
|
1073
|
+
customNestedParser: parseTaskListContent
|
|
1074
|
+
},
|
|
1075
|
+
lexer
|
|
1076
|
+
);
|
|
1077
|
+
if (!result) {
|
|
1078
|
+
return void 0;
|
|
1079
|
+
}
|
|
1080
|
+
return {
|
|
1081
|
+
type: "taskList",
|
|
1082
|
+
raw: result.raw,
|
|
1083
|
+
items: result.items
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
markdownOptions: {
|
|
1088
|
+
indentsContent: true
|
|
1089
|
+
},
|
|
682
1090
|
addCommands() {
|
|
683
1091
|
return {
|
|
684
1092
|
toggleTaskList: () => ({ commands }) => {
|