Browse Source
This gives markdown headers an id so that we can link directly to sections of our docs. This is better than the alternative of adding them all ourselves.main
Paul O’Shannessy
11 years ago
3 changed files with 26 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||||
|
require 'redcarpet' |
||||
|
require 'sanitize' |
||||
|
|
||||
|
# Simple converter that is probably better than RedCarpet's built in TOC id |
||||
|
# generator (which ends up with things lik id="toc_1"... terrible). |
||||
|
|
||||
|
class Redcarpet::Render::HTML |
||||
|
def header(title, level) |
||||
|
clean_title = Sanitize.clean(title) |
||||
|
.downcase |
||||
|
.gsub(/\s+/, "-") |
||||
|
.gsub(/[^A-Za-z0-9\-_.]/, "") |
||||
|
|
||||
|
return "<h#{level} id=\"#{clean_title}\">#{title}</h#{level}>" |
||||
|
end |
||||
|
end |
||||
|
|
Loading…
Reference in new issue