mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 01:45:15 +00:00
23 lines
662 B
Ruby
23 lines
662 B
Ruby
# Nested unique header generation
|
|
require 'middleman-core/renderers/redcarpet'
|
|
|
|
class NestingUniqueHeadCounter < Middleman::Renderers::MiddlemanRedcarpetHTML
|
|
def initialize
|
|
super
|
|
@@headers_history = {} if !defined?(@@headers_history)
|
|
end
|
|
|
|
def header(text, header_level)
|
|
friendly_text = text.gsub(/<[^>]*>/,"").parameterize
|
|
@@headers_history[header_level] = text.parameterize
|
|
|
|
if header_level > 1
|
|
for i in (header_level - 1).downto(1)
|
|
friendly_text.prepend("#{@@headers_history[i]}-") if @@headers_history.key?(i)
|
|
end
|
|
end
|
|
|
|
return "<h#{header_level} id='#{friendly_text}'>#{text}</h#{header_level}>"
|
|
end
|
|
end
|