| 2 | import { makeId } from '../../../nestjs-libraries/src/services/make.is'; |
| 3 | |
| 4 | export 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 | }; |