Search code examples
markdowndocpad

How to change markdown image generated html in docpad?


I am using Docpad and my page is based on Bootstrap. I want all images to have class attribute: "img-responsive". One way is using HTML tag directly in the Markdown document, but I don't like this approach. I would like to use Markdown syntax for it. Then if I change my design I do not have to update all my pages with new HTML.

Is it possible to change behavior how image tag's HTML is generated from Markdown?


Solution

  • According to DocPad documentation, you can configure which Markdown implementation DocPad uses. If one of the Markdown implementations offers an option to alter its behavior, you might be able to create your own plugin to get the behavior you want. But, I suspect it will take some work on your part to build your own plugin. I doubt you'll find anything pre-built that works out-of-the-box. You are asking for non-standard Markdown behavior after all.

    For example, the marked Markdown implementation allows you to override renderer methods. If you override the image renderer, you should be able to have it output your desired HTML for images. However, it is not clear to me if the Marked Plugin for DocPad supports that. If not, you may need to fork that plugin and create your own.