Skip to content

Commit

Permalink
resolves asciidoctor#1268 document title in outline should point to s…
Browse files Browse the repository at this point in the history
…econd page if document has cover page
  • Loading branch information
mojavelinux committed Sep 12, 2019
1 parent 6e8a299 commit 02b688b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[

== Unreleased

* document title in outline should point to second page if document has cover page (#1268)
* start at setting for running content and page numbering must account for disabled title page (book doctype) (#1263)
* start at setting for running content and page numbering must account for front cover (#1266)
* preserve indentation that uses tabs in verbatim blocks when tabsize is not set (#1258)
Expand Down
9 changes: 4 additions & 5 deletions lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def convert_document doc
end
end

add_outline doc, (doc.attr 'outlinelevels', num_toc_levels), toc_page_nums, num_front_matter_pages[1]
add_outline doc, (doc.attr 'outlinelevels', num_toc_levels), toc_page_nums, num_front_matter_pages[1], has_front_cover
if state.pages.size > 0 && (initial_zoom = @theme.page_initial_zoom)
case initial_zoom.to_sym
when :Fit
Expand Down Expand Up @@ -3258,7 +3258,7 @@ def allocate_running_content_layout page, periphery, cache
end
end

def add_outline doc, num_levels = 2, toc_page_nums = [], num_front_matter_pages = 0
def add_outline doc, num_levels = 2, toc_page_nums = [], num_front_matter_pages = 0, has_front_cover = false
if ::String === num_levels
if num_levels.include? ':'
num_levels, expand_levels = num_levels.split ':', 2
Expand All @@ -3284,9 +3284,8 @@ def add_outline doc, num_levels = 2, toc_page_nums = [], num_front_matter_pages

outline.define do
# FIXME use sanitize: :plain_text once available
if (doctitle = document.sanitize(doc.doctitle use_fallback: true))
# FIXME link to title page if there's a cover page (skip cover page and ensure blank page)
page title: doctitle, destination: (document.dest_top 1)
if (doctitle = document.sanitize(doc.doctitle use_fallback: true)) && document.page_count > (has_front_cover ? 2 : 1)
page title: doctitle, destination: (document.dest_top has_front_cover ? 2 : 1)
end
unless toc_page_nums.none? || (toc_title = doc.attr 'toc-title').nil_or_empty?
page title: toc_title, destination: (document.dest_top toc_page_nums.first)
Expand Down
1 change: 1 addition & 0 deletions spec/cover_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
images = get_images pdf, 1
(expect images).to have_size 1
(expect images[0].data).to eql File.binread fixture_file 'cover.jpg'
(expect extract_outline pdf).to be_empty
end

it 'should not crash if front cover image is a URI and the allow-uri-read attribute is not set' do
Expand Down
17 changes: 17 additions & 0 deletions spec/outline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@
(expect get_page_labels pdf).to eql %w(i ii 1 2)
end

it 'should label title page using roman numeral ii if cover page is present' do
pdf = to_pdf <<~'EOS', doctype: :book
= Book Title
:toc:
:front-cover-image: image:cover.jpg[]
== Chapter 1
== Chapter 2
EOS

(expect get_page_labels pdf).to eql %w(i ii iii 1 2)
outline = extract_outline pdf
(expect outline[0][:title]).to eql 'Book Title'
(expect outline[0][:dest][:pagenum]).to eql 2
end

it 'should label first page starting with 1 if no front matter is present' do
pdf = to_pdf <<~'EOS', doctype: :book
no front matter
Expand Down

0 comments on commit 02b688b

Please sign in to comment.