module Jekyll module FancyToCFilter def fancytoc(input) converter = @context.registers[:site].converters.find { |c| c.is_a? Jekyll::Converters::Markdown } extensions = converter.instance_variable_get(:@parser).instance_variable_get(:@redcarpet_extensions) toc_generator = Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC, extensions) toc = toc_generator.render(input) <<-HTML unless toc.empty?