Skip to content

Commit

Permalink
Fix bug where head count always got larger across reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
lord committed Jun 15, 2017
1 parent 685179d commit 8b83099
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/unique_head.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Unique header generation
require 'middleman-core/renderers/redcarpet'
class UniqueHeadCounter < Middleman::Renderers::MiddlemanRedcarpetHTML
@@head_count = {}
def initialize
super
@head_count = {}
end
def header(text, header_level)
friendly_text = text.parameterize
@@head_count[friendly_text] ||= 0
@@head_count[friendly_text] += 1
if @@head_count[friendly_text] > 1
friendly_text += "-#{@@head_count[friendly_text]}"
@head_count[friendly_text] ||= 0
@head_count[friendly_text] += 1
if @head_count[friendly_text] > 1
friendly_text += "-#{@head_count[friendly_text]}"
end
return "<h#{header_level} id='#{friendly_text}'>#{text}</h#{header_level}>"
end
Expand Down

0 comments on commit 8b83099

Please sign in to comment.