From 2dbf0fb848ea5d8ea427c0a68ad57ba1e4b099a6 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 10 Feb 2023 09:27:16 +0100 Subject: [PATCH] :bug: (editor) Allow variables in bubble text links --- apps/builder/src/lib/plate.tsx | 3 ++- apps/builder/src/utils/helpers.ts | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/builder/src/lib/plate.tsx b/apps/builder/src/lib/plate.tsx index a2b45c307..713055db3 100644 --- a/apps/builder/src/lib/plate.tsx +++ b/apps/builder/src/lib/plate.tsx @@ -27,7 +27,8 @@ export const platePlugins = createPlugins( url.startsWith('https:') || url.startsWith('mailto:') || url.startsWith('tel:') || - url.startsWith('sms:'), + url.startsWith('sms:') || + (url.startsWith('{{') && url.endsWith('}}')), }, }), ], diff --git a/apps/builder/src/utils/helpers.ts b/apps/builder/src/utils/helpers.ts index 71ea7da4c..fb56ee4d7 100644 --- a/apps/builder/src/utils/helpers.ts +++ b/apps/builder/src/utils/helpers.ts @@ -48,15 +48,19 @@ export const blockHasOptions = (block: Block) => 'options' in block export const parseVariableHighlight = (content: string, typebot: Typebot) => { const varNames = typebot.variables.map((v) => v.name) - return content.replace(/\{\{(.*?)\}\}/g, (fullMatch, foundVar) => { - if (varNames.some((val) => foundVar === val)) { - return `${fullMatch.replace( - /{{|}}/g, - '' - )}` + console.log(content) + return content.replace( + new RegExp(`(? { + if (varNames.some((val) => foundVar === val)) { + return `${fullMatch.replace( + /{{|}}/g, + '' + )}` + } + return fullMatch } - return fullMatch - }) + ) } export const setMultipleRefs =