3

I am building a site with Middleman, and using Redcarpet as my markdown engine, mostly for its GFM support.

I would like to tap into or precede the markdown rendering process to add support for various syntax options. In one example, I'd like this:

[file:/path/to/file]

to be rendered as:

<p class="file">
  <code>/path/to/file</code>
</p>

In every case, I'm not rendering anything that would interfere affect the remaining markdown in the template, so I would suspect I could precede the rendering process.

Also, if this is simpler by using another renderer, I'm not tied to Redcarpet in any way other than that I'd prefer to have GFM support.

seancdavis
  • 2,739
  • 2
  • 26
  • 36
  • If you decide to go with Pandoc instead, take a look at [pandoc scripting](http://pandoc.org/scripting.html), good luck! – mb21 Jul 11 '15 at 23:05

1 Answers1

1

First, you need to create a new renderer based upon redcarpet within your config.rb file. something like:

   set renderer: myRenderer

Next, you need to create "myRenderer" as a new class (you can do this at the top of your config.rb but you can also put it in an external file)

require "middleman-core/renderers/redcarpet"
class myRenderer < Middleman::Renderers::MiddlemanRedcarpetHTML

def preprocess(document)
  # insert ruby code to use a regex to find your tag in the document
  # insert ruby code to generate your HTML and replace your tag with
  #    HTML that you want
  return (document)
end

If you want this to be the last thing done, use postprocess(document) instead of preprocess(document)