@tiptap/extension-list 3.27.2 → 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.
@@ -40,10 +40,15 @@ export const ORDERED_LIST_LINE_START_REGEX = new RegExp(
40
40
  const INDENTED_LINE_REGEX = /^\s/
41
41
 
42
42
  /**
43
- * Matches heading lines (1-6 # characters followed by whitespace or end-of-line)
44
- * Heading lines always starts a new block, so they can never be lazy continuation text of a list item
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
45
  */
46
- const HEADING_LINE_REGEX = /^#{1,6}(?:\s|$)/
46
+ const PARAGRAPH_INTERRUPTERS = {
47
+ heading: /^#{1,6}(?:\s|$)/,
48
+ bulletItem: /^[-+*]\s+/,
49
+ codeFence: /^(?:```|~~~)/,
50
+ thematicBreak: /^(?:(?:-[ \t]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})$/,
51
+ }
47
52
 
48
53
  /**
49
54
  * Represents a parsed ordered list item with indentation information
@@ -65,19 +70,22 @@ function isBlockContentLine(line: string): boolean {
65
70
  const trimmedLine = line.trimStart()
66
71
 
67
72
  return (
68
- // oxlint-disable-next-line prefer-string-starts-ends-with
69
- /^[-+*]\s+/.test(trimmedLine) ||
73
+ PARAGRAPH_INTERRUPTERS.bulletItem.test(trimmedLine) ||
70
74
  isOrderedListMarkerLine(trimmedLine) ||
71
- HEADING_LINE_REGEX.test(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('-')) ||
72
79
  // oxlint-disable-next-line prefer-string-starts-ends-with
73
80
  /^>\s?/.test(trimmedLine) ||
74
- // oxlint-disable-next-line prefer-string-starts-ends-with
75
- /^```/.test(trimmedLine) ||
76
- // oxlint-disable-next-line prefer-string-starts-ends-with
77
- /^~~~/.test(trimmedLine)
81
+ PARAGRAPH_INTERRUPTERS.codeFence.test(trimmedLine)
78
82
  )
79
83
  }
80
84
 
85
+ function interruptsLazyContinuation(line: string): boolean {
86
+ return Object.values(PARAGRAPH_INTERRUPTERS).some(pattern => pattern.test(line))
87
+ }
88
+
81
89
  function splitItemContent(contentLines: string[]): {
82
90
  paragraphLines: string[]
83
91
  blockLines: string[]
@@ -173,7 +181,7 @@ export function collectOrderedListItems(lines: string[]): [OrderedListItem[], nu
173
181
  itemContentLines.push(nextLine.slice(Math.min(leadingWhitespace, contentIndent)))
174
182
  nextLineIndex += 1
175
183
  } else {
176
- if (sawBlankLine || HEADING_LINE_REGEX.test(nextLine)) {
184
+ if (sawBlankLine || interruptsLazyContinuation(nextLine)) {
177
185
  break
178
186
  }
179
187