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