diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 6a076223d..543ce2358 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -931,9 +931,14 @@ def convert_open node # TODO process abstract child even when partintro has multiple blocks convert_abstract node.blocks[0] else - add_dest_for_block node if node.id - layout_caption node.title if node.title? - convert_content_for_block node + doc = node.document + keep_together_if node.option? 'unbreakable' do + push_scratch doc if scratch? + add_dest_for_block node if node.id + layout_caption node.title if node.title? + convert_content_for_block node + pop_scratch doc if scratch? + end end end diff --git a/spec/example_spec.rb b/spec/example_spec.rb index fef884932..ea1b67dff 100644 --- a/spec/example_spec.rb +++ b/spec/example_spec.rb @@ -1,6 +1,57 @@ require_relative 'spec_helper' describe 'Asciidoctor::PDF::Converter - Example' do + it 'should keep block together when it has the unbreakable option' do + to_file = to_pdf_file <<~EOS, 'example-unbreakable-option-fit.pdf' + Make it rain.footnote:[money] + + #{(['filler'] * 21).join %(\n\n)} + [%unbreakable] + -- + To install Antora, open a terminal and type: + + $ npm i -g @antora/cli@2.2 @antora/site-generator-default@2.2 + + IMPORTANT: The `@` at the beginning of the package name is important. + It tells `npm` that the `cli` package is located in the `antora` group. + If you omit this character, `npm` will assume the package name is the name of a git repository on GitHub. + The second `@` offsets the requested version number.footnote:[Clarification about this statement.] + Only the major and minor segments are specified to ensure you receive the latest patch update. + -- + + Make it snow.footnote:[dollar bills] + EOS + + (expect to_file).to visually_match 'example-unbreakable-option-fit.pdf' + end + + it 'should break an unbreakable block if it does not fit on one page' do + to_file = to_pdf_file <<~EOS, 'example-unbreakable-option-break.pdf' + Make it rain.footnote:[money] + + #{(['filler'] * 21).join %(\n\n)} + + [%unbreakable] + -- + To install Antora, open a terminal and type: + + $ npm i -g @antora/cli@2.2 @antora/site-generator-default@2.2 + + IMPORTANT: The `@` at the beginning of the package name is important. + It tells `npm` that the `cli` package is located in the `antora` group. + If you omit this character, `npm` will assume the package name is the name of a git repository on GitHub. + The second `@` offsets the requested version number.footnote:[Clarification about this statement.] + Only the major and minor segments are specified to ensure you receive the latest patch update. + + #{(['filler'] * 25).join %(\n\n)} + -- + + Make it snow.footnote:[dollar bills] + EOS + + (expect to_file).to visually_match 'example-unbreakable-option-break.pdf' + end + it 'should keep block together if it can fit on one page' do pdf = to_pdf <<~EOS, analyze: true #{(['filler'] * 15).join %(\n\n)} diff --git a/spec/reference/example-unbreakable-option-break.pdf b/spec/reference/example-unbreakable-option-break.pdf new file mode 100644 index 000000000..35bce444d Binary files /dev/null and b/spec/reference/example-unbreakable-option-break.pdf differ diff --git a/spec/reference/example-unbreakable-option-fit.pdf b/spec/reference/example-unbreakable-option-fit.pdf new file mode 100644 index 000000000..7c0e44207 Binary files /dev/null and b/spec/reference/example-unbreakable-option-fit.pdf differ