blocks into the preceding paragraph (marked splits on newlines). */ export function collapseStandaloneCitationParagraphs(html: string): string { if (!html || !html.includes('citation')) return html const mergePattern = new RegExp( `(<\\/(?:p|li)>)\\s*(?:
\\s*<\\/p>\\s*)*
\\s*(${CITATION_HTML_FRAGMENT})\\s*<\\/p>`,
'g',
)
let result = html
let prev = ''
while (result !== prev) {
prev = result
result = result.replace(mergePattern, (_match, closeTag: string, citation: string) => {
return ` ${citation}${closeTag}`
})
}
return result
}
/** Preserve raw