Skip to content

Commit

Permalink
Update headers to never have problematic characters in ids, fixes #64…
Browse files Browse the repository at this point in the history
…, hopefully
  • Loading branch information
lord committed Jun 25, 2014
1 parent e8a491c commit 719061a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require './lib/redcarpet_header_fix'

set :css_dir, 'stylesheets'

set :js_dir, 'javascripts'
Expand Down Expand Up @@ -34,3 +36,4 @@
# Or use a different image path
# set :http_prefix, "/Content/images/"
end

9 changes: 9 additions & 0 deletions lib/redcarpet_header_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RedcarpetHeaderFix
def header(text, level, id)
clean_id = id.gsub(/[\.]/, '-').gsub(/[^a-zA-Z0-9\-_]/, '')
"<h#{level} id='#{clean_id}'>#{text}</h1>"
end
end

require 'middleman-core/renderers/redcarpet'
Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, RedcarpetHeaderFix

0 comments on commit 719061a

Please sign in to comment.