From 0f83fbc6de4d5f0a78377e4c62c8f012444c87d4 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 18 Oct 2024 00:56:23 +0400 Subject: [PATCH] Allow to disable chapter anchors --- lib/repubmark/elems/chapter.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/repubmark/elems/chapter.rb b/lib/repubmark/elems/chapter.rb index 31766cf..ccd4bab 100644 --- a/lib/repubmark/elems/chapter.rb +++ b/lib/repubmark/elems/chapter.rb @@ -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 - %(#@title\n) if @level != 1 + id_attr = %( id="#{anchor}") unless anchor_prefix.empty? + %(#@title\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