Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

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 · 609 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 jean-louis67, 3 weeks ago
2 308 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 310 3 weeks ago
General · by Veehem, 4 weeks ago
0 263 4 weeks ago
General · by milkboy, 4 weeks ago
0 264 4 weeks ago
General · by ian russell, 1 month ago
2 335 1 month ago