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:
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user