summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-06-23 13:02:05 -0600
committerGitHub <noreply@github.com>2022-06-23 13:02:05 -0600
commit0166f33cd712ed2731111db4d274b0a8fc2019c4 (patch)
treeec87ebadcd8df318d23a07b66df87c2a83f0fed6
parentde8298e20ee98ba94d412a8f367a97140f168f6c (diff)
resolves #2255 interpret start-at theme keys with value 1 correctly (PR #2256)
-rw-r--r--.github/workflows/ci.yml3
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/converter.rb8
-rw-r--r--spec/running_content_spec.rb51
4 files changed, 59 insertions, 4 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9fa1bc20..f9e3923a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -54,6 +54,9 @@ jobs:
# remove 3.1 on ubuntu-latest to mark as primary
- os: ubuntu-latest
ruby: '3.1'
+ # jruby-9.3 on windows-latest is currently broken in GitHub Actions
+ - os: windows-latest
+ ruby: jruby-9.3
include:
- os: ubuntu-latest
ruby: jruby-9.2
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 56a6d5a5..de63e340 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -15,6 +15,7 @@ Enhancements::
Bug Fixes::
+* interpret `start-at` theme keys with value `1` correctly (as `1` instead of `2`) (#2255)
* fix crash when border color is transparent (thematic_break_border_color, admonition_column_rule, quote_border_color, verse_border_color)
* verify page margin is restored after imported page
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 74089f4c..ee444b01 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -213,7 +213,7 @@ module Asciidoctor
first_page_offset = has_title_page ? zero_page_offset.next : zero_page_offset
body_offset = (body_start_page_number = page_number) - 1
if ::Integer === (running_content_start_at = @theme.running_content_start_at)
- running_content_body_offset = body_offset + [running_content_start_at.pred, 1].max
+ running_content_body_offset = body_offset + [running_content_start_at.pred, 0].max
running_content_start_at = 'body'
else
running_content_body_offset = body_offset
@@ -227,7 +227,7 @@ module Asciidoctor
end
end
if ::Integer === (page_numbering_start_at = @theme.page_numbering_start_at)
- page_numbering_body_offset = body_offset + [page_numbering_start_at.pred, 1].max
+ page_numbering_body_offset = body_offset + [page_numbering_start_at.pred, 0].max
page_numbering_start_at = 'body'
else
page_numbering_body_offset = body_offset
@@ -263,12 +263,12 @@ module Asciidoctor
else
body_offset = body_start_page_number - 1
if ::Integer === (running_content_start_at = @theme.running_content_start_at)
- running_content_body_offset = body_offset + [running_content_start_at.pred, 1].max
+ running_content_body_offset = body_offset + [running_content_start_at.pred, 0].max
else
running_content_body_offset = body_offset
end
if ::Integer === (page_numbering_start_at = @theme.page_numbering_start_at)
- page_numbering_body_offset = body_offset + [page_numbering_start_at.pred, 1].max
+ page_numbering_body_offset = body_offset + [page_numbering_start_at.pred, 0].max
elsif page_numbering_start_at == 'cover' && has_front_cover
page_numbering_body_offset = 0
else
diff --git a/spec/running_content_spec.rb b/spec/running_content_spec.rb
index a80ba030..527de36b 100644
--- a/spec/running_content_spec.rb
+++ b/spec/running_content_spec.rb
@@ -811,6 +811,57 @@ describe 'Asciidoctor::PDF::Converter - Running Content' do
(expect pgnum_labels.slice 0, 5).to eql [nil, 'ii', 'iii', '1', '2']
end
+ it 'should start page numbering and running content at first page of article body if start-at value is body or 1' do
+ [1, 'body'].each do |start_at|
+ pdf = to_pdf <<~'EOS', enable_footer: true, pdf_theme: { page_numbering_start_at: start_at, running_content_start_at: start_at }, analyze: true
+ = Article Title
+
+ page one
+
+ <<<
+
+ page two
+
+ <<<
+
+ page three
+ EOS
+
+ (expect pdf.pages).to have_size 3
+ pgnum_labels = (1.upto pdf.pages.size).each_with_object [] do |page_number, accum|
+ accum << ((pdf.find_text page_number: page_number, y: 14.263)[-1] || {})[:string]
+ end
+ (expect pgnum_labels).to eql %w(1 2 3)
+ end
+ end
+
+ it 'should start page numbering and running content at first page of book body if start-at value is body or 1' do
+ [1, 'body'].each do |start_at|
+ pdf = to_pdf <<~'EOS', enable_footer: true, pdf_theme: { page_numbering_start_at: start_at, running_content_start_at: start_at }, analyze: true
+ = Book Title
+ :doctype: book
+
+ == Dedication
+
+ To the only person who gets me.
+
+ == Acknowledgements
+
+ Thanks all to all who made this possible!
+
+ == Chapter One
+
+ content
+ EOS
+
+ (expect pdf.pages).to have_size 4
+ pgnum_labels = (1.upto pdf.pages.size).each_with_object [] do |page_number, accum|
+ accum << ((pdf.find_text page_number: page_number, y: 14.263)[-1] || {})[:string]
+ end
+ (expect pgnum_labels).to eql [nil, '1', '2', '3']
+ end
+ end
+
it 'should start page numbering and running content at specified page of body' do
pdf = to_pdf <<~'EOS', enable_footer: true, pdf_theme: { page_numbering_start_at: 3, running_content_start_at: 3 }, analyze: true
= Book Title