Pre-process a text field before the API delivers it

Hi, is there a way to pre-process a data field before the API delivers it?

I would like to replace and insert some HTML code in a text field that was edited with markdown.

Thanks!

You can try scripting: https://docs.squidex.io/guides/06-scripting

Thanks Sebastian. So I can use the “query” event, great!

Is it javascript?
How do I know which commands are available and how they work? like replace, disallow and reject.

Its javascript, yes. Only the 3 commands from the docs are relevant and supported.

I’m testing the replace funtion but it seems I don’t understand its use.

Is this right for replacing all newlines with a BR?

if (ctx.isClient) {
    ctx.data.descripcion.es = ctx.data.descripcion.es.replace(/\n/gm,"</br>");
    replace();
}

Yes, it should work, but you do not need the “isClient”. I can prepare a sample later. Which script do you edit?

I tried something simpler, just replace all “a” for “A”, but it’s not working. I’m using the “Query” event.

image

Is your field localizable?

I tried a schema with a string and a number field and this works for me:

ctx.data.test.iv = ctx.data.test.iv + 5;
ctx.data.description.iv = ctx.data.description.iv.replace(/a/gm, "A");
replace();