mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 05:30:21 +00:00
refactor(plugins): finish provider and whatsapp cleanup
This commit is contained in:
22
src/shared/text/strip-markdown.ts
Normal file
22
src/shared/text/strip-markdown.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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(/(?<!_)_(?!_)(.+?)(?<!_)_(?!_)/g, "$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();
|
||||
}
|
||||
Reference in New Issue
Block a user