Skip to content

Commit

Permalink
resolves #1407 add an unbreable option on open blocks
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 committed Nov 28, 2019
1 parent b7630cd commit c9af084
Show file tree
Hide file tree
Showing 3 changed files with 32 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
24 changes: 24 additions & 0 deletions spec/example_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
require_relative 'spec_helper'

describe 'Asciidoctor::PDF::Converter - Example' do
it 'should keep block together when block has the unbreakable option' do
to_file = to_pdf_file <<~EOS, 'example-unbreakable-option.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.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 added spec/reference/example-unbreakable-option.pdf
Binary file not shown.

0 comments on commit c9af084

Please sign in to comment.