Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #1407 add a keep-together role on open blocks #1408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even without push_scratch doc if scratch? and pop_scratch doc if scratch? the footnotes are not duplicated so I'm not sure how to test this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The footnotes have to be inside the open block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did add a footnote before the open block, inside the open block and after the open block 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. The scenario is that the footnote is in the open block, but not inside another nested block. In the test, the footnote is in an admonition block, which masks the problem.


#{(['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.