2
0

🐛 (editor) Allow variables in bubble text links

This commit is contained in:
Baptiste Arnaud
2023-02-10 09:27:16 +01:00
parent c386bb5a08
commit 2dbf0fb848
2 changed files with 14 additions and 9 deletions

View File

@ -27,7 +27,8 @@ export const platePlugins = createPlugins(
url.startsWith('https:') || url.startsWith('https:') ||
url.startsWith('mailto:') || url.startsWith('mailto:') ||
url.startsWith('tel:') || url.startsWith('tel:') ||
url.startsWith('sms:'), url.startsWith('sms:') ||
(url.startsWith('{{') && url.endsWith('}}')),
}, },
}), }),
], ],

View File

@ -48,7 +48,10 @@ export const blockHasOptions = (block: Block) => 'options' in block
export const parseVariableHighlight = (content: string, typebot: Typebot) => { export const parseVariableHighlight = (content: string, typebot: Typebot) => {
const varNames = typebot.variables.map((v) => v.name) const varNames = typebot.variables.map((v) => v.name)
return content.replace(/\{\{(.*?)\}\}/g, (fullMatch, foundVar) => { console.log(content)
return content.replace(
new RegExp(`(?<!href="){{(${varNames.join('|')})}}`, 'g'),
(fullMatch, foundVar) => {
if (varNames.some((val) => foundVar === val)) { if (varNames.some((val) => foundVar === val)) {
return `<span style="background-color:#ff8b1a; color:#ffffff; padding: 0.125rem 0.25rem; border-radius: 0.35rem">${fullMatch.replace( return `<span style="background-color:#ff8b1a; color:#ffffff; padding: 0.125rem 0.25rem; border-radius: 0.35rem">${fullMatch.replace(
/{{|}}/g, /{{|}}/g,
@ -56,7 +59,8 @@ export const parseVariableHighlight = (content: string, typebot: Typebot) => {
)}</span>` )}</span>`
} }
return fullMatch return fullMatch
}) }
)
} }
export const setMultipleRefs = export const setMultipleRefs =