Hi!
So I’ve been trying to get ![alt](image-path)
to work, but the kirbytext()
and markdown()
functions don’t convert the relative path to the file to a path that points to the media folder. I’m not sure what to do, the only solution I could find here in the forum is for Kirby 2 and I don’t know how to adapt it to Kirby 3.
How can I use the ![alt](image)
MD-syntax for images, instead of the (image:) kt-syntax?
Would really appreciate some help here
Text: ![Alt text](about/table.jpg)
In a Starterkit, this works for me in the about page.
Updated, I made a mistake.
It works with absolute paths, but not with relative paths. Is there a way to make it work with relative paths?
I can use
![Bar-chart, description below.](/blog/2023/May/after-twitter/BARCHART-mastodon-use.png)
and get
<img src="/blog/2023/May/after-twitter/BARCHART-mastodon-use.png" alt="Bar-chart, description below.">
But using
![Bar-chart, description below.](BARCHART-mastodon-use.png)
doesn’t work. Kirby does not update the URL to the page’s path.
That’s right, this won’t work, you need the full path to the file.
Ok, thanks for the info. That’s disappointing. Could I hook into the markdown()
or kirbytext()
functions to add the functionality? I’d like the ![alt](path)
to work the same as (image: path alt: alt)
.
The alternative is to create a plugin for my editing software (Obsidian) to export the MD files with the proper path, because it only shows the images if the path is relative. I’d rather write a plugin for Kirby, but I’m not sure how to modify the kirbytext()
and markdown()
functions.
As long as you only use references to the files in the same folder, replacing all releative references in the text in a kirbytext hook should do the job (not sure if you have access to the current page object, though.
Maybe better: create a custom field method, that replaces the references, then call the parent field method on the result.
Thanks, yes, I can work with that