Can we replace a pattern, for ex: {{pattern}} anywhere in the visual editor or typed by the user in an input or paragraph with custom html or javascript

Can we replace a pattern, for ex: {{pattern}} anywhere in the visual editor or typed by the user in an input or paragraph with any HTML / javascript code which we need to add via Plugin?

Hi Soumya,

As for replacing any text on the page, you can use regex for this.
Take a look at this javascript code:
document.body.innerHTML = document.body.innerHTML.replace(/lorem/g, 'ipsum');

which changes all occurrences of lorem to ipsum

Refer to our docs on how to add custom code to your page

If there’s something more specific you want to do within the visual editor, please provide some more details (such as an example of what you want to do) so I can assist.

Thanks, but i was looking for some Builder code/api which could do this, i.e allow me to execute function and transform the text/content.

What do you mean by Builder code/api?

For the regex code I provided, you can use it directly in the editor, either by using a code block or by using the Add JS + CSS, which are both Builder features. The link to the docs I shared provides some more details.

Add JS + CSS has to be used in each page, i want something which i can execute for all page models / content.

Ah, I see. In that case, you might want to create your own Builder plugin. You would first need to create the plugin file and then use the Builder SDK to define and register it.

You can look at the docs on action shortcut plugins here: Intro to contributing plugins - Builder.io

Be sure to check out the example repo linked in that doc. If you need help with any steps, let me know :+1: