Skip to content

Commit

Permalink
resolves asciidoctor#1795 don't insert page break between part and fi…
Browse files Browse the repository at this point in the history
…rst chapter if heading-part-break-after key in theme is avoid
  • Loading branch information
mojavelinux committed Jun 10, 2022
1 parent 8d25b99 commit fd9ae86
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/theme/pages/heading.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/asciidoctor/pdf/ext/asciidoctor/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions spec/section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd9ae86

Please sign in to comment.