refactor: simplify parse ingredients code

This commit is contained in:
2025-01-19 19:22:19 +01:00
parent f106460502
commit 78e94ccf82
14 changed files with 201 additions and 137 deletions

View File

@@ -133,3 +133,41 @@ export function parseTimeCacheKey(key: string) {
export function rgbToHex(r: number, g: number, b: number) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
export function removeMarkdownFormatting(text: string): string {
// Remove code blocks
text = text.replace(/```[\s\S]*?```/g, "");
// Remove inline code
text = text.replace(/`([^`]+)`/g, "$1");
// Remove images
text = text.replace(/!\[.*?\]\(.*?\)/g, "");
// Remove links
text = text.replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1");
// Remove bold and italic formatting
text = text.replace(/(\*\*|__)(.*?)\1/g, "$2"); // Bold
text = text.replace(/(\*|_)(.*?)\1/g, "$2"); // Italic
// Remove strikethrough
text = text.replace(/~~(.*?)~~/g, "$1");
// Remove headings
text = text.replace(/^#{1,6}\s*(.+)$/gm, "$1");
// Remove blockquotes
text = text.replace(/^>\s*/gm, "");
// Remove unordered list markers
text = text.replace(/^[-*+]\s+/gm, "-");
// Remove ordered list markers
text = text.replace(/^\d+\.\s+/gm, "");
// Remove horizontal rules
text = text.replace(/^---+$/gm, "");
return text;
}