Skip to content

Commit 491b62c

Browse files
Extend Markdown preprocessor to add anchors in main headers only "h2"
1 parent a9aa5c1 commit 491b62c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

_plugins/convert-header.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Kramdown
2+
module Converter
3+
class Html
4+
def convert_header(el, indent)
5+
el_attribute = el.attr.dup
6+
7+
if @options[:auto_ids] && !el_attribute['id']
8+
el_attribute['id'] = generate_id(el.options[:raw_text])
9+
end
10+
11+
el_attribute['class'] = "header-with-anchor"
12+
13+
@toc << [el.options[:level], el_attribute['id'], el.children] if el_attribute['id'] && in_toc?(el)
14+
level = output_header_level(el.options[:level])
15+
format_as_block_html("h#{level}", el_attribute, "#{inner(el, indent)} <a href=\"##{el_attribute['id']}\">#</a>", indent)
16+
end
17+
end
18+
end
19+
end

assets/stylesheets/_screen.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ cite {
177177
}
178178
}
179179

180-
h2.with-anchor {
180+
h2.header-with-anchor {
181181
&:hover {
182182
a {
183183
display: inline-block;
184184
}
185185
}
186186

187187
a {
188-
color: var(--color-text);
189188
display: none;
189+
color: var(--color-text);
190190
margin-left: .2em;
191191
text-decoration: none;
192192
}

0 commit comments

Comments
 (0)