diff --git a/markdownPreview/src/index.tsx b/markdownPreview/src/index.tsx index eff1911..064a2bc 100644 --- a/markdownPreview/src/index.tsx +++ b/markdownPreview/src/index.tsx @@ -14,7 +14,12 @@ import { createRoot } from "react-dom/client"; import App from "./components/App"; -function init() { +const init = () => { + let allElements = Array.from(document.querySelectorAll("*")); + // Checks if the markdown contains any taipy elements + if (!allElements.some((el) => el.tagName.toLowerCase().startsWith("taipy"))) { + return; + } const mdbd = document.getElementsByClassName("markdown-body"); const markdownBodyHTML = mdbd[mdbd.length - 1].outerHTML; mdbd[mdbd.length - 1].remove(); @@ -27,8 +32,17 @@ function init() { } rootDiv.innerHTML = ""; const root = createRoot(rootDiv); - root.render(); -} + root.render(); +}; + +// Regular expression to find curly braces outside of HTML tags +const replaceCurlyBracesRegex = /(?:\{[^}]*\})(?![^<]*>)/g; +const replaceCurlyBraces = (match: string) => { + return match.replace(/{/g, "{").replace(/}/g, "}"); +}; +const formatHtmlBody = (html: string) => { + return html.replace(replaceCurlyBracesRegex, replaceCurlyBraces); +}; window.addEventListener("vscode.markdown.updateContent", init);