Allow to disable chapter anchors

This commit is contained in:
Alex Kotov 2024-10-18 00:56:23 +04:00
parent 71ec8dc7f6
commit 0f83fbc6de
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

View file

@ -67,8 +67,7 @@ module Repubmark
def anchor
if parent.instance_of?(self.class) && @level > 2
"#{parent.anchor}-#@slug"
elsif (anchor_prefix =
String(config[:chapter_anchor_prefix]).strip).empty?
elsif anchor_prefix.empty?
@slug
else
"#{anchor_prefix}-#@slug"
@ -133,12 +132,17 @@ module Repubmark
end
def build_title_html
%(<h#@level id="#{anchor}">#@title</h#@level>\n) if @level != 1
id_attr = %( id="#{anchor}") unless anchor_prefix.empty?
%(<h#@level#{id_attr}>#@title</h#@level>\n) if @level != 1
end
def build_title_gemtext
"\n#{'#' * @level} #@title\n\n" if @level != 1
end
def anchor_prefix
@anchor_prefix ||= String(config[:chapter_anchor_prefix]).strip.freeze
end
end
end
end