diff --git a/frontend/src/components/v2/SecretInput/SecretInput.tsx b/frontend/src/components/v2/SecretInput/SecretInput.tsx index 314dada0c..2dfafca74 100644 --- a/frontend/src/components/v2/SecretInput/SecretInput.tsx +++ b/frontend/src/components/v2/SecretInput/SecretInput.tsx @@ -1,43 +1,46 @@ /* eslint-disable react/no-danger */ import { forwardRef, TextareaHTMLAttributes } from "react"; -import sanitizeHtml, { DisallowedTagsModes } from "sanitize-html"; import { twMerge } from "tailwind-merge"; import { useToggle } from "@app/hooks"; -const REGEX = /\${([^}]+)}/g; +const REGEX = /(\${([^}]+)})/g; const replaceContentWithDot = (str: string) => { let finalStr = ""; for (let i = 0; i < str.length; i += 1) { const char = str.at(i); - finalStr += char === "\n" ? "\n" : "•"; + finalStr += char === "\n" ? "\n" : "*"; } return finalStr; }; -const sanitizeConf = { - allowedTags: ["span"], - disallowedTagsMode: "escape" as DisallowedTagsModes -}; - const syntaxHighlight = (content?: string | null, isVisible?: boolean) => { if (content === "") return "EMPTY"; if (!content) return "EMPTY"; if (!isVisible) return replaceContentWithDot(content); - const sanitizedContent = sanitizeHtml( - content.replaceAll("<", "<").replaceAll(">", ">"), - sanitizeConf - ); - const newContent = sanitizedContent.replace( - REGEX, - (_a, b) => - `${${b}}` - ); + let skipNext = false; + const formatedContent = content.split(REGEX).flatMap((el, i) => { + const isInterpolationSyntax = el.startsWith("${") && el.endsWith("}"); + if (isInterpolationSyntax) { + skipNext = true; + return ( + + ${{el.slice(2, -1)} + } + + ); + } + if (skipNext) { + skipNext = false; + return []; + } + return el; + }); // akhilmhdh: Dont remove this br. I am still clueless how this works but weirdly enough // when break is added a line break works properly - return `${newContent}
`; + return formatedContent.concat(
); }; type Props = TextareaHTMLAttributes & { @@ -59,18 +62,15 @@ export const SecretInput = forwardRef( return (
             
-              
+              
+                {syntaxHighlight(value, isVisible || isSecretFocused)}
+