Skip to content
Browse files

Better anchor creation

  • Loading branch information...
1 parent a739f4b commit 11fe28c77f1bfb3fe03a83d2ea24d464808c3f57 @wagenet wagenet committed Mar 31, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 config.rb
View
11 config.rb
@@ -14,6 +14,13 @@
# end
class TableOfContents < Redcarpet::Render::Base
+
+ def self.anchorify(text)
+ res = text.gsub(/&#?\w+;/, '-').gsub(/\W+/, '-').gsub(/^-|-$/, '').downcase
+ puts "#{text.inspect} -- #{res.inspect}"
+ res
+ end
+
def initialize
@current_level = 0
@result = []
@@ -43,7 +50,7 @@ def header(text, level)
result << "</li>\n<li>\n"
end
- result << "<a href=\"##{text.gsub(/\W+/, '-').gsub(/^-|-$/, '').downcase}\">#{text}</a>"
+ result << "<a href=\"#toc_#{TableOfContents.anchorify(text)}\">#{text}</a>"
""
end
@@ -82,7 +89,7 @@ def table_of_contents
class HighlightedHTML < Redcarpet::Render::HTML
def header(text, level)
- "<h#{level} id='#{text.gsub(/\W+/, '-').gsub(/^-|-$/, '').downcase}'>#{text}</h#{level}>"
+ "<h#{level} id='toc_#{TableOfContents.anchorify(text)}'>#{text}</h#{level}>"
end
def block_code(code, language)

0 comments on commit 11fe28c

Please sign in to comment.
Something went wrong with that request. Please try again.