Sha256: cc498324d2409c5513cb4f7f6eedad4b878441c1efc6bf2e80859cdc275fa29a

Contents?: true

Size: 643 Bytes

Versions: 5

Compression:

Stored size: 643 Bytes

Contents

# 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.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

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
arctic-vendor-1.0.1 documentation/lib/nesting_unique_head.rb
arctic-vendor-1.0.0 documentation/lib/nesting_unique_head.rb
arctic-vendor-0.2.4 documentation/lib/nesting_unique_head.rb
arctic-vendor-0.2.3 documentation/lib/nesting_unique_head.rb
arctic-ui-0.1.0 documentation/lib/nesting_unique_head.rb