* feat(ui-chat,ui-conversation): 通过通用文本交互支持原文引用 * refactor(message-quotes): 插件化引用交互与文本扫描豁免 * test(message-quotes): 补齐插件装配预期与交互分发覆盖 * refactor(ui-conversation): 移除引用删除文案的语言切换刷新 * refactor(message-quotes): 移除引用扫描豁免并收窄文本交互接口 * fix(ui-chat): 修复引用浮层的滚动遮挡与恢复 * fix(ui-chat): 对齐 master 的聊天流注入与界面快照 * test(message-quotes): 补齐 Host 入口覆盖并固定子会话回放时序 * refactor(message-quotes): 清理文本依赖特例并修正引用按钮 * fix(ui-primitives): 让引用原文弹层按内容收缩 * fix(ui-primitives): 修复相邻引用悬停弹层重叠与误切换 * fix(message-quotes): 为引用悬停样式限定设备能力 --------- Co-authored-by: lsdsjy <[email protected]>
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
/** Explicit blockquote recognition and decoding for quote presentation. */
|
|
|
|
/**
|
|
* Remove one blockquote marker from each explicitly quoted line.
|
|
* @param text - consecutive blockquote lines, with up to three leading spaces.
|
|
* @returns excerpt text with original line endings normalized.
|
|
*/
|
|
export function quoteTextOf(text: string): string {
|
|
return text.replace(/\r\n?/gu, '\n').replace(/^ {0,3}>[ \t]?/gmu, '')
|
|
}
|
|
|
|
/** One blockquote span in original UTF-16 text, excluding its trailing line break. */
|
|
export interface MessageQuoteRange {
|
|
readonly start: number
|
|
readonly end: number
|
|
}
|
|
|
|
/**
|
|
* Recognize consecutive explicitly marked Markdown blockquote lines.
|
|
* @param text - complete original message text.
|
|
* @returns ordered nonblank quote spans; inline greater-than signs remain ordinary text.
|
|
*/
|
|
export function messageQuoteRanges(text: string): readonly MessageQuoteRange[] {
|
|
const ranges: MessageQuoteRange[] = []
|
|
for (const match of text.matchAll(/^ {0,3}>[^\r\n]*(?:\r?\n {0,3}>[^\r\n]*)*/gmu)) {
|
|
if (quoteTextOf(match[0]).trim() !== '') ranges.push({ start: match.index, end: match.index + match[0].length })
|
|
}
|
|
return ranges
|
|
}
|