Add pattern for variable tag in tiptap (#16652)

Since we now store rich text value in blocknote rather than markdown,
variables need to be resolved accordingly.

Replacing the variable tag pattern
`{"type":"variableTag","attrs":\{"variable":"(\{\{[^{}]+\}\})"\}\}` by a
blocknote text `{"type":"text","text":"${escapedText}"}`

Fixes https://github.com/twentyhq/twenty/issues/16583

To test :
- build a workflow that creates a note/ sends an email with a variable
in the body
- make sure the result is properly formatted once run

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
This commit is contained in:
Thomas Trompette
2025-12-18 17:24:13 +01:00
committed by GitHub
co-authored by cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
parent 636cec0f59
commit b2d2babbb9
11 changed files with 429 additions and 55 deletions
@@ -1,10 +1,7 @@
import Handlebars from 'handlebars';
import { evalFromContext } from '@/utils/evalFromContext';
import { isDefined } from '@/utils/validation';
const isNil = (value: any): value is null | undefined => {
return value === null || value === undefined;
};
const isString = (value: any): value is string => {
const isString = (value: unknown): value is string => {
return typeof value === 'string';
};
@@ -14,7 +11,7 @@ export const resolveInput = (
unresolvedInput: unknown,
context: Record<string, unknown>,
): unknown => {
if (isNil(unresolvedInput)) {
if (!isDefined(unresolvedInput)) {
return unresolvedInput;
}
@@ -84,23 +81,3 @@ const resolveString = (
return processedToken;
});
};
const evalFromContext = (input: string, context: Record<string, unknown>) => {
try {
Handlebars.registerHelper('json', (input: string) => JSON.stringify(input));
const inputWithHelper = input
.replace('{{', '{{{ json ')
.replace('}}', ' }}}');
const inferredInput = Handlebars.compile(inputWithHelper)(context, {
helpers: {
json: (input: string) => JSON.stringify(input),
},
});
return JSON.parse(inferredInput);
} catch {
return undefined;
}
};