Skip to content

Commit

Permalink
backport fix for #2505 drop links from entries in TOC
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Mar 9, 2024
1 parent 926f0a6 commit 582f2d6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3917,6 +3917,7 @@ def ink_toc_level entries, num_levels, dot_leader, num_front_matter_pages
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
Expand Down
24 changes: 24 additions & 0 deletions spec/toc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,30 @@ def get_entries_for_toc _node
(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
Expand Down

0 comments on commit 582f2d6

Please sign in to comment.