pref: markdownToText
This commit is contained in:
parent
e592ae592d
commit
002d0488fa
|
@ -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, '')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue