Skip to content

Commit

Permalink
backport fix for #2441 show dot leaders in TOC entry if toclevels is …
Browse files Browse the repository at this point in the history
…increased for a given section
  • Loading branch information
mojavelinux committed Aug 20, 2023
1 parent 33db144 commit c54420f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
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._
Bug Fixes::

* show dot leaders in TOC entry if toclevels is increased for a given section (#2441)

== 2.3.9 (2023-06-28) - @mojavelinux

Expand Down
4 changes: 2 additions & 2 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3861,7 +3861,7 @@ def ink_toc doc, num_levels, toc_page_number, start_cursor, num_front_matter_pag
font_style: dot_leader_font_style,
font_size: font_size,
levels: ((dot_leader_l = @theme.toc_dot_leader_levels) == 'none' ? ::Set.new :
(dot_leader_l && dot_leader_l != 'all' ? dot_leader_l.to_s.split.map(&:to_i).to_set : (0..num_levels).to_set)),
(dot_leader_l && dot_leader_l != 'all' ? dot_leader_l.to_s.split.map(&:to_i).to_set : nil)),
text: (dot_leader_text = @theme.toc_dot_leader_content || DotLeaderTextDefault),
width: dot_leader_text.empty? ? 0 : (rendered_width_of_string dot_leader_text),
# TODO: spacer gives a little bit of room between dots and page number
Expand Down Expand Up @@ -3935,7 +3935,7 @@ def ink_toc_level entries, num_levels, dot_leader, num_front_matter_pages
end_cursor = cursor
move_cursor_to start_cursor
# NOTE: we're guaranteed to be on the same page as the final line of the entry
if dot_leader[:width] > 0 && (dot_leader[:levels].include? entry_level.pred)
if dot_leader[:width] > 0 && (dot_leader[:levels] ? (dot_leader[:levels].include? entry_level.pred) : true)
pgnum_label_width = rendered_width_of_string pgnum_label
pgnum_label_font_settings = { color: @font_color, font: font_family, size: @font_size, styles: font_styles }
save_font do
Expand Down
29 changes: 29 additions & 0 deletions spec/toc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,35 @@
(expect pdf.find_text page_number: 2, string: 'Appendix Section').to have_size 0
end

it 'should include dot leaders in TOC entry if toclevels is increased for a given section' do
pdf = to_pdf <<~'END', analyze: true
= Document Title
:doctype: book
:toc:
:toclevels: 1
== Chapter
=== Chapter Section
==== Chapter Subsection
[toclevels=3]
== Lorem Ipsum
=== Lorem Ipsum Section
==== Lorem Ipsum Subsection
END

toc_lines = pdf.lines pdf.find_text page_number: 2
(expect toc_lines).to have_size 5
(expect toc_lines[1]).to match %r/^Chapter (\. )+.*?1/
(expect toc_lines[2]).to match %r/^Lorem Ipsum (\. )+.*?2/
(expect toc_lines[3]).to match %r/^Lorem Ipsum Section (\. )+.*?2/
(expect toc_lines[4]).to match %r/^Lorem Ipsum Subsection (\. )+.*?2/
end

it 'should allow section to remove itself from toc by setting toclevels to less than section level' do
pdf = to_pdf <<~'EOS', analyze: true
= Document Title
Expand Down

0 comments on commit c54420f

Please sign in to comment.