Kirbytext() gives incorrect file path for embedded images

Hi, Iā€™m using Kirby as an API to serve JSON for a web-app.

My API is a top-level page. I get pages based on the request path, then I loop through the content fields as an array and apply kirbytext() to textarea fields like so :

foreach($page->content($lang)->toArray() as $key => $value) {
   if (strpos($key, '_html') !== false) $value = kirbytext($value);
   ...
}

But the output just uses the site root for the image path :frowning:

<figure><img src=\"http://127.0.0.1:8010/bears.png\" alt=\"\"></figure>

Kirby Info:

Toolkit version: 2.5.1
Kirby version: 2.5.1
Panel version: 2.5.1

Ok, looks like the toArray() causes the issue. It has the correct path with $page->text_html()->kirbytext()

Just a hunch but you probably have to turn the image to a file first.

Oh i just realised you mean an image inside markdown.

Thanks @jimbobrjames, I managed to get it to work with the following:

$fields = $page->content()->toArray();
foreach($fields as $key => $value) { 
   if (strpos($key, '_html') !== false) $value = kirbytext($page->content()->get($key));
   ...
}

Might be a more elegant solution out there