You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
425 B

  1. require 'nokogiri'
  2. # Adds linkable anchors for documentation headers
  3. class Kramdown::Converter::Html
  4. def convert_header(el, indent)
  5. text = el.options[:raw_text]
  6. level = el.options[:level]
  7. anchor = Nokogiri::HTML(text).text.gsub(/[^a-zA-Z0-9\-_]/, "").downcase
  8. "<a class=\"anchor\" id=\"#{anchor}\"></a>" +
  9. "<h#{level}><a class=\"anchorable\" href=\"##{anchor}\">#{text}</a></h#{level}>"
  10. end
  11. end