@tiptap/extension-list 3.27.1 → 3.27.3

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.
@@ -39,6 +39,17 @@ export const ORDERED_LIST_LINE_START_REGEX = new RegExp(
39
39
  */
40
40
  const INDENTED_LINE_REGEX = /^\s/
41
41
 
42
+ /**
43
+ * This are blocks that can interrupt a paragraph, so a line starting with one of
44
+ * them can never be lazy continuation text of a list item
45
+ */
46
+ const PARAGRAPH_INTERRUPTERS = {
47
+ heading: /^#{1,6}(?:\s|$)/,
48
+ bulletItem: /^[-+*]\s+/,
49
+ codeFence: /^(?:```|~~~)/,
50
+ thematicBreak: /^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/,
51
+ }
52
+
42
53
  /**
43
54
  * Represents a parsed ordered list item with indentation information
44
55
  */
@@ -59,18 +70,22 @@ function isBlockContentLine(line: string): boolean {
59
70
  const trimmedLine = line.trimStart()
60
71
 
61
72
  return (
62
- // oxlint-disable-next-line prefer-string-starts-ends-with
63
- /^[-+*]\s+/.test(trimmedLine) ||
73
+ PARAGRAPH_INTERRUPTERS.bulletItem.test(trimmedLine) ||
64
74
  isOrderedListMarkerLine(trimmedLine) ||
75
+ PARAGRAPH_INTERRUPTERS.heading.test(trimmedLine) ||
76
+ // dash breaks are excluded: "---" directly below paragraph text is a
77
+ // setext heading underline, not a thematic break
78
+ (PARAGRAPH_INTERRUPTERS.thematicBreak.test(trimmedLine) && !trimmedLine.startsWith('-')) ||
65
79
  // oxlint-disable-next-line prefer-string-starts-ends-with
66
80
  /^>\s?/.test(trimmedLine) ||
67
- // oxlint-disable-next-line prefer-string-starts-ends-with
68
- /^```/.test(trimmedLine) ||
69
- // oxlint-disable-next-line prefer-string-starts-ends-with
70
- /^~~~/.test(trimmedLine)
81
+ PARAGRAPH_INTERRUPTERS.codeFence.test(trimmedLine)
71
82
  )
72
83
  }
73
84
 
85
+ function interruptsLazyContinuation(line: string): boolean {
86
+ return Object.values(PARAGRAPH_INTERRUPTERS).some(pattern => pattern.test(line))
87
+ }
88
+
74
89
  function splitItemContent(contentLines: string[]): {
75
90
  paragraphLines: string[]
76
91
  blockLines: string[]
@@ -166,7 +181,7 @@ export function collectOrderedListItems(lines: string[]): [OrderedListItem[], nu
166
181
  itemContentLines.push(nextLine.slice(Math.min(leadingWhitespace, contentIndent)))
167
182
  nextLineIndex += 1
168
183
  } else {
169
- if (sawBlankLine) {
184
+ if (sawBlankLine || interruptsLazyContinuation(nextLine)) {
170
185
  break
171
186
  }
172
187