MCPcopy
hub / github.com/gitroomhq/postiz-app / removeMarkdown

Function removeMarkdown

libraries/helpers/src/utils/remove.markdown.ts:4–28  ·  view source on GitHub ↗
(params: { text: string; except?: RegExp[] })

Source from the content-addressed store, hash-verified

2import { makeId } from '../../../nestjs-libraries/src/services/make.is';
3
4export const removeMarkdown = (params: { text: string; except?: RegExp[] }) => {
5 let modifiedText = params.text;
6 const except = params.except || [];
7 const placeholders: { [key: string]: string } = {};
8
9 // Step 2: Replace exceptions with placeholders
10 except.forEach((regexp, index) => {
11 modifiedText = modifiedText.replace(regexp, (match) => {
12 const placeholder = `[[EXCEPT_PLACEHOLDER_${makeId(5)}]]`;
13 placeholders[placeholder] = match;
14 return placeholder;
15 });
16 });
17
18 // Step 3: Remove markdown from modified text
19 // Assuming removeMd is the function that removes markdown
20 const cleanedText = removeMd(modifiedText);
21
22 // Step 4: Replace placeholders with original text
23 const finalText = Object.keys(placeholders).reduce((text, placeholder) => {
24 return text.replace(placeholder, placeholders[placeholder]);
25 }, cleanedText);
26
27 return finalText;
28};

Callers

nothing calls this directly

Calls 1

makeIdFunction · 0.90

Tested by

no test coverage detected