From 7adec560c8bf2856679dfff2d84e5425ad4aae34 Mon Sep 17 00:00:00 2001 From: Olivier Lacan Date: Thu, 23 Mar 2017 03:48:28 +0100 Subject: [PATCH] Set TOC data for Markdown & override Haml filter --- config.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/config.rb b/config.rb index 89c65f2..3e183f4 100644 --- a/config.rb +++ b/config.rb @@ -55,12 +55,14 @@ activate :automatic_image_sizes activate :syntax set :markdown_engine, :redcarpet -set :markdown, { +$markdown_config = { fenced_code_blocks: true, footnotes: true, smartypants: true, - tables: true + tables: true, + with_toc_data: true } +set :markdown, $markdown_config # -------------------------------------- # Helpers @@ -117,3 +119,19 @@ activate :autoprefixer do |config| config.browsers = ['last 2 versions', 'Explorer >= 10'] config.cascade = false end + +# Haml doesn't pick up on Markdown configuration so we have to remove the +# default Markdown Haml filter and reconfigure one that follows our +# global configuration. + +module Haml::Filters + remove_filter("Markdown") #remove the existing Markdown filter + + module Markdown + include Haml::Filters::Base + + def render(text) + Redcarpet::Markdown.new(Redcarpet::Render::HTML.new($markdown_config)).render(text) + end + end +end