mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 04:01:05 +00:00
Fixes #46185. Verified: - pnpm install --frozen-lockfile - pnpm build - pnpm test -- extensions/line/src/markdown-to-line.test.ts src/tts/prepare-text.test.ts Note: `pnpm check` currently fails on unchanged `extensions/microsoft/speech-provider.test.ts` lines 108 and 139 on the rebased base, outside this PR diff.
23 lines
797 B
TypeScript
23 lines
797 B
TypeScript
/**
|
|
* Strip lightweight markdown formatting from text while preserving readable
|
|
* plain-text structure for TTS and channel fallbacks.
|
|
*/
|
|
export function stripMarkdown(text: string): string {
|
|
let result = text;
|
|
|
|
result = result.replace(/\*\*(.+?)\*\*/g, "$1");
|
|
result = result.replace(/__(.+?)__/g, "$1");
|
|
|
|
result = result.replace(/(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)/g, "$1");
|
|
result = result.replace(/(?<![\p{L}\p{N}])_(?!_)(.+?)(?<!_)_(?![\p{L}\p{N}])/gu, "$1");
|
|
|
|
result = result.replace(/~~(.+?)~~/g, "$1");
|
|
result = result.replace(/^#{1,6}\s+(.+)$/gm, "$1");
|
|
result = result.replace(/^>\s?(.*)$/gm, "$1");
|
|
result = result.replace(/^[-*_]{3,}$/gm, "");
|
|
result = result.replace(/`([^`]+)`/g, "$1");
|
|
result = result.replace(/\n{3,}/g, "\n\n");
|
|
|
|
return result.trim();
|
|
}
|