From 002d0488faf7f80e8f0d5b2d51374e47a369fe51 Mon Sep 17 00:00:00 2001 From: KUN1007 Date: Mon, 27 Nov 2023 17:06:24 +0800 Subject: [PATCH] pref: markdownToText --- src/utils/markdownToText.ts | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/utils/markdownToText.ts b/src/utils/markdownToText.ts index 1e4fa05f..17c8f95c 100644 --- a/src/utils/markdownToText.ts +++ b/src/utils/markdownToText.ts @@ -1,29 +1,9 @@ export const markdownToText = (markdown: string) => { return markdown - .replace(/^(-\s*?|\*\s*?|_\s*?){3,}\s*$/gm, '') - .replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, ' $1') - .replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, '$1') - .replace(/\n={2,}/g, '\n') - .replace(/~{3}.*\n/g, '') - .replace(/~~/g, '') - .replace(/`{3}.*\n/g, '') - .replace(/\[(.*?)\][\[\(](.*?)[\]\)]/g, '$1 ($2)') - .replace(/<[^>]*>/g, '') - .replace(/^[=\-]{2,}\s*$/g, '') - .replace(/\[\^.+?\](\: .*?$)?/g, '') - .replace(/\s{0,2}\[.*?\]: .*?$/g, '') - .replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, '$1') - .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1') - .replace(/^\s{0,3}>\s?/g, '') - .replace(/(^|\n)\s{0,3}>\s?/g, '\n\n') - .replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, '') - .replace( - /^(\n)?\s{0,}#{1,6}\s+| {0,}(\n)?\s{0,}#{0,} {0,}(\n)?\s{0,}$/gm, - '$1$2$3' - ) - .replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2') - .replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2') - .replace(/(`{3,})(.*?)\1/gm, '$2') - .replace(/`(.+?)`/g, '$1') - .replace(/\n{2,}/g, '\n\n') + .replace(/(\*\*|__)(.*?)\1/gs, '$2') + .replace(/(\*|_)(.*?)\1/gs, '$2') + .replace(/#+\s*(.*?)\n/g, '$1\n') + .replace(/!?\[(.*?)\]\(.*?\)/gs, '$1') + .replace(/`([^`]+)`/g, '$1') + .replace(/```[\s\S]+?```/gs, '') }