added headers anchor support

This commit is contained in:
Kilian Ciuffolo
2015-11-26 01:54:37 -08:00
parent 881901fae4
commit 26d8113357
5 changed files with 19 additions and 6 deletions
+2 -1
View File
@@ -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
+5 -1
View File
@@ -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
-3
View File
@@ -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
+1 -1
View File
@@ -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
+11
View File
@@ -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
"<a class=\"anchor\" id=\"#{anchor}\"></a>" +
"<h#{level}><a class=\"anchorable\" href=\"##{anchor}\">#{text}</a></h#{level}>"
end
end