summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-08-30 03:17:41 -0600
committerGitHub <noreply@github.com>2019-08-30 03:17:41 -0600
commit1e634a8de07aec3cae8b36cd9d29b7fe37aeab66 (patch)
tree60d8485478c12ee27cfd45d2ed13391b884d0a96
parent3eb0f36aa99e95b8a68e93064a25397a2ffdced2 (diff)
resolves #1240 fix placement of toc in article when doctitle is not set (PR #1241)
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor-pdf/converter.rb2
-rw-r--r--spec/toc_spec.rb14
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 4e9cd66c..b20f5a0b 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -23,6 +23,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
* allow theme to configure the minimum height required after a section title for it to stay on same page (#1210)
* convert hyphen to underscore in theme key for admonition icon type (#1217)
* always resolve images in running content relative to themesdir (instead of document) (#1183)
+* fix placement of toc in article when doctitle is not set (#1240)
* honor text alignment role on abstract paragraph(s)
* don't insert blank page at start of document if media=prepress and document does not have a cover (#1181)
* insert blank page after cover if media=prepress (#1181)
diff --git a/lib/asciidoctor-pdf/converter.rb b/lib/asciidoctor-pdf/converter.rb
index 8c9719c4..69d84b5d 100644
--- a/lib/asciidoctor-pdf/converter.rb
+++ b/lib/asciidoctor-pdf/converter.rb
@@ -196,8 +196,8 @@ class Converter < ::Prawn::Document
theme_font :heading, level: 1 do
layout_heading doc.doctitle, align: (@theme.heading_h1_align || :center).to_sym, level: 1
end
- toc_start = @y
end
+ toc_start = @y
end
# NOTE font must be set before toc dry run to ensure dry run size is accurate
diff --git a/spec/toc_spec.rb b/spec/toc_spec.rb
index 0bfe50ea..6fc201af 100644
--- a/spec/toc_spec.rb
+++ b/spec/toc_spec.rb
@@ -255,6 +255,20 @@ describe 'Asciidoctor::PDF::Converter - TOC' do
(expect toc_bottom_text[:y] - content_top_text[:y]).to be < 35
end
+ it 'should insert toc at top of first page if toc is set and document has no doctitle' do
+ pdf = to_pdf <<~'EOS', analyze: true
+ :toc:
+
+ == Section A
+
+ == Section B
+ EOS
+
+ toc_title_text = (pdf.find_text 'Table of Contents')[0]
+ sect_a_text = (pdf.find_text string: 'Section A', font_size: 22)[0]
+ (expect toc_title_text[:y]).to be > sect_a_text[:y]
+ end
+
it 'should reserve enough pages for toc if it spans more than one page' do
sections = (1..40).map {|num| %(\n\n== Section #{num}) }
input = <<~EOS