gallery.badmanners.xyz/src/utils/to_plain_markdown.ts

5 lines
233 B
TypeScript

/**
* Replaces HTML in Markdown text with its simplified representation.
*/
export const toPlainMarkdown = (text: string) =>
text.replaceAll(/<\s*a(?:\s+\S+)*(?:\s+href="([^"]+)")(?:\s+\S+)*\s*>\s*([^<]+)\s*<\/a>/g, "[$2]($1)");