Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

What's the best way to change markdown output in Grav?

Solved by Ole Vik View solution

Started by Memm 7 years ago · 1 replies · 742 views
7 years ago

For example ![](someimage.jpg) will produce <img src="route/someimage.jpg"></img>, but what if I want for example to change src to data-src like this
<img data-src="route/someimage.jpg"></img>?

I could use regex and the onPageContentRaw hook, but is there a better way? Is there a template system but for markdown output?

7 years ago Solution

No, Markdown is a very strict and simple syntax. The parser Grav uses, Parsedown, demonstrates this well. The easiest, and most likely most performant, way of doing this is with a simple regular expression. The other way is DOM-manipulation, which is very slow in comparison to regex.

Suggested topics

Topic Participants Replies Views Activity
General · by Hanns Mattes, 9 hours ago
0 26 9 hours ago
General · by Karmalakas, 2 days ago
2 86 2 days ago
General · by Hanns Mattes, 2 weeks ago
0 175 2 weeks ago
General · by Dima, 3 weeks ago
1 170 3 weeks ago
General · by pamtbaau, 3 weeks ago
0 277 3 weeks ago