Commit 17e22c41 authored by Paul 🐻's avatar Paul 🐻

markdown: Add anchors on h2 titles.

parent fc62a444
......@@ -26,10 +26,15 @@ page '/*.txt', layout: false
# page "/admin/*"
# end
###
# Renderers
###
require "lib/renderers.rb"
###
# Helpers
###
require "lib/helpers/date_helpers"
require "lib/helpers.rb"
helpers DateHelpers
# Methods defined in the helpers block are available in templates
......
require "lib/helpers/date_helpers"
require "lib/renderers/middleman_kramdown_html"
require "middleman-core/renderers/kramdown"
class ::Middleman::Renderers::MiddlemanKramdownHTML
def convert_header(el, indent)
attr = el.attr.dup
if @options[:auto_ids] && !attr['id']
attr['id'] = generate_id(el.options[:raw_text])
end
@toc << [el.options[:level], attr['id'], el.children] if attr['id'] && in_toc?(el)
level = output_header_level(el.options[:level])
icon = format_as_block_html("i", { class: "fa fa-link" }, "", 0)
link_icon = format_as_block_html("a", { href: "##{attr['id']}", class: "anchor" }, icon, 0)
inner = link_icon + inner(el, indent)
# "<h%s id=\"%s\"><a href=\"#%s\" class=\"anchor\"><i class=\"fa fa-link\"></i></a>%s</h%s>" % [level, attr['id'], attr['id'], inner(el, indent), level]
format_as_block_html("h#{level}", attr, inner, indent)
end
end
......@@ -76,6 +76,21 @@ article :not(pre) code {
article .subtitle, article h1, article h2, article h3 {
margin: 10px auto 20px; }
article .anchor {
float: left;
padding-right: 4px;
margin-left: -20px;
display: none; }
article .anchor i.fa {
width: 16px;
height: 16px;
font-size: 0.7em; }
article h2:hover .anchor {
display: block;
text-decoration: none; }
aside {
color: rgb(255, 246, 228);
position: relative;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment