Skip to content

Commit

Permalink
resolves #2505 drop links from entries in TOC (PR #2506)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux authored Mar 9, 2024
1 parent 65dbe42 commit 6b99613
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Improvements::
* refactor formatted text transform to simplify how inner space is collapsed; verify only inner hard breaks are preserved
* allow relative font size for sub and sup to be set independently; support combined setting for backwards compatibility
* upgrade prawn-svg to 0.34 to add support for SVG referenced by image tag (SVG in SVG)
* drop links from entries in TOC (#2505)

Bug Fixes::

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 @@ -3952,6 +3952,7 @@ def ink_toc_level entries, num_levels, dot_leader, num_front_matter_pages
entry_title = entry.context == :section ? entry.numbered_title : (entry.title? ? entry.title : (entry.xreftext 'basic'))
next if entry_title.empty?
theme_font :toc, level: entry_level do
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 @@ -1625,6 +1625,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 <<~'END'
= Document Title
:doctype: book
:toc:
[#ch1]
== https://example.org[Once] Upon a https://example.com[Time]
[#ch2]
== Continuing What <<ch1>> Started
END

(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 6b99613

Please sign in to comment.