@tiptap/extension-list 3.6.7 → 3.7.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 +379 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +382 -3
- package/dist/index.js.map +1 -1
- package/dist/item/index.cjs +59 -0
- package/dist/item/index.cjs.map +1 -1
- package/dist/item/index.js +60 -1
- package/dist/item/index.js.map +1 -1
- package/dist/kit/index.cjs +379 -0
- package/dist/kit/index.cjs.map +1 -1
- package/dist/kit/index.js +382 -3
- 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 +21 -0
- package/dist/task-item/index.cjs.map +1 -1
- package/dist/task-item/index.js +22 -1
- 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 +81 -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 +33 -1
- 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,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,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,kBACE,MACA,CAAC,EAAE,UAAU,MAAM,MAAM;AACvB,YAAI,KAAK,QAAQ,gBAAgB;AAC/B,iBAAO,MAAM,EACV,WAAW,KAAK,MAAM,KAAK,QAAQ,cAAc,KAAK,QAAQ,SAAS,EACvE,iBAAiB,cAAc,KAAK,OAAO,cAAc,aAAa,CAAC,EACvE,IAAI;AAAA,QACT;AACA,eAAO,SAAS,WAAW,KAAK,MAAM,KAAK,QAAQ,cAAc,KAAK,QAAQ,SAAS;AAAA,MACzF;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,iBAAiB;AAAA,IAC7D;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,QAAI,gBAAY,+BAAkB;AAAA,MAChC,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,IACb,CAAC;AAED,QAAI,KAAK,QAAQ,aAAa,KAAK,QAAQ,gBAAgB;AACzD,sBAAY,+BAAkB;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":[]}
|
|
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,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AAAA,EAEA,mBAAmB;AAAA,EAEnB,eAAe,CAAC,OAAO,YAAY;AACjC,QAAI,MAAM,SAAS,UAAW,MAAc,SAAS;AACnD,aAAO,CAAC;A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AO,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,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,W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,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;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAA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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,65 @@ 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
|
+
if (context.parentType === "bulletList") {
|
|
189
|
+
return "- ";
|
|
190
|
+
}
|
|
191
|
+
if (context.parentType === "orderedList") {
|
|
192
|
+
return `${context.index + 1}. `;
|
|
193
|
+
}
|
|
194
|
+
return "- ";
|
|
195
|
+
},
|
|
196
|
+
ctx
|
|
197
|
+
);
|
|
198
|
+
},
|
|
121
199
|
addKeyboardShortcuts() {
|
|
122
200
|
return {
|
|
123
201
|
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
@@ -408,6 +486,138 @@ var import_core12 = require("@tiptap/core");
|
|
|
408
486
|
|
|
409
487
|
// src/ordered-list/ordered-list.ts
|
|
410
488
|
var import_core9 = require("@tiptap/core");
|
|
489
|
+
|
|
490
|
+
// src/ordered-list/utils.ts
|
|
491
|
+
var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/;
|
|
492
|
+
var INDENTED_LINE_REGEX = /^\s/;
|
|
493
|
+
function collectOrderedListItems(lines) {
|
|
494
|
+
const listItems = [];
|
|
495
|
+
let currentLineIndex = 0;
|
|
496
|
+
let consumed = 0;
|
|
497
|
+
while (currentLineIndex < lines.length) {
|
|
498
|
+
const line = lines[currentLineIndex];
|
|
499
|
+
const match = line.match(ORDERED_LIST_ITEM_REGEX);
|
|
500
|
+
if (!match) {
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
const [, indent, number, content] = match;
|
|
504
|
+
const indentLevel = indent.length;
|
|
505
|
+
let itemContent = content;
|
|
506
|
+
let nextLineIndex = currentLineIndex + 1;
|
|
507
|
+
const itemLines = [line];
|
|
508
|
+
while (nextLineIndex < lines.length) {
|
|
509
|
+
const nextLine = lines[nextLineIndex];
|
|
510
|
+
const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX);
|
|
511
|
+
if (nextMatch) {
|
|
512
|
+
break;
|
|
513
|
+
}
|
|
514
|
+
if (nextLine.trim() === "") {
|
|
515
|
+
itemLines.push(nextLine);
|
|
516
|
+
itemContent += "\n";
|
|
517
|
+
nextLineIndex += 1;
|
|
518
|
+
} else if (nextLine.match(INDENTED_LINE_REGEX)) {
|
|
519
|
+
itemLines.push(nextLine);
|
|
520
|
+
itemContent += `
|
|
521
|
+
${nextLine.slice(indentLevel + 2)}`;
|
|
522
|
+
nextLineIndex += 1;
|
|
523
|
+
} else {
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
listItems.push({
|
|
528
|
+
indent: indentLevel,
|
|
529
|
+
number: parseInt(number, 10),
|
|
530
|
+
content: itemContent.trim(),
|
|
531
|
+
raw: itemLines.join("\n")
|
|
532
|
+
});
|
|
533
|
+
consumed = nextLineIndex;
|
|
534
|
+
currentLineIndex = nextLineIndex;
|
|
535
|
+
}
|
|
536
|
+
return [listItems, consumed];
|
|
537
|
+
}
|
|
538
|
+
function buildNestedStructure(items, baseIndent, lexer) {
|
|
539
|
+
var _a;
|
|
540
|
+
const result = [];
|
|
541
|
+
let currentIndex = 0;
|
|
542
|
+
while (currentIndex < items.length) {
|
|
543
|
+
const item = items[currentIndex];
|
|
544
|
+
if (item.indent === baseIndent) {
|
|
545
|
+
const contentLines = item.content.split("\n");
|
|
546
|
+
const mainText = ((_a = contentLines[0]) == null ? void 0 : _a.trim()) || "";
|
|
547
|
+
const tokens = [];
|
|
548
|
+
if (mainText) {
|
|
549
|
+
tokens.push({
|
|
550
|
+
type: "paragraph",
|
|
551
|
+
raw: mainText,
|
|
552
|
+
tokens: lexer.inlineTokens(mainText)
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
const additionalContent = contentLines.slice(1).join("\n").trim();
|
|
556
|
+
if (additionalContent) {
|
|
557
|
+
const blockTokens = lexer.blockTokens(additionalContent);
|
|
558
|
+
tokens.push(...blockTokens);
|
|
559
|
+
}
|
|
560
|
+
let lookAheadIndex = currentIndex + 1;
|
|
561
|
+
const nestedItems = [];
|
|
562
|
+
while (lookAheadIndex < items.length && items[lookAheadIndex].indent > baseIndent) {
|
|
563
|
+
nestedItems.push(items[lookAheadIndex]);
|
|
564
|
+
lookAheadIndex += 1;
|
|
565
|
+
}
|
|
566
|
+
if (nestedItems.length > 0) {
|
|
567
|
+
const nextIndent = Math.min(...nestedItems.map((nestedItem) => nestedItem.indent));
|
|
568
|
+
const nestedListItems = buildNestedStructure(nestedItems, nextIndent, lexer);
|
|
569
|
+
tokens.push({
|
|
570
|
+
type: "list",
|
|
571
|
+
ordered: true,
|
|
572
|
+
start: nestedItems[0].number,
|
|
573
|
+
items: nestedListItems,
|
|
574
|
+
raw: nestedItems.map((nestedItem) => nestedItem.raw).join("\n")
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
result.push({
|
|
578
|
+
type: "list_item",
|
|
579
|
+
raw: item.raw,
|
|
580
|
+
tokens
|
|
581
|
+
});
|
|
582
|
+
currentIndex = lookAheadIndex;
|
|
583
|
+
} else {
|
|
584
|
+
currentIndex += 1;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
return result;
|
|
588
|
+
}
|
|
589
|
+
function parseListItems(items, helpers) {
|
|
590
|
+
return items.map((item) => {
|
|
591
|
+
if (item.type !== "list_item") {
|
|
592
|
+
return helpers.parseChildren([item])[0];
|
|
593
|
+
}
|
|
594
|
+
const content = [];
|
|
595
|
+
if (item.tokens && item.tokens.length > 0) {
|
|
596
|
+
item.tokens.forEach((itemToken) => {
|
|
597
|
+
if (itemToken.type === "paragraph" || itemToken.type === "list" || itemToken.type === "blockquote" || itemToken.type === "code") {
|
|
598
|
+
content.push(...helpers.parseChildren([itemToken]));
|
|
599
|
+
} else if (itemToken.type === "text" && itemToken.tokens) {
|
|
600
|
+
const inlineContent = helpers.parseChildren([itemToken]);
|
|
601
|
+
content.push({
|
|
602
|
+
type: "paragraph",
|
|
603
|
+
content: inlineContent
|
|
604
|
+
});
|
|
605
|
+
} else {
|
|
606
|
+
const parsed = helpers.parseChildren([itemToken]);
|
|
607
|
+
if (parsed.length > 0) {
|
|
608
|
+
content.push(...parsed);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
return {
|
|
614
|
+
type: "listItem",
|
|
615
|
+
content
|
|
616
|
+
};
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// src/ordered-list/ordered-list.ts
|
|
411
621
|
var ListItemName2 = "listItem";
|
|
412
622
|
var TextStyleName2 = "textStyle";
|
|
413
623
|
var orderedListInputRegex = /^(\d+)\.\s$/;
|
|
@@ -450,6 +660,63 @@ var OrderedList = import_core9.Node.create({
|
|
|
450
660
|
const { start, ...attributesWithoutStart } = HTMLAttributes;
|
|
451
661
|
return start === 1 ? ["ol", (0, import_core9.mergeAttributes)(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", (0, import_core9.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
452
662
|
},
|
|
663
|
+
markdownTokenName: "list",
|
|
664
|
+
parseMarkdown: (token, helpers) => {
|
|
665
|
+
if (token.type !== "list" || !token.ordered) {
|
|
666
|
+
return [];
|
|
667
|
+
}
|
|
668
|
+
const startValue = token.start || 1;
|
|
669
|
+
const content = token.items ? parseListItems(token.items, helpers) : [];
|
|
670
|
+
if (startValue !== 1) {
|
|
671
|
+
return {
|
|
672
|
+
type: "orderedList",
|
|
673
|
+
attrs: { start: startValue },
|
|
674
|
+
content
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
return {
|
|
678
|
+
type: "orderedList",
|
|
679
|
+
content
|
|
680
|
+
};
|
|
681
|
+
},
|
|
682
|
+
renderMarkdown: (node, h) => {
|
|
683
|
+
if (!node.content) {
|
|
684
|
+
return "";
|
|
685
|
+
}
|
|
686
|
+
return h.renderChildren(node.content, "\n");
|
|
687
|
+
},
|
|
688
|
+
markdownTokenizer: {
|
|
689
|
+
name: "orderedList",
|
|
690
|
+
level: "block",
|
|
691
|
+
start: (src) => {
|
|
692
|
+
const match = src.match(/^(\s*)(\d+)\.\s+/);
|
|
693
|
+
const index = match == null ? void 0 : match.index;
|
|
694
|
+
return index !== void 0 ? index : -1;
|
|
695
|
+
},
|
|
696
|
+
tokenize: (src, _tokens, lexer) => {
|
|
697
|
+
var _a;
|
|
698
|
+
const lines = src.split("\n");
|
|
699
|
+
const [listItems, consumed] = collectOrderedListItems(lines);
|
|
700
|
+
if (listItems.length === 0) {
|
|
701
|
+
return void 0;
|
|
702
|
+
}
|
|
703
|
+
const items = buildNestedStructure(listItems, 0, lexer);
|
|
704
|
+
if (items.length === 0) {
|
|
705
|
+
return void 0;
|
|
706
|
+
}
|
|
707
|
+
const startValue = ((_a = listItems[0]) == null ? void 0 : _a.number) || 1;
|
|
708
|
+
return {
|
|
709
|
+
type: "list",
|
|
710
|
+
ordered: true,
|
|
711
|
+
start: startValue,
|
|
712
|
+
items,
|
|
713
|
+
raw: lines.slice(0, consumed).join("\n")
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
markdownOptions: {
|
|
718
|
+
indentsContent: true
|
|
719
|
+
},
|
|
453
720
|
addCommands() {
|
|
454
721
|
return {
|
|
455
722
|
toggleOrderedList: () => ({ commands, chain }) => {
|
|
@@ -547,6 +814,27 @@ var TaskItem = import_core10.Node.create({
|
|
|
547
814
|
["div", 0]
|
|
548
815
|
];
|
|
549
816
|
},
|
|
817
|
+
parseMarkdown: (token, h) => {
|
|
818
|
+
const content = [];
|
|
819
|
+
if (token.tokens && token.tokens.length > 0) {
|
|
820
|
+
content.push(h.createNode("paragraph", {}, h.parseInline(token.tokens)));
|
|
821
|
+
} else if (token.text) {
|
|
822
|
+
content.push(h.createNode("paragraph", {}, [h.createNode("text", { text: token.text })]));
|
|
823
|
+
} else {
|
|
824
|
+
content.push(h.createNode("paragraph", {}, []));
|
|
825
|
+
}
|
|
826
|
+
if (token.nestedTokens && token.nestedTokens.length > 0) {
|
|
827
|
+
const nestedContent = h.parseChildren(token.nestedTokens);
|
|
828
|
+
content.push(...nestedContent);
|
|
829
|
+
}
|
|
830
|
+
return h.createNode("taskItem", { checked: token.checked || false }, content);
|
|
831
|
+
},
|
|
832
|
+
renderMarkdown: (node, h) => {
|
|
833
|
+
var _a;
|
|
834
|
+
const checkedChar = ((_a = node.attrs) == null ? void 0 : _a.checked) ? "x" : " ";
|
|
835
|
+
const prefix = `- [${checkedChar}] `;
|
|
836
|
+
return (0, import_core10.renderNestedMarkdownContent)(node, h, prefix);
|
|
837
|
+
},
|
|
550
838
|
addKeyboardShortcuts() {
|
|
551
839
|
const shortcuts = {
|
|
552
840
|
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
@@ -664,6 +952,97 @@ var TaskList = import_core11.Node.create({
|
|
|
664
952
|
renderHTML({ HTMLAttributes }) {
|
|
665
953
|
return ["ul", (0, import_core11.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
|
|
666
954
|
},
|
|
955
|
+
parseMarkdown: (token, h) => {
|
|
956
|
+
return h.createNode("taskList", {}, h.parseChildren(token.items || []));
|
|
957
|
+
},
|
|
958
|
+
renderMarkdown: (node, h) => {
|
|
959
|
+
if (!node.content) {
|
|
960
|
+
return "";
|
|
961
|
+
}
|
|
962
|
+
return h.renderChildren(node.content, "\n");
|
|
963
|
+
},
|
|
964
|
+
markdownTokenizer: {
|
|
965
|
+
name: "taskList",
|
|
966
|
+
level: "block",
|
|
967
|
+
start(src) {
|
|
968
|
+
var _a;
|
|
969
|
+
const index = (_a = src.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)) == null ? void 0 : _a.index;
|
|
970
|
+
return index !== void 0 ? index : -1;
|
|
971
|
+
},
|
|
972
|
+
tokenize(src, tokens, lexer) {
|
|
973
|
+
const parseTaskListContent = (content) => {
|
|
974
|
+
const nestedResult = (0, import_core11.parseIndentedBlocks)(
|
|
975
|
+
content,
|
|
976
|
+
{
|
|
977
|
+
itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,
|
|
978
|
+
extractItemData: (match) => ({
|
|
979
|
+
indentLevel: match[1].length,
|
|
980
|
+
mainContent: match[4],
|
|
981
|
+
checked: match[3].toLowerCase() === "x"
|
|
982
|
+
}),
|
|
983
|
+
createToken: (data, nestedTokens) => ({
|
|
984
|
+
type: "taskItem",
|
|
985
|
+
raw: "",
|
|
986
|
+
mainContent: data.mainContent,
|
|
987
|
+
indentLevel: data.indentLevel,
|
|
988
|
+
checked: data.checked,
|
|
989
|
+
text: data.mainContent,
|
|
990
|
+
tokens: lexer.inlineTokens(data.mainContent),
|
|
991
|
+
nestedTokens
|
|
992
|
+
}),
|
|
993
|
+
// Allow recursive nesting
|
|
994
|
+
customNestedParser: parseTaskListContent
|
|
995
|
+
},
|
|
996
|
+
lexer
|
|
997
|
+
);
|
|
998
|
+
if (nestedResult) {
|
|
999
|
+
return [
|
|
1000
|
+
{
|
|
1001
|
+
type: "taskList",
|
|
1002
|
+
raw: nestedResult.raw,
|
|
1003
|
+
items: nestedResult.items
|
|
1004
|
+
}
|
|
1005
|
+
];
|
|
1006
|
+
}
|
|
1007
|
+
return lexer.blockTokens(content);
|
|
1008
|
+
};
|
|
1009
|
+
const result = (0, import_core11.parseIndentedBlocks)(
|
|
1010
|
+
src,
|
|
1011
|
+
{
|
|
1012
|
+
itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,
|
|
1013
|
+
extractItemData: (match) => ({
|
|
1014
|
+
indentLevel: match[1].length,
|
|
1015
|
+
mainContent: match[4],
|
|
1016
|
+
checked: match[3].toLowerCase() === "x"
|
|
1017
|
+
}),
|
|
1018
|
+
createToken: (data, nestedTokens) => ({
|
|
1019
|
+
type: "taskItem",
|
|
1020
|
+
raw: "",
|
|
1021
|
+
mainContent: data.mainContent,
|
|
1022
|
+
indentLevel: data.indentLevel,
|
|
1023
|
+
checked: data.checked,
|
|
1024
|
+
text: data.mainContent,
|
|
1025
|
+
tokens: lexer.inlineTokens(data.mainContent),
|
|
1026
|
+
nestedTokens
|
|
1027
|
+
}),
|
|
1028
|
+
// Use the recursive parser for nested content
|
|
1029
|
+
customNestedParser: parseTaskListContent
|
|
1030
|
+
},
|
|
1031
|
+
lexer
|
|
1032
|
+
);
|
|
1033
|
+
if (!result) {
|
|
1034
|
+
return void 0;
|
|
1035
|
+
}
|
|
1036
|
+
return {
|
|
1037
|
+
type: "taskList",
|
|
1038
|
+
raw: result.raw,
|
|
1039
|
+
items: result.items
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
},
|
|
1043
|
+
markdownOptions: {
|
|
1044
|
+
indentsContent: true
|
|
1045
|
+
},
|
|
667
1046
|
addCommands() {
|
|
668
1047
|
return {
|
|
669
1048
|
toggleTaskList: () => ({ commands }) => {
|