mirror of
https://github.com/danbulant/api_docs
synced 2026-06-19 06:11:42 +00:00
Adds unique header creation (#743)
This commit is contained in:
parent
7b1e718672
commit
39aaa0fca5
2 changed files with 19 additions and 1 deletions
|
|
@ -1,3 +1,6 @@
|
||||||
|
# Unique header generation
|
||||||
|
require './lib/unique_head.rb'
|
||||||
|
|
||||||
# Markdown
|
# Markdown
|
||||||
set :markdown_engine, :redcarpet
|
set :markdown_engine, :redcarpet
|
||||||
set :markdown,
|
set :markdown,
|
||||||
|
|
@ -7,7 +10,8 @@ set :markdown,
|
||||||
prettify: true,
|
prettify: true,
|
||||||
tables: true,
|
tables: true,
|
||||||
with_toc_data: true,
|
with_toc_data: true,
|
||||||
no_intra_emphasis: true
|
no_intra_emphasis: true,
|
||||||
|
renderer: UniqueHeadCounter
|
||||||
|
|
||||||
# Assets
|
# Assets
|
||||||
set :css_dir, 'stylesheets'
|
set :css_dir, 'stylesheets'
|
||||||
|
|
|
||||||
14
lib/unique_head.rb
Normal file
14
lib/unique_head.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Unique header generation
|
||||||
|
require 'middleman-core/renderers/redcarpet'
|
||||||
|
class UniqueHeadCounter < Middleman::Renderers::MiddlemanRedcarpetHTML
|
||||||
|
@@head_count = {}
|
||||||
|
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]}"
|
||||||
|
end
|
||||||
|
return "<h#{header_level} id='#{friendly_text}'>#{text}</h#{header_level}>"
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue