From 15f3c7b8306afa0db02499ff8a5c6cfbebb3cb46 Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Mon, 16 Sep 2024 11:24:54 +0200 Subject: [PATCH] revert package.json changes, replace markdown in util --- package.json | 3 +-- src/lib/utils/post-utils.ts | 17 +++++++++++++++++ .../popular-threads-box/popular-threads-box.tsx | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8b07bf74..fa1ec20d 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,8 @@ "rehype-sanitize": "5.0.1", "remark-gfm": "3.0.1", "remark-supersub": "1.0.0", - "remove-markdown": "0.5.5", "tcp-port-used": "1.0.2", - "typescript": "4.9.5", + "typescript": "5.2.2", "zustand": "4.4.3" }, "scripts": { diff --git a/src/lib/utils/post-utils.ts b/src/lib/utils/post-utils.ts index 01dcee51..76dfeb75 100644 --- a/src/lib/utils/post-utils.ts +++ b/src/lib/utils/post-utils.ts @@ -37,3 +37,20 @@ export const formatMarkdown = (content: string): string => { } return md; }; + +export function removeMarkdown(md: string): string { + return md + .replace(/\[([^\]]*?)\][\[\(].*?[\]\)]/g, '$1') // Remove links + .replace(/[*_~`]/g, '') // Remove emphasis and code markers + .replace(/^#+\s*(.+)$/gm, '$1') // Remove headers + .replace(/^\s*[-*+]\s+/gm, '') // Remove list markers + .replace(/^\s*>\s+/gm, '') // Remove blockquotes + .replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, '') // Remove reference-style links + .replace(/^(\n)?\s{0,}#{1,6}\s*( (.+))? +#+$|^(\n)?\s{0,}#{1,6}\s*( (.+))?$/gm, '$1$3$4$6') // Remove atx-style headers + .replace(/([\*]+)(\S)(.*?\S)??\1/g, '$2$3') // Remove * emphasis + .replace(/(^|\W)([_]+)(\S)(.*?\S)??\2($|\W)/g, '$1$3$4$5') // Remove _ emphasis + .replace(/(`{3,})(.*?)\1/gm, '$2') // Remove code blocks + .replace(/`(.+?)`/g, '$1') // Remove inline code + .replace(/~(.*?)~/g, '$1') // Remove strike through + .trim(); +} diff --git a/src/views/home/popular-threads-box/popular-threads-box.tsx b/src/views/home/popular-threads-box/popular-threads-box.tsx index 8059a286..80da3f6a 100644 --- a/src/views/home/popular-threads-box/popular-threads-box.tsx +++ b/src/views/home/popular-threads-box/popular-threads-box.tsx @@ -10,7 +10,7 @@ import { CatalogPostMedia } from '../../../components/catalog-row'; import LoadingEllipsis from '../../../components/loading-ellipsis'; import BoxModal from '../box-modal'; import { nsfwTags } from '../home'; -import removeMarkdown from 'remove-markdown'; +import { removeMarkdown } from '../../../lib/utils/post-utils'; interface PopularThreadProps { post: Comment;