mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 00:20:28 +01:00
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.
18 lines
437 B
Ruby
18 lines
437 B
Ruby
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
|
|
|