Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extending markdown?

Tags:

html

php

markdown

I have a site where users can file game reports. I currently use a combination of markdown and HTMLPurifier to allow for limited mark-up.

I would like to add inline photo support, drawing images from a user gallery.

I've built an image sidebar with a bit of JS that on thumbnail click inserts a corresponding markdown code snippet at the cursor position.

This is all well and good, but rather than markdown processing this standard code and giving me:

<img src="foo.jpg" />

I'd much rather end up with:

<a href="original/foo.jpg">
    <img src="foo.jpg" />
</a>

i.e., an automatic link to the original fullsize image.

Because the code and paths are predictable, I could change these tags at the post-markdown HTML step via string replace, but that seems... inelegant.

Should I extend or otherwise modify markdown.php to give me a customized '<img /> mark-up, or is this a bad idea for some reason I am not perceiving?

like image 323
Drew Avatar asked Dec 05 '25 10:12

Drew


1 Answers

Modifying your markdown parser sounds like a good idea to me. You're entitled to getting the program you want. Be sure to store your changes as a patch as well, so you can easily re-apply them to future versions of markdown.

like image 171
sarnold Avatar answered Dec 07 '25 22:12

sarnold



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!