rubymiddlemankramdown

Middleman Kramdown Converter for <a> html tags


I'm trying to convert every kramdown link within a middlemanapp.

So far I've tried to prepend the Kramdown::Converter::Html module and override the convert_a method.

module Kramdown
  module Converter
    module UrlConverter
      def convert_a(el, indent)
        "<a href=\"foo\">bar</a>"
      end
    end
  end
end

Kramdown::Converter::Html.prepend Kramdown::Converter::UrlConverter

But for some reason, convert_a is never executed. Methods like convert_p or convert_codeblock are executed and I can change their behavior.

Kramdown 1.10.0 Middleman 4.3.5

Any ideas?


Solution

  • Middleman overrides convert_a (and convert_img) in middleman-core/lib/middleman-core/renderers/kramdown.rb by deriving from Kramdown::Converter::Html and without calling super.

    Therefore by prepending to Kramdown::Converter::Html, your method is replaced by middleman's version.

    You might be more successful by monkeypatching Middleman::Renderes::MiddlemanKramdownHTML instead, but you'll need to be careful not to violate middleman's expectations of the convert_a method.