mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Fixes #447. We do this by moving the actual anchored element up in the page without moving the actual text. (Apple uses a similar trick in their framed docs.) Now this looks a bit sillier on smaller screens but it's better overall.
18 lines
486 B
Ruby
18 lines
486 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}\" class=\"anchor\"><a href=\"##{clean_title}\">#{title}</a></h#{level}>"
|
|
end
|
|
end
|
|
|