Answer the stability review: a code or HTML block swallows the marker line too
CI / gate (push) Successful in 4s
CI / gate (push) Successful in 4s
This commit is contained in:
@@ -16,10 +16,11 @@ const atxHeadingOpener = /^(#{1,6})(?:[ \t]|$)/
|
||||
const codeFenceOpener = /^(`{3,}|~{3,})/
|
||||
const directiveClaim = /^:{2,}(?:[A-Za-z0-9]|[ \t]*$)/
|
||||
const pipeClaim = /^\|/
|
||||
const bulletListOpener = /^[*+-](?:[ \t]|$)/
|
||||
// A superset of what the parser claims: over-escaping a line is safe, under-escaping one breaks the round-trip.
|
||||
const firstCharacterOpeners = [atxHeadingOpener, /^>/, /^[*+-](?:[ \t]|$)/, codeFenceOpener, /^:{2,}/, pipeClaim]
|
||||
const firstCharacterOpeners = [atxHeadingOpener, /^>/, bulletListOpener, codeFenceOpener, /^:{2,}/, pipeClaim]
|
||||
const htmlConstructs = [/^<[!?]/, /^<\/?[A-Za-z][A-Za-z0-9-]*(?:[\s/>]|$)/, /^<[^\s<>@]+@[^\s<>@]+>/]
|
||||
const orderedListOpener = /^(\d{1,9})[.)](?:[ \t]|$)/
|
||||
const orderedListOpener = /^(\d{1,9})([.)])(?:[ \t]|$)/
|
||||
const setextUnderline = /^(=+|-+)[ \t]*$/
|
||||
const thematicBreak = /^(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/
|
||||
const unicodeWhitespace = /[\t\n\f\r \p{Zs}]/u
|
||||
@@ -86,8 +87,16 @@ export function isUnicodeWhitespace(character: string): boolean {
|
||||
return unicodeWhitespace.test(character)
|
||||
}
|
||||
|
||||
// The first marker of a list, `undefined` for a bullet: one answer both directions read, or the emitter
|
||||
// spells a list the parser folds into the paragraph above it.
|
||||
// `start` is the list's first number, `undefined` for a bullet.
|
||||
export function listMarker(line: string): { delimiter: string; start: number | undefined; width: number } | undefined {
|
||||
const ordered = orderedListOpener.exec(line)
|
||||
if (ordered !== null) {
|
||||
const digits = ordered[1] ?? ''
|
||||
return { delimiter: ordered[2] ?? '', start: Number(digits), width: digits.length + 1 }
|
||||
}
|
||||
return bulletListOpener.test(line) ? { delimiter: line.charAt(0), start: undefined, width: 1 } : undefined
|
||||
}
|
||||
|
||||
export function markerInterruptsParagraph(start: number | undefined, empty: boolean): boolean {
|
||||
return !empty && (start === undefined || start === 1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user