After investigating the source of docpad-plugin-marked
,
it turns out the plugin already supports a method to customise the Marked renderer, albeit undocumented.
Alongside the markedOptions
object, which is used to pass configuration to Marked, you can add the markedRenderer
object.
In this object, you can specify custom renderer methods.
(Refer to the official Marked documentation for accepted keys.)
The plugin then takes care of the rest (i.e. it creates a custom render instance).
A stripped down docpad.coffee file would look as follows:
docpadConfig =
plugins:
marked:
markedOptions:
# customize Marked... (https://github.com/chjj/marked#options-1)
markedRenderer:
# add custom render methods (https://github.com/chjj/marked#block-level-renderer-methods and https://github.com/chjj/marked#inline-level-renderer-methods)
# f.i. wrap a span around images
image: (href, title, text) ->
output = '<span class="img-wpr">'
# I should probably escape here...
output += '<img src="' + href + '" alt="' + text + '" title="' + title + '" />'
output += '<div>'
output += text
output += '</div>'
output += '</span>'
Note my pervious solution wasn't wrong, but this is just cleaner and easier, thanks to the DocPad team!