summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2024-03-09 14:19:56 -0700
committerDan Allen <dan.j.allen@gmail.com>2024-03-09 14:27:31 -0700
commit582f2d66359fa72313df6b762cbf558faa3f4f36 (patch)
tree532c1e13ca1cb5eeb34a91d125fd314dd09443c7
parent926f0a627801d4b2668cd1d50c8b45b925b43af3 (diff)
backport fix for #2505 drop links from entries in TOC
-rw-r--r--CHANGELOG.adoc4
-rw-r--r--lib/asciidoctor/pdf/converter.rb1
-rw-r--r--spec/toc_spec.rb24
3 files changed, 28 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 2f89a64a..3c1d27b8 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -7,7 +7,9 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
== Unreleased
-_No changes since previous release._
+Improvements::
+
+* drop links from entries in TOC (#2505)
== 2.3.14 (2024-03-08) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 791fd1cc..d4b9049c 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -3917,6 +3917,7 @@ module Asciidoctor
theme_font :toc, level: entry_level do
entry_title = entry.context == :section ? entry.numbered_title : (entry.title? ? entry.title : (entry.xreftext 'basic'))
next if entry_title.empty?
+ entry_title = entry_title.gsub DropAnchorRx, '' if entry_title.include? '<a'
entry_title = transform_text entry_title, @text_transform if @text_transform
pgnum_label_placeholder_width = rendered_width_of_string '0' * @toc_max_pagenum_digits
# NOTE: only write title (excluding dots and page number) if this is a dry run
diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb
index 9fda447e..6d755a61 100644
--- a/spec/toc_spec.rb
+++ b/spec/toc_spec.rb
@@ -1604,6 +1604,30 @@ describe 'Asciidoctor::PDF::Converter - TOC' do
(expect images[0][:width]).to eql images[1][:width]
end
+ it 'should remove links from entries in toc but leave behind linked text' do
+ pdf = to_pdf <<~'EOS'
+ = Document Title
+ :doctype: book
+ :toc:
+
+ [#ch1]
+ == https://example.org[Once] Upon a https://example.com[Time]
+
+ [#ch2]
+ == Continuing What <<ch1>> Started
+ EOS
+
+ (expect pdf.pages).to have_size 4
+ toc_lines = ((pdf.page 2).text.split ?\n).reject(&:empty?)
+ (expect toc_lines).to have_size 3
+ (expect toc_lines[0]).to eql 'Table of Contents'
+ (expect toc_lines[1]).to start_with 'Once Upon a Time'
+ (expect toc_lines[2]).to start_with 'Continuing What Once Upon a Time Started'
+ annots = get_annotations pdf, 2
+ (expect annots).to have_size 4
+ (expect annots.map {|it| it[:Dest] }.sort).to eql %w(ch1 ch1 ch2 ch2)
+ end
+
it 'should allow extended converter to insert extra page before toc' do
backend = nil
create_class (Asciidoctor::Converter.for 'pdf') do