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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

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 · 464 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 Jerry Hunt, 4 days ago
2 125 19 hours ago
General · by pamtbaau, 24 hours ago
1 89 23 hours ago
General · by Andy Miller, 1 day ago
0 73 1 day ago
General · by Marcel, 12 months ago
6 382 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago