Skip to content

Commit

Permalink
resolves #1407 add an unbreakable option on open blocks (PR #1408)
Browse files Browse the repository at this point in the history
The content of an unbreakable open block will be kept together on the same page (if it fits on one page).
  • Loading branch information
ggrossetie authored and mojavelinux committed Nov 29, 2019
1 parent b7630cd commit dfd34f6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 51 additions & 0 deletions spec/example_spec.rb
Original file line number Diff line number Diff line change
@@ -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)}
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit dfd34f6

Please sign in to comment.