diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 7a51da103..3b3a9f3e3 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -12,6 +12,7 @@ Enhancements:: * add `save_theme` helper to work with a copy of the theme within a scope (#2196) * add support for `scale` attribute or `iw` unit on `pdfwidth` attribute on image macros (#1933) * add backlink from bibref on bibliography entry to first reference to that entry in the document (#1737) +* don't insert page break between part and first chapter if `heading-part-break-after` key in theme is `avoid` (#1795) == 2.0.8 (2022-06-08) - @mojavelinux diff --git a/docs/modules/theme/pages/heading.adoc b/docs/modules/theme/pages/heading.adoc index bd40ffb84..4f0a006d0 100644 --- a/docs/modules/theme/pages/heading.adoc +++ b/docs/modules/theme/pages/heading.adoc @@ -286,7 +286,7 @@ The doctype must be `book` for the `heading-part` keys to take effect. |Key |Value Type |Example |break-after -|`always` {vbar} `auto` + +|`always` {vbar} `avoid` {vbar} `auto` + (default: `auto`) |[source] heading: diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 208a1579d..7fb6fc737 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -578,6 +578,8 @@ def prepare_theme theme theme.base_font_style = theme.base_font_style&.to_sym || :normal theme.page_numbering_start_at ||= 'body' theme.running_content_start_at ||= 'body' + theme.heading_chapter_break_before ||= 'always' + theme.heading_part_break_before ||= 'always' theme.heading_margin_page_top ||= 0 theme.heading_margin_top ||= 0 theme.heading_margin_bottom ||= 0 @@ -657,13 +659,14 @@ def convert_section sect, _opts = {} hidden = sect.option? 'notitle' hopts = { align: text_align, level: hlevel, part: part, chapterlike: chapterlike, outdent: !(part || chapterlike) } if part - unless @theme.heading_part_break_before == 'auto' + if @theme.heading_part_break_before == 'always' started_new = true start_new_part sect end elsif chapterlike - if @theme.heading_chapter_break_before != 'auto' || - (@theme.heading_part_break_after == 'always' && sect == sect.parent.sections[0]) + if (@theme.heading_chapter_break_before == 'always' && + !(@theme.heading_part_break_after == 'avoid' && sect.first_section_of_part?)) || + (@theme.heading_part_break_after == 'always' && sect.first_section_of_part?) started_new = true start_new_chapter sect end diff --git a/lib/asciidoctor/pdf/ext/asciidoctor/section.rb b/lib/asciidoctor/pdf/ext/asciidoctor/section.rb index 2428a47c3..28d011c53 100644 --- a/lib/asciidoctor/pdf/ext/asciidoctor/section.rb +++ b/lib/asciidoctor/pdf/ext/asciidoctor/section.rb @@ -30,4 +30,8 @@ def numbered_title opts = {} end opts[:formal] ? @cached_formal_numbered_title : @cached_numbered_title end unless method_defined? :numbered_title + + def first_section_of_part? + (par = @parent).context == :section && par.sectname == 'part' && self == par.blocks.find {|it| it.context == :section } + end unless method_defined? :first_section_of_part? end diff --git a/spec/section_spec.rb b/spec/section_spec.rb index b267bf2f9..332ea23df 100644 --- a/spec/section_spec.rb +++ b/spec/section_spec.rb @@ -1185,6 +1185,24 @@ (expect part2_text[:page_number]).to be 4 end + it 'should not add page break after part if heading-part-break-after key in theme is avoid' do + pdf = to_pdf <<~'EOS', pdf_theme: { heading_part_break_after: 'avoid' }, analyze: true + = Document Title + :doctype: book + + = Part I + + == Chapter in Part I + EOS + + (expect pdf.pages).to have_size 2 + part1_text = (pdf.find_text 'Part I')[0] + chapter1_text = (pdf.find_text 'Chapter in Part I')[0] + (expect part1_text[:page_number]).to be 2 + (expect chapter1_text[:page_number]).to be 2 + (expect part1_text[:y] - chapter1_text[:y]).to be < 50 + end + it 'should support abstract defined as special section' do pdf = to_pdf <<~'EOS', analyze: true = Document Title