24 lines
882 B
TypeScript
24 lines
882 B
TypeScript
export function parseEditPasses(text: string): string[] | null {
|
|
const src = String(text || '').replace(/\r\n/g, '\n')
|
|
const marker = /^[ \t]*---pass\s+(\d+)---[ \t]*$/gim
|
|
const markers = [...src.matchAll(marker)]
|
|
if (!markers.length) return null
|
|
const parts: string[] = []
|
|
const preamble = src.slice(0, markers[0].index || 0).trim()
|
|
for (let i = 0; i < markers.length; i++) {
|
|
const from = (markers[i].index || 0) + markers[i][0].length
|
|
const to = i + 1 < markers.length ? (markers[i + 1].index || src.length) : src.length
|
|
const body = src.slice(from, to).trim()
|
|
if (body) parts.push(body)
|
|
}
|
|
if (!parts.length) return null
|
|
if (preamble && preamble.length > 40) {
|
|
parts[0] = `${preamble}\n\n${parts[0]}`
|
|
}
|
|
return parts
|
|
}
|
|
|
|
export function looksLikeShotScript(text: string) {
|
|
return /^[ \t]*shot\s+[2-9]\d*\b/im.test(String(text || ''))
|
|
}
|