Skip to content

Commit 582f2d6

Browse files
committed
backport fix for asciidoctor#2505 drop links from entries in TOC
1 parent 926f0a6 commit 582f2d6

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.adoc

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
77

88
== Unreleased
99

10-
_No changes since previous release._
10+
Improvements::
11+
12+
* drop links from entries in TOC (#2505)
1113

1214
== 2.3.14 (2024-03-08) - @mojavelinux
1315

lib/asciidoctor/pdf/converter.rb

+1
Original file line numberDiff line numberDiff line change
@@ -3917,6 +3917,7 @@ def ink_toc_level entries, num_levels, dot_leader, num_front_matter_pages
39173917
theme_font :toc, level: entry_level do
39183918
entry_title = entry.context == :section ? entry.numbered_title : (entry.title? ? entry.title : (entry.xreftext 'basic'))
39193919
next if entry_title.empty?
3920+
entry_title = entry_title.gsub DropAnchorRx, '' if entry_title.include? '<a'
39203921
entry_title = transform_text entry_title, @text_transform if @text_transform
39213922
pgnum_label_placeholder_width = rendered_width_of_string '0' * @toc_max_pagenum_digits
39223923
# NOTE: only write title (excluding dots and page number) if this is a dry run

spec/toc_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,30 @@ def get_entries_for_toc _node
16041604
(expect images[0][:width]).to eql images[1][:width]
16051605
end
16061606

1607+
it 'should remove links from entries in toc but leave behind linked text' do
1608+
pdf = to_pdf <<~'EOS'
1609+
= Document Title
1610+
:doctype: book
1611+
:toc:
1612+
1613+
[#ch1]
1614+
== https://example.org[Once] Upon a https://example.com[Time]
1615+
1616+
[#ch2]
1617+
== Continuing What <<ch1>> Started
1618+
EOS
1619+
1620+
(expect pdf.pages).to have_size 4
1621+
toc_lines = ((pdf.page 2).text.split ?\n).reject(&:empty?)
1622+
(expect toc_lines).to have_size 3
1623+
(expect toc_lines[0]).to eql 'Table of Contents'
1624+
(expect toc_lines[1]).to start_with 'Once Upon a Time'
1625+
(expect toc_lines[2]).to start_with 'Continuing What Once Upon a Time Started'
1626+
annots = get_annotations pdf, 2
1627+
(expect annots).to have_size 4
1628+
(expect annots.map {|it| it[:Dest] }.sort).to eql %w(ch1 ch1 ch2 ch2)
1629+
end
1630+
16071631
it 'should allow extended converter to insert extra page before toc' do
16081632
backend = nil
16091633
create_class (Asciidoctor::Converter.for 'pdf') do

0 commit comments

Comments
 (0)