mirror of
https://github.com/olivierlacan/keep-a-changelog.git
synced 2025-07-31 01:34:18 +02:00
Finally restore the header anchor links
This is why you don’t merge pull requests without proper reviews. Almost makes me feel like we need feature specs for this damn project. :-)
This commit is contained in:
parent
7adec560c8
commit
62340f6552
28
config.rb
28
config.rb
@ -55,12 +55,32 @@ activate :automatic_image_sizes
|
|||||||
|
|
||||||
activate :syntax
|
activate :syntax
|
||||||
set :markdown_engine, :redcarpet
|
set :markdown_engine, :redcarpet
|
||||||
|
|
||||||
|
## Override default Redcarpet renderer in order to define a class
|
||||||
|
class CustomMarkdownRenderer < Redcarpet::Render::HTML
|
||||||
|
def header(text, header_level)
|
||||||
|
slug = text.gsub(" ", "-").downcase
|
||||||
|
tag_name = "h#{header_level}"
|
||||||
|
anchor_link = "<a id='#{slug}' class='anchor' href='##{slug}' aria-hidden='true'></a>"
|
||||||
|
header_tag_open = "<#{tag_name} id='#{slug}'>"
|
||||||
|
|
||||||
|
output = ""
|
||||||
|
output << header_tag_open
|
||||||
|
output << anchor_link
|
||||||
|
output << text
|
||||||
|
output << "</#{tag_name}>"
|
||||||
|
|
||||||
|
output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
$markdown_config = {
|
$markdown_config = {
|
||||||
fenced_code_blocks: true,
|
fenced_code_blocks: true,
|
||||||
footnotes: true,
|
footnotes: true,
|
||||||
smartypants: true,
|
smartypants: true,
|
||||||
tables: true,
|
tables: true,
|
||||||
with_toc_data: true
|
with_toc_data: true,
|
||||||
|
renderer: CustomMarkdownRenderer
|
||||||
}
|
}
|
||||||
set :markdown, $markdown_config
|
set :markdown, $markdown_config
|
||||||
|
|
||||||
@ -130,8 +150,12 @@ module Haml::Filters
|
|||||||
module Markdown
|
module Markdown
|
||||||
include Haml::Filters::Base
|
include Haml::Filters::Base
|
||||||
|
|
||||||
|
def renderer
|
||||||
|
$markdown_config[:renderer]
|
||||||
|
end
|
||||||
|
|
||||||
def render(text)
|
def render(text)
|
||||||
Redcarpet::Markdown.new(Redcarpet::Render::HTML.new($markdown_config)).render(text)
|
Redcarpet::Markdown.new(renderer.new($markdown_config)).render(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user