From 26d811335724f745113a7dc1206434ad594546b6 Mon Sep 17 00:00:00 2001 From: Kilian Ciuffolo Date: Thu, 26 Nov 2015 01:54:37 -0800 Subject: [PATCH] added headers anchor support --- Gemfile | 3 ++- Gemfile.lock | 6 +++++- _config.yml | 3 --- _plugins/anchor.rb | 2 +- _plugins/redcarpet_custom.rb | 11 +++++++++++ 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 _plugins/redcarpet_custom.rb diff --git a/Gemfile b/Gemfile index 519ff85..27e19c4 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,6 @@ source 'https://rubygems.org' group :development, :test do gem 'jekyll', '~> 2.5.3' gem 'jekyll-redirect-from', '~> 0.8.0' - gem 'octopress-minify-html' + gem 'nokogiri', '1.6.6.4' + gem 'octopress-minify-html', '1.3.0' end diff --git a/Gemfile.lock b/Gemfile.lock index 5ad0ecc..ebe7b9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -57,10 +57,13 @@ GEM rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) mercenary (0.3.5) + mini_portile (0.6.2) multi_css (0.1.0) css_press multi_js (0.1.0) uglifier (~> 2) + nokogiri (1.6.6.4) + mini_portile (~> 0.6.0) octopress-hooks (2.6.1) jekyll (>= 2.0) octopress-minify-html (1.3.0) @@ -94,7 +97,8 @@ PLATFORMS DEPENDENCIES jekyll (~> 2.5.3) jekyll-redirect-from (~> 0.8.0) - octopress-minify-html + nokogiri (= 1.6.6.4) + octopress-minify-html (= 1.3.0) BUNDLED WITH 1.10.6 diff --git a/_config.yml b/_config.yml index 1692962..defa53f 100644 --- a/_config.yml +++ b/_config.yml @@ -4,12 +4,9 @@ shared_baseurl: "" syntax_highlight_theme: "tomorrow-night" cdnurl: "//cdn.tinymce.com/4/tinymce.min.js" exclude: - - docs - README.md - Gemfile - Gemfile.lock - - build.sh - - v*/nav.yml - vendor markdown: redcarpet diff --git a/_plugins/anchor.rb b/_plugins/anchor.rb index a9e5329..25f0c63 100644 --- a/_plugins/anchor.rb +++ b/_plugins/anchor.rb @@ -1,7 +1,7 @@ module Jekyll module AnchorFilter def anchor(input) - input.gsub(/[^a-zA-Z\-_]/, "").downcase if !input.nil? + input.gsub(/[^a-zA-Z0-9\-_]/, "").downcase if !input.nil? end end end diff --git a/_plugins/redcarpet_custom.rb b/_plugins/redcarpet_custom.rb new file mode 100644 index 0000000..f879086 --- /dev/null +++ b/_plugins/redcarpet_custom.rb @@ -0,0 +1,11 @@ +require 'redcarpet' +require 'nokogiri' + +class Redcarpet::Render::HTML + def header(text, level) + anchor = Nokogiri::HTML(text).text.gsub(/[^a-zA-Z0-9\-_]/, "").downcase + + "" + + "#{text}" + end +end