Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

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 · 673 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 Andy Miller, 5 days ago
0 91 5 days ago
General · by lynbor, 4 weeks ago
3 426 2 weeks ago
General · by lynbor, 3 weeks ago
7 546 2 weeks ago
General · by Harry, 2 weeks ago
0 153 2 weeks ago
General · by Old Man Umby, 1 month ago
2 300 3 weeks ago