How to replace custom kirbytags with standard ones?

Hi, I’m currently using my own custom kirbytags for embedding images and videos in the textarea fields.

Now, switching to the Kirby Editor, I’ve seen that my custom tags are not automagically converted, so I wonder which is the best way to programmatically replace my custom tags with the standard ones.

Example:
I’m using (img:…) and (imgsmall:…) for images, (yt:…) and (ytsmall: …) for videos.
Now I need to replace

  • (img: …) with (image: … class: img-medium)
  • (imgsmall: …) with (image: … class: img-small)
    etc.

Any help??
Thanx in advance!

You could update the fields in question programmatically, while doing a regex search and replace on each field that may be concerned.

Thank, this is also the solution I came up with. Just wondering if there was something more “elegant”. Thank you.

$longs = $pages->find('lungo')->children();

foreach ($longs as $l) 

{

    $t = '';

    $t = Str::replace($l->text(), '(imgsmall:', '(image:');

    $t = Str::replace($t, '(img:', '(image:');

    $t = Str::replace($t, '(yt:', '(video:');

    $t = Str::replace($t, '(ytsmall:', '(video:');

    $t = Str::replace($t, '(video: ', '(video:https://www.youtube.com/embed/');

    $l->update(array(

        'text' => $t)

    );

    echo $l->title() . '<br>';

}

This could certainly be reduced a bit but since you only have to do it once, it doesn’t really matter.