b2d2babbb9
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>
25 lines
563 B
TypeScript
25 lines
563 B
TypeScript
import Handlebars from 'handlebars';
|
|
|
|
export 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;
|
|
}
|
|
};
|