@tiptap/extension-list 3.22.3 → 3.22.4

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.
@@ -4,6 +4,36 @@ import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core";
4
4
  // src/ordered-list/utils.ts
5
5
  var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/;
6
6
  var INDENTED_LINE_REGEX = /^\s/;
7
+ function isBlockContentLine(line) {
8
+ const trimmedLine = line.trimStart();
9
+ return /^[-+*]\s+/.test(trimmedLine) || /^\d+\.\s+/.test(trimmedLine) || /^>\s?/.test(trimmedLine) || /^```/.test(trimmedLine) || /^~~~/.test(trimmedLine);
10
+ }
11
+ function splitItemContent(contentLines) {
12
+ const paragraphLines = [];
13
+ const blockLines = [];
14
+ let reachedBlockBoundary = false;
15
+ contentLines.forEach((line) => {
16
+ if (reachedBlockBoundary) {
17
+ blockLines.push(line);
18
+ return;
19
+ }
20
+ if (line.trim() === "") {
21
+ reachedBlockBoundary = true;
22
+ blockLines.push(line);
23
+ return;
24
+ }
25
+ if (paragraphLines.length > 0 && isBlockContentLine(line)) {
26
+ reachedBlockBoundary = true;
27
+ blockLines.push(line);
28
+ return;
29
+ }
30
+ paragraphLines.push(line);
31
+ });
32
+ return {
33
+ paragraphLines,
34
+ blockLines
35
+ };
36
+ }
7
37
  function collectOrderedListItems(lines) {
8
38
  const listItems = [];
9
39
  let currentLineIndex = 0;
@@ -16,9 +46,10 @@ function collectOrderedListItems(lines) {
16
46
  }
17
47
  const [, indent, number, content] = match;
18
48
  const indentLevel = indent.length;
19
- let itemContent = content;
49
+ const itemContentLines = [content];
20
50
  let nextLineIndex = currentLineIndex + 1;
21
51
  const itemLines = [line];
52
+ let sawBlankLine = false;
22
53
  while (nextLineIndex < lines.length) {
23
54
  const nextLine = lines[nextLineIndex];
24
55
  const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX);
@@ -27,21 +58,27 @@ function collectOrderedListItems(lines) {
27
58
  }
28
59
  if (nextLine.trim() === "") {
29
60
  itemLines.push(nextLine);
30
- itemContent += "\n";
61
+ itemContentLines.push("");
62
+ sawBlankLine = true;
31
63
  nextLineIndex += 1;
32
64
  } else if (nextLine.match(INDENTED_LINE_REGEX)) {
33
65
  itemLines.push(nextLine);
34
- itemContent += `
35
- ${nextLine.slice(indentLevel + 2)}`;
66
+ itemContentLines.push(nextLine.slice(indentLevel + 2));
36
67
  nextLineIndex += 1;
37
68
  } else {
38
- break;
69
+ if (sawBlankLine) {
70
+ break;
71
+ }
72
+ itemLines.push(nextLine);
73
+ itemContentLines.push(nextLine);
74
+ nextLineIndex += 1;
39
75
  }
40
76
  }
41
77
  listItems.push({
42
78
  indent: indentLevel,
43
79
  number: parseInt(number, 10),
44
- content: itemContent.trim(),
80
+ content: itemContentLines.join("\n").trim(),
81
+ contentLines: itemContentLines,
45
82
  raw: itemLines.join("\n")
46
83
  });
47
84
  consumed = nextLineIndex;
@@ -50,14 +87,13 @@ ${nextLine.slice(indentLevel + 2)}`;
50
87
  return [listItems, consumed];
51
88
  }
52
89
  function buildNestedStructure(items, baseIndent, lexer) {
53
- var _a;
54
90
  const result = [];
55
91
  let currentIndex = 0;
56
92
  while (currentIndex < items.length) {
57
93
  const item = items[currentIndex];
58
94
  if (item.indent === baseIndent) {
59
- const contentLines = item.content.split("\n");
60
- const mainText = ((_a = contentLines[0]) == null ? void 0 : _a.trim()) || "";
95
+ const { paragraphLines, blockLines } = splitItemContent(item.contentLines);
96
+ const mainText = paragraphLines.join("\n").trim();
61
97
  const tokens = [];
62
98
  if (mainText) {
63
99
  tokens.push({
@@ -66,7 +102,7 @@ function buildNestedStructure(items, baseIndent, lexer) {
66
102
  tokens: lexer.inlineTokens(mainText)
67
103
  });
68
104
  }
69
- const additionalContent = contentLines.slice(1).join("\n").trim();
105
+ const additionalContent = blockLines.join("\n").trim();
70
106
  if (additionalContent) {
71
107
  const blockTokens = lexer.blockTokens(additionalContent);
72
108
  tokens.push(...blockTokens);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ordered-list/ordered-list.ts","../../src/ordered-list/utils.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nimport { buildNestedStructure, collectOrderedListItems, parseListItems } from './utils.js'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface OrderedListOptions {\n /**\n * The node type name for list items.\n * @default 'listItem'\n * @example 'myListItem'\n */\n itemTypeName: string\n\n /**\n * The HTML attributes for an ordered list node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting a list item.\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting a list item.\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n orderedList: {\n /**\n * Toggle an ordered list\n * @example editor.commands.toggleOrderedList()\n */\n toggleOrderedList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches an ordered list to a 1. on input (or any number followed by a dot).\n */\nexport const orderedListInputRegex = /^(\\d+)\\.\\s$/\n\n/**\n * This extension allows you to create ordered lists.\n * This requires the ListItem extension\n * @see https://www.tiptap.dev/api/nodes/ordered-list\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nexport const OrderedList = Node.create<OrderedListOptions>({\n name: 'orderedList',\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 addAttributes() {\n return {\n start: {\n default: 1,\n parseHTML: element => {\n return element.hasAttribute('start') ? parseInt(element.getAttribute('start') || '', 10) : 1\n },\n },\n type: {\n default: null,\n parseHTML: element => element.getAttribute('type'),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'ol',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const { start, ...attributesWithoutStart } = HTMLAttributes\n\n return start === 1\n ? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]\n : ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n markdownTokenName: 'list',\n\n parseMarkdown: (token, helpers) => {\n if (token.type !== 'list' || !token.ordered) {\n return []\n }\n\n const startValue = token.start || 1\n const content = token.items ? parseListItems(token.items, helpers) : []\n\n if (startValue !== 1) {\n return {\n type: 'orderedList',\n attrs: { start: startValue },\n content,\n }\n }\n\n return {\n type: 'orderedList',\n content,\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 markdownTokenizer: {\n name: 'orderedList',\n level: 'block',\n start: (src: string) => {\n const match = src.match(/^(\\s*)(\\d+)\\.\\s+/)\n const index = match?.index\n return index !== undefined ? index : -1\n },\n tokenize: (src: string, _tokens, lexer) => {\n const lines = src.split('\\n')\n const [listItems, consumed] = collectOrderedListItems(lines)\n\n if (listItems.length === 0) {\n return undefined\n }\n\n const items = buildNestedStructure(listItems, 0, lexer)\n\n if (items.length === 0) {\n return undefined\n }\n\n const startValue = listItems[0]?.number || 1\n\n return {\n type: 'list',\n ordered: true,\n start: startValue,\n items,\n raw: lines.slice(0, consumed).join('\\n'),\n } as unknown as object\n },\n },\n\n markdownOptions: {\n indentsContent: true,\n },\n\n addCommands() {\n return {\n toggleOrderedList:\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-7': () => this.editor.commands.toggleOrderedList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: orderedListInputRegex,\n type: this.type,\n getAttributes: match => ({ start: +match[1] }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: orderedListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n","import type { JSONContent, MarkdownLexerConfiguration, MarkdownParseHelpers, MarkdownToken } from '@tiptap/core'\n\n/**\n * Matches an ordered list item line with optional leading whitespace.\n * Captures: (1) indentation spaces, (2) item number, (3) content after marker\n * Example matches: \"1. Item\", \" 2. Nested item\", \" 3. Deeply nested\"\n */\nconst ORDERED_LIST_ITEM_REGEX = /^(\\s*)(\\d+)\\.\\s+(.*)$/\n\n/**\n * Matches any line that starts with whitespace (indented content).\n * Used to identify continuation content that belongs to a list item.\n */\nconst INDENTED_LINE_REGEX = /^\\s/\n\n/**\n * Represents a parsed ordered list item with indentation information\n */\nexport interface OrderedListItem {\n indent: number\n number: number\n content: string\n raw: string\n}\n\n/**\n * Collects all ordered list items from lines, parsing them into a flat array\n * with indentation information. Stops collecting continuation content when\n * encountering nested list items, allowing them to be processed separately.\n *\n * @param lines - Array of source lines to parse\n * @returns Tuple of [listItems array, number of lines consumed]\n */\nexport function collectOrderedListItems(lines: string[]): [OrderedListItem[], number] {\n const listItems: OrderedListItem[] = []\n let currentLineIndex = 0\n let consumed = 0\n\n while (currentLineIndex < lines.length) {\n const line = lines[currentLineIndex]\n const match = line.match(ORDERED_LIST_ITEM_REGEX)\n\n if (!match) {\n break\n }\n\n const [, indent, number, content] = match\n const indentLevel = indent.length\n let itemContent = content\n let nextLineIndex = currentLineIndex + 1\n const itemLines = [line]\n\n // Collect continuation lines for this item (but NOT nested list items)\n while (nextLineIndex < lines.length) {\n const nextLine = lines[nextLineIndex]\n const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX)\n\n // If it's another list item (nested or not), stop collecting\n if (nextMatch) {\n break\n }\n\n // Check for continuation content (non-list content)\n if (nextLine.trim() === '') {\n // Empty line\n itemLines.push(nextLine)\n itemContent += '\\n'\n nextLineIndex += 1\n } else if (nextLine.match(INDENTED_LINE_REGEX)) {\n // Indented content - part of this item (but not a list item)\n itemLines.push(nextLine)\n itemContent += `\\n${nextLine.slice(indentLevel + 2)}` // Remove list marker indent\n nextLineIndex += 1\n } else {\n // Non-indented line means end of list\n break\n }\n }\n\n listItems.push({\n indent: indentLevel,\n number: parseInt(number, 10),\n content: itemContent.trim(),\n raw: itemLines.join('\\n'),\n })\n\n consumed = nextLineIndex\n currentLineIndex = nextLineIndex\n }\n\n return [listItems, consumed]\n}\n\n/**\n * Recursively builds a nested structure from a flat array of list items\n * based on their indentation levels. Creates proper markdown tokens with\n * nested lists where appropriate.\n *\n * @param items - Flat array of list items with indentation info\n * @param baseIndent - The indentation level to process at this recursion level\n * @param lexer - Markdown lexer for parsing inline and block content\n * @returns Array of list_item tokens with proper nesting\n */\nexport function buildNestedStructure(\n items: OrderedListItem[],\n baseIndent: number,\n lexer: MarkdownLexerConfiguration,\n): unknown[] {\n const result: unknown[] = []\n let currentIndex = 0\n\n while (currentIndex < items.length) {\n const item = items[currentIndex]\n\n if (item.indent === baseIndent) {\n // This item belongs at the current level\n const contentLines = item.content.split('\\n')\n const mainText = contentLines[0]?.trim() || ''\n\n const tokens = []\n\n // Always wrap the main text in a paragraph token\n if (mainText) {\n tokens.push({\n type: 'paragraph',\n raw: mainText,\n tokens: lexer.inlineTokens(mainText),\n })\n }\n\n // Handle additional content after the main text\n const additionalContent = contentLines.slice(1).join('\\n').trim()\n if (additionalContent) {\n // Parse as block tokens (handles mixed unordered lists, etc.)\n const blockTokens = lexer.blockTokens(additionalContent)\n tokens.push(...blockTokens)\n }\n\n // Look ahead to find nested items at deeper indent levels\n let lookAheadIndex = currentIndex + 1\n const nestedItems = []\n\n while (lookAheadIndex < items.length && items[lookAheadIndex].indent > baseIndent) {\n nestedItems.push(items[lookAheadIndex])\n lookAheadIndex += 1\n }\n\n // If we have nested items, recursively build their structure\n if (nestedItems.length > 0) {\n // Find the next indent level (immediate children)\n const nextIndent = Math.min(...nestedItems.map(nestedItem => nestedItem.indent))\n\n // Build the nested list recursively with all nested items\n // The recursive call will handle further nesting\n const nestedListItems = buildNestedStructure(nestedItems, nextIndent, lexer)\n\n // Create a nested list token\n tokens.push({\n type: 'list',\n ordered: true,\n start: nestedItems[0].number,\n items: nestedListItems,\n raw: nestedItems.map(nestedItem => nestedItem.raw).join('\\n'),\n })\n }\n\n result.push({\n type: 'list_item',\n raw: item.raw,\n tokens,\n })\n\n // Skip the nested items we just processed\n currentIndex = lookAheadIndex\n } else {\n // This item has deeper indent than we're currently processing\n // It should be handled by a recursive call\n currentIndex += 1\n }\n }\n\n return result\n}\n\n/**\n * Parses markdown list item tokens into Tiptap JSONContent structure,\n * ensuring text content is properly wrapped in paragraph nodes.\n *\n * @param items - Array of markdown tokens representing list items\n * @param helpers - Markdown parse helpers for recursive parsing\n * @returns Array of listItem JSONContent nodes\n */\nexport function parseListItems(items: MarkdownToken[], helpers: MarkdownParseHelpers): JSONContent[] {\n return items.map(item => {\n if (item.type !== 'list_item') {\n return helpers.parseChildren([item])[0]\n }\n\n // Parse the tokens within the list item\n const content: JSONContent[] = []\n\n if (item.tokens && item.tokens.length > 0) {\n item.tokens.forEach(itemToken => {\n // If it's already a proper block node (paragraph, list, etc.), parse it directly\n if (\n itemToken.type === 'paragraph' ||\n itemToken.type === 'list' ||\n itemToken.type === 'blockquote' ||\n itemToken.type === 'code'\n ) {\n content.push(...helpers.parseChildren([itemToken]))\n } else if (itemToken.type === 'text' && itemToken.tokens) {\n // If it's inline text tokens, wrap them in a paragraph\n const inlineContent = helpers.parseChildren([itemToken])\n content.push({\n type: 'paragraph',\n content: inlineContent,\n })\n } else {\n // For any other content, try to parse it\n const parsed = helpers.parseChildren([itemToken])\n if (parsed.length > 0) {\n content.push(...parsed)\n }\n }\n })\n }\n\n return {\n type: 'listItem',\n content,\n }\n })\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,MAAM,yBAAyB;;;ACOzD,IAAM,0BAA0B;AAMhC,IAAM,sBAAsB;AAoBrB,SAAS,wBAAwB,OAA8C;AACpF,QAAM,YAA+B,CAAC;AACtC,MAAI,mBAAmB;AACvB,MAAI,WAAW;AAEf,SAAO,mBAAmB,MAAM,QAAQ;AACtC,UAAM,OAAO,MAAM,gBAAgB;AACnC,UAAM,QAAQ,KAAK,MAAM,uBAAuB;AAEhD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,UAAM,CAAC,EAAE,QAAQ,QAAQ,OAAO,IAAI;AACpC,UAAM,cAAc,OAAO;AAC3B,QAAI,cAAc;AAClB,QAAI,gBAAgB,mBAAmB;AACvC,UAAM,YAAY,CAAC,IAAI;AAGvB,WAAO,gBAAgB,MAAM,QAAQ;AACnC,YAAM,WAAW,MAAM,aAAa;AACpC,YAAM,YAAY,SAAS,MAAM,uBAAuB;AAGxD,UAAI,WAAW;AACb;AAAA,MACF;AAGA,UAAI,SAAS,KAAK,MAAM,IAAI;AAE1B,kBAAU,KAAK,QAAQ;AACvB,uBAAe;AACf,yBAAiB;AAAA,MACnB,WAAW,SAAS,MAAM,mBAAmB,GAAG;AAE9C,kBAAU,KAAK,QAAQ;AACvB,uBAAe;AAAA,EAAK,SAAS,MAAM,cAAc,CAAC,CAAC;AACnD,yBAAiB;AAAA,MACnB,OAAO;AAEL;AAAA,MACF;AAAA,IACF;AAEA,cAAU,KAAK;AAAA,MACb,QAAQ;AAAA,MACR,QAAQ,SAAS,QAAQ,EAAE;AAAA,MAC3B,SAAS,YAAY,KAAK;AAAA,MAC1B,KAAK,UAAU,KAAK,IAAI;AAAA,IAC1B,CAAC;AAED,eAAW;AACX,uBAAmB;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AAA,MACL,eAAe,MAAM,KAAK,OAAO,SAAS,kBAAkB;AAAA,IAC9D;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,QAAI,YAAY,kBAAkB;AAAA,MAChC,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,MACX,eAAe,YAAU,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE;AAAA,MAC5C,eAAe,CAAC,OAAO,SAAS,KAAK,aAAa,KAAK,MAAM,UAAU,CAAC,MAAM,CAAC;AAAA,IACjF,CAAC;AAED,QAAI,KAAK,QAAQ,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,YAAU,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,KAAK,OAAO,cAAc,aAAa,EAAE;AAAA,QACzF,eAAe,CAAC,OAAO,SAAS,KAAK,aAAa,KAAK,MAAM,UAAU,CAAC,MAAM,CAAC;AAAA,QAC/E,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AACA,WAAO,CAAC,SAAS;AAAA,EACnB;AACF,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/ordered-list/ordered-list.ts","../../src/ordered-list/utils.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nimport { buildNestedStructure, collectOrderedListItems, parseListItems } from './utils.js'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface OrderedListOptions {\n /**\n * The node type name for list items.\n * @default 'listItem'\n * @example 'myListItem'\n */\n itemTypeName: string\n\n /**\n * The HTML attributes for an ordered list node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting a list item.\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting a list item.\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n orderedList: {\n /**\n * Toggle an ordered list\n * @example editor.commands.toggleOrderedList()\n */\n toggleOrderedList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches an ordered list to a 1. on input (or any number followed by a dot).\n */\nexport const orderedListInputRegex = /^(\\d+)\\.\\s$/\n\n/**\n * This extension allows you to create ordered lists.\n * This requires the ListItem extension\n * @see https://www.tiptap.dev/api/nodes/ordered-list\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nexport const OrderedList = Node.create<OrderedListOptions>({\n name: 'orderedList',\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 addAttributes() {\n return {\n start: {\n default: 1,\n parseHTML: element => {\n return element.hasAttribute('start') ? parseInt(element.getAttribute('start') || '', 10) : 1\n },\n },\n type: {\n default: null,\n parseHTML: element => element.getAttribute('type'),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'ol',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const { start, ...attributesWithoutStart } = HTMLAttributes\n\n return start === 1\n ? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]\n : ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n markdownTokenName: 'list',\n\n parseMarkdown: (token, helpers) => {\n if (token.type !== 'list' || !token.ordered) {\n return []\n }\n\n const startValue = token.start || 1\n const content = token.items ? parseListItems(token.items, helpers) : []\n\n if (startValue !== 1) {\n return {\n type: 'orderedList',\n attrs: { start: startValue },\n content,\n }\n }\n\n return {\n type: 'orderedList',\n content,\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 markdownTokenizer: {\n name: 'orderedList',\n level: 'block',\n start: (src: string) => {\n const match = src.match(/^(\\s*)(\\d+)\\.\\s+/)\n const index = match?.index\n return index !== undefined ? index : -1\n },\n tokenize: (src: string, _tokens, lexer) => {\n const lines = src.split('\\n')\n const [listItems, consumed] = collectOrderedListItems(lines)\n\n if (listItems.length === 0) {\n return undefined\n }\n\n const items = buildNestedStructure(listItems, 0, lexer)\n\n if (items.length === 0) {\n return undefined\n }\n\n const startValue = listItems[0]?.number || 1\n\n return {\n type: 'list',\n ordered: true,\n start: startValue,\n items,\n raw: lines.slice(0, consumed).join('\\n'),\n } as unknown as object\n },\n },\n\n markdownOptions: {\n indentsContent: true,\n },\n\n addCommands() {\n return {\n toggleOrderedList:\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-7': () => this.editor.commands.toggleOrderedList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: orderedListInputRegex,\n type: this.type,\n getAttributes: match => ({ start: +match[1] }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: orderedListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n","import type { JSONContent, MarkdownLexerConfiguration, MarkdownParseHelpers, MarkdownToken } from '@tiptap/core'\n\n/**\n * Matches an ordered list item line with optional leading whitespace.\n * Captures: (1) indentation spaces, (2) item number, (3) content after marker\n * Example matches: \"1. Item\", \" 2. Nested item\", \" 3. Deeply nested\"\n */\nconst ORDERED_LIST_ITEM_REGEX = /^(\\s*)(\\d+)\\.\\s+(.*)$/\n\n/**\n * Matches any line that starts with whitespace (indented content).\n * Used to identify continuation content that belongs to a list item.\n */\nconst INDENTED_LINE_REGEX = /^\\s/\n\n/**\n * Represents a parsed ordered list item with indentation information\n */\nexport interface OrderedListItem {\n indent: number\n number: number\n content: string\n contentLines: string[]\n raw: string\n}\n\nfunction isBlockContentLine(line: string): boolean {\n const trimmedLine = line.trimStart()\n\n return (\n /^[-+*]\\s+/.test(trimmedLine) ||\n /^\\d+\\.\\s+/.test(trimmedLine) ||\n /^>\\s?/.test(trimmedLine) ||\n /^```/.test(trimmedLine) ||\n /^~~~/.test(trimmedLine)\n )\n}\n\nfunction splitItemContent(contentLines: string[]): {\n paragraphLines: string[]\n blockLines: string[]\n} {\n const paragraphLines: string[] = []\n const blockLines: string[] = []\n let reachedBlockBoundary = false\n\n contentLines.forEach(line => {\n if (reachedBlockBoundary) {\n blockLines.push(line)\n return\n }\n\n if (line.trim() === '') {\n reachedBlockBoundary = true\n blockLines.push(line)\n return\n }\n\n if (paragraphLines.length > 0 && isBlockContentLine(line)) {\n reachedBlockBoundary = true\n blockLines.push(line)\n return\n }\n\n paragraphLines.push(line)\n })\n\n return {\n paragraphLines,\n blockLines,\n }\n}\n\n/**\n * Collects all ordered list items from lines, parsing them into a flat array\n * with indentation information. Stops collecting continuation content when\n * encountering nested list items, allowing them to be processed separately.\n *\n * @param lines - Array of source lines to parse\n * @returns Tuple of [listItems array, number of lines consumed]\n */\nexport function collectOrderedListItems(lines: string[]): [OrderedListItem[], number] {\n const listItems: OrderedListItem[] = []\n let currentLineIndex = 0\n let consumed = 0\n\n while (currentLineIndex < lines.length) {\n const line = lines[currentLineIndex]\n const match = line.match(ORDERED_LIST_ITEM_REGEX)\n\n if (!match) {\n break\n }\n\n const [, indent, number, content] = match\n const indentLevel = indent.length\n const itemContentLines = [content]\n let nextLineIndex = currentLineIndex + 1\n const itemLines = [line]\n let sawBlankLine = false\n\n // Collect continuation lines for this item (but NOT nested list items)\n while (nextLineIndex < lines.length) {\n const nextLine = lines[nextLineIndex]\n const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX)\n\n // If it's another list item (nested or not), stop collecting\n if (nextMatch) {\n break\n }\n\n // Check for continuation content (non-list content)\n if (nextLine.trim() === '') {\n // Empty line\n itemLines.push(nextLine)\n itemContentLines.push('')\n sawBlankLine = true\n nextLineIndex += 1\n } else if (nextLine.match(INDENTED_LINE_REGEX)) {\n // Indented content - part of this item (but not a list item)\n itemLines.push(nextLine)\n itemContentLines.push(nextLine.slice(indentLevel + 2))\n nextLineIndex += 1\n } else {\n if (sawBlankLine) {\n break\n }\n\n itemLines.push(nextLine)\n itemContentLines.push(nextLine)\n nextLineIndex += 1\n }\n }\n\n listItems.push({\n indent: indentLevel,\n number: parseInt(number, 10),\n content: itemContentLines.join('\\n').trim(),\n contentLines: itemContentLines,\n raw: itemLines.join('\\n'),\n })\n\n consumed = nextLineIndex\n currentLineIndex = nextLineIndex\n }\n\n return [listItems, consumed]\n}\n\n/**\n * Recursively builds a nested structure from a flat array of list items\n * based on their indentation levels. Creates proper markdown tokens with\n * nested lists where appropriate.\n *\n * @param items - Flat array of list items with indentation info\n * @param baseIndent - The indentation level to process at this recursion level\n * @param lexer - Markdown lexer for parsing inline and block content\n * @returns Array of list_item tokens with proper nesting\n */\nexport function buildNestedStructure(\n items: OrderedListItem[],\n baseIndent: number,\n lexer: MarkdownLexerConfiguration,\n): unknown[] {\n const result: unknown[] = []\n let currentIndex = 0\n\n while (currentIndex < items.length) {\n const item = items[currentIndex]\n\n if (item.indent === baseIndent) {\n // This item belongs at the current level\n const { paragraphLines, blockLines } = splitItemContent(item.contentLines)\n const mainText = paragraphLines.join('\\n').trim()\n\n const tokens = []\n\n // Always wrap the main text in a paragraph token\n if (mainText) {\n tokens.push({\n type: 'paragraph',\n raw: mainText,\n tokens: lexer.inlineTokens(mainText),\n })\n }\n\n const additionalContent = blockLines.join('\\n').trim()\n if (additionalContent) {\n const blockTokens = lexer.blockTokens(additionalContent)\n tokens.push(...blockTokens)\n }\n\n // Look ahead to find nested items at deeper indent levels\n let lookAheadIndex = currentIndex + 1\n const nestedItems = []\n\n while (lookAheadIndex < items.length && items[lookAheadIndex].indent > baseIndent) {\n nestedItems.push(items[lookAheadIndex])\n lookAheadIndex += 1\n }\n\n // If we have nested items, recursively build their structure\n if (nestedItems.length > 0) {\n // Find the next indent level (immediate children)\n const nextIndent = Math.min(...nestedItems.map(nestedItem => nestedItem.indent))\n\n // Build the nested list recursively with all nested items\n // The recursive call will handle further nesting\n const nestedListItems = buildNestedStructure(nestedItems, nextIndent, lexer)\n\n // Create a nested list token\n tokens.push({\n type: 'list',\n ordered: true,\n start: nestedItems[0].number,\n items: nestedListItems,\n raw: nestedItems.map(nestedItem => nestedItem.raw).join('\\n'),\n })\n }\n\n result.push({\n type: 'list_item',\n raw: item.raw,\n tokens,\n })\n\n // Skip the nested items we just processed\n currentIndex = lookAheadIndex\n } else {\n // This item has deeper indent than we're currently processing\n // It should be handled by a recursive call\n currentIndex += 1\n }\n }\n\n return result\n}\n\n/**\n * Parses markdown list item tokens into Tiptap JSONContent structure,\n * ensuring text content is properly wrapped in paragraph nodes.\n *\n * @param items - Array of markdown tokens representing list items\n * @param helpers - Markdown parse helpers for recursive parsing\n * @returns Array of listItem JSONContent nodes\n */\nexport function parseListItems(items: MarkdownToken[], helpers: MarkdownParseHelpers): JSONContent[] {\n return items.map(item => {\n if (item.type !== 'list_item') {\n return helpers.parseChildren([item])[0]\n }\n\n // Parse the tokens within the list item\n const content: JSONContent[] = []\n\n if (item.tokens && item.tokens.length > 0) {\n item.tokens.forEach(itemToken => {\n // If it's already a proper block node (paragraph, list, etc.), parse it directly\n if (\n itemToken.type === 'paragraph' ||\n itemToken.type === 'list' ||\n itemToken.type === 'blockquote' ||\n itemToken.type === 'code'\n ) {\n content.push(...helpers.parseChildren([itemToken]))\n } else if (itemToken.type === 'text' && itemToken.tokens) {\n // If it's inline text tokens, wrap them in a paragraph\n const inlineContent = helpers.parseChildren([itemToken])\n content.push({\n type: 'paragraph',\n content: inlineContent,\n })\n } else {\n // For any other content, try to parse it\n const parsed = helpers.parseChildren([itemToken])\n if (parsed.length > 0) {\n content.push(...parsed)\n }\n }\n })\n }\n\n return {\n type: 'listItem',\n content,\n }\n })\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,MAAM,yBAAyB;;;ACOzD,IAAM,0BAA0B;AAMhC,IAAM,sBAAsB;AAa5B,SAAS,mBAAmB,MAAuB;AACjD,QAAM,cAAc,KAAK,UAAU;AAEnC,SACE,YAAY,KAAK,WAAW,KAC5B,YAAY,KAAK,WAAW,KAC5B,QAAQ,KAAK,WAAW,KACxB,OAAO,KAAK,WAAW,KACvB,OAAO,KAAK,WAAW;AAE3B;AAEA,SAAS,iBAAiB,cAGxB;AACA,QAAM,iBAA2B,CAAC;AAClC,QAAM,aAAuB,CAAC;AAC9B,MAAI,uBAAuB;AAE3B,eAAa,QAAQ,UAAQ;AAC3B,QAAI,sBAAsB;AACxB,iBAAW,KAAK,IAAI;AACpB;AAAA,IACF;AAEA,QAAI,KAAK,KAAK,MAAM,IAAI;AACtB,6BAAuB;AACvB,iBAAW,KAAK,IAAI;AACpB;AAAA,IACF;AAEA,QAAI,eAAe,SAAS,KAAK,mBAAmB,IAAI,GAAG;AACzD,6BAAuB;AACvB,iBAAW,KAAK,IAAI;AACpB;AAAA,IACF;AAEA,mBAAe,KAAK,IAAI;AAAA,EAC1B,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAUO,SAAS,wBAAwB,OAA8C;AACpF,QAAM,YAA+B,CAAC;AACtC,MAAI,mBAAmB;AACvB,MAAI,WAAW;AAEf,SAAO,mBAAmB,MAAM,QAAQ;AACtC,UAAM,OAAO,MAAM,gBAAgB;AACnC,UAAM,QA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AC,OAAO,SAAS,KAAK,aAAa,KAAK,MAAM,UAAU,CAAC,MAAM,CAAC;AAAA,IACjF,CAAC;AAED,QAAI,KAAK,QAAQ,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,YAAU,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,KAAK,OAAO,cAAc,aAAa,EAAE;AAAA,QACzF,eAAe,CAAC,OAAO,SAAS,KAAK,aAAa,KAAK,MAAM,UAAU,CAAC,MAAM,CAAC;AAAA,QAC/E,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AACA,WAAO,CAAC,SAAS;AAAA,EACnB;AACF,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-list",
3
3
  "description": "List extension for tiptap",
4
- "version": "3.22.3",
4
+ "version": "3.22.4",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -87,12 +87,12 @@
87
87
  "dist"
88
88
  ],
89
89
  "devDependencies": {
90
- "@tiptap/core": "^3.22.3",
91
- "@tiptap/pm": "^3.22.3"
90
+ "@tiptap/core": "^3.22.4",
91
+ "@tiptap/pm": "^3.22.4"
92
92
  },
93
93
  "peerDependencies": {
94
- "@tiptap/core": "^3.22.3",
95
- "@tiptap/pm": "^3.22.3"
94
+ "@tiptap/core": "3.22.4",
95
+ "@tiptap/pm": "3.22.4"
96
96
  },
97
97
  "repository": {
98
98
  "type": "git",
@@ -20,9 +20,57 @@ export interface OrderedListItem {
20
20
  indent: number
21
21
  number: number
22
22
  content: string
23
+ contentLines: string[]
23
24
  raw: string
24
25
  }
25
26
 
27
+ function isBlockContentLine(line: string): boolean {
28
+ const trimmedLine = line.trimStart()
29
+
30
+ return (
31
+ /^[-+*]\s+/.test(trimmedLine) ||
32
+ /^\d+\.\s+/.test(trimmedLine) ||
33
+ /^>\s?/.test(trimmedLine) ||
34
+ /^```/.test(trimmedLine) ||
35
+ /^~~~/.test(trimmedLine)
36
+ )
37
+ }
38
+
39
+ function splitItemContent(contentLines: string[]): {
40
+ paragraphLines: string[]
41
+ blockLines: string[]
42
+ } {
43
+ const paragraphLines: string[] = []
44
+ const blockLines: string[] = []
45
+ let reachedBlockBoundary = false
46
+
47
+ contentLines.forEach(line => {
48
+ if (reachedBlockBoundary) {
49
+ blockLines.push(line)
50
+ return
51
+ }
52
+
53
+ if (line.trim() === '') {
54
+ reachedBlockBoundary = true
55
+ blockLines.push(line)
56
+ return
57
+ }
58
+
59
+ if (paragraphLines.length > 0 && isBlockContentLine(line)) {
60
+ reachedBlockBoundary = true
61
+ blockLines.push(line)
62
+ return
63
+ }
64
+
65
+ paragraphLines.push(line)
66
+ })
67
+
68
+ return {
69
+ paragraphLines,
70
+ blockLines,
71
+ }
72
+ }
73
+
26
74
  /**
27
75
  * Collects all ordered list items from lines, parsing them into a flat array
28
76
  * with indentation information. Stops collecting continuation content when
@@ -46,9 +94,10 @@ export function collectOrderedListItems(lines: string[]): [OrderedListItem[], nu
46
94
 
47
95
  const [, indent, number, content] = match
48
96
  const indentLevel = indent.length
49
- let itemContent = content
97
+ const itemContentLines = [content]
50
98
  let nextLineIndex = currentLineIndex + 1
51
99
  const itemLines = [line]
100
+ let sawBlankLine = false
52
101
 
53
102
  // Collect continuation lines for this item (but NOT nested list items)
54
103
  while (nextLineIndex < lines.length) {
@@ -64,23 +113,30 @@ export function collectOrderedListItems(lines: string[]): [OrderedListItem[], nu
64
113
  if (nextLine.trim() === '') {
65
114
  // Empty line
66
115
  itemLines.push(nextLine)
67
- itemContent += '\n'
116
+ itemContentLines.push('')
117
+ sawBlankLine = true
68
118
  nextLineIndex += 1
69
119
  } else if (nextLine.match(INDENTED_LINE_REGEX)) {
70
120
  // Indented content - part of this item (but not a list item)
71
121
  itemLines.push(nextLine)
72
- itemContent += `\n${nextLine.slice(indentLevel + 2)}` // Remove list marker indent
122
+ itemContentLines.push(nextLine.slice(indentLevel + 2))
73
123
  nextLineIndex += 1
74
124
  } else {
75
- // Non-indented line means end of list
76
- break
125
+ if (sawBlankLine) {
126
+ break
127
+ }
128
+
129
+ itemLines.push(nextLine)
130
+ itemContentLines.push(nextLine)
131
+ nextLineIndex += 1
77
132
  }
78
133
  }
79
134
 
80
135
  listItems.push({
81
136
  indent: indentLevel,
82
137
  number: parseInt(number, 10),
83
- content: itemContent.trim(),
138
+ content: itemContentLines.join('\n').trim(),
139
+ contentLines: itemContentLines,
84
140
  raw: itemLines.join('\n'),
85
141
  })
86
142
 
@@ -114,8 +170,8 @@ export function buildNestedStructure(
114
170
 
115
171
  if (item.indent === baseIndent) {
116
172
  // This item belongs at the current level
117
- const contentLines = item.content.split('\n')
118
- const mainText = contentLines[0]?.trim() || ''
173
+ const { paragraphLines, blockLines } = splitItemContent(item.contentLines)
174
+ const mainText = paragraphLines.join('\n').trim()
119
175
 
120
176
  const tokens = []
121
177
 
@@ -128,10 +184,8 @@ export function buildNestedStructure(
128
184
  })
129
185
  }
130
186
 
131
- // Handle additional content after the main text
132
- const additionalContent = contentLines.slice(1).join('\n').trim()
187
+ const additionalContent = blockLines.join('\n').trim()
133
188
  if (additionalContent) {
134
- // Parse as block tokens (handles mixed unordered lists, etc.)
135
189
  const blockTokens = lexer.blockTokens(additionalContent)
136
190
  tokens.push(...blockTokens)
137
191
  }