Files
max-richter.dev/src/helpers/markdownToText.ts
Max Richter 93c00e1c7e
Some checks failed
Deploy to SFTP Server / build (push) Failing after 3m7s
fix: handle of markdownTextTs receives null
2025-10-22 13:37:29 +02:00

28 lines
722 B
TypeScript

import MarkdownIt from "markdown-it";
const parser = new MarkdownIt();
export default function markdownToText(markdown: string): string {
if(!markdown) return ''
return parser
.render(markdown)
.split("\n")
.map((str) => str.trim())
.map((str) => {
return str.replace(/<\/?[^>]+(>|$)/g, "").split("\n");
})
.flat()
.filter((str) =>
!str.startsWith("import") &&
!str.startsWith("export") &&
!str.startsWith("#") &&
!str.startsWith("const") &&
!str.startsWith("function") &&
!str.startsWith("export") &&
!str.startsWith("import") &&
!str.startsWith("&lt;") &&
!str.startsWith("let") &&
str.length > 0
)
.join(" ");
}