* Strips Markdown formatting to produce plain text.
(md: string)
| 14 | * Strips Markdown formatting to produce plain text. |
| 15 | */ |
| 16 | function markdownToPlainText(md: string): string { |
| 17 | let text = md |
| 18 | .replace(/!\[.*?\]\(.*?\)/g, '') // images |
| 19 | .replace(/\[([^\]]*)\]\(.*?\)/g, '$1') // links |
| 20 | .replace(/#{1,6}\s+/g, '') // headings |
| 21 | .replace(/(\*\*|__)(.*?)\1/g, '$2') // bold |
| 22 | .replace(/(\*|_)(.*?)\1/g, '$2') // italic |
| 23 | .replace(/~~(.*?)~~/g, '$1') // strikethrough |
| 24 | .replace(/`{3}[\s\S]*?`{3}/g, '') // code blocks |
| 25 | .replace(/`([^`]*)`/g, '$1') // inline code |
| 26 | .replace(/^\s*[-*+]\s+/gm, '') // list items |
| 27 | .replace(/^\s*\d+\.\s+/gm, '') // ordered list items |
| 28 | .replace(/^\s*>\s+/gm, '') // blockquotes |
| 29 | .replace(/---+/g, '') // horizontal rules |
| 30 | text = text.replace(/\s+/g, ' ').trim() |
| 31 | return text |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Executes a GraphQL query against the Linear API. |
no test coverage detected