-
Notifications
You must be signed in to change notification settings - Fork 500
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
resolves #1407 add a keep-together role on open blocks #1408
Conversation
lib/asciidoctor/pdf/converter.rb
Outdated
add_dest_for_block node if node.id | ||
layout_caption node.title if node.title? | ||
convert_content_for_block node | ||
if node.has_role? 'keep-together' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with AsciiDoc.py and other converters, this should instead check for the unbreakable role.
if node.option? 'unbreakable'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should instead check for the unbreakable role.
You mean option?
You can use the unbreakable option to instruct the browser not to break a block element. The following image and it’s caption will be kept together the printed page:
[options="unbreakable"] .Tiger block image image::images/tiger.png[Tiger image]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Or the shorthand for it:
[%unbreakable]
lib/asciidoctor/pdf/converter.rb
Outdated
layout_caption node.title if node.title? | ||
convert_content_for_block node | ||
if node.has_role? 'keep-together' | ||
keep_together do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make this DRY by using keep_together_if
, like:
keep_together_if node.option? 'unbreakable' do
To avoid footnotes from being duplicated, it's also necessary to add this line at the start of the block:
push_scratch doc if scratch?
and this line to the end:
pop_scratch doc if scratch?
In all, that looks like:
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review.
I wasn't aware of this issue with footnotes. I will add footnotes in my test to make sure that they are not duplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird, and I wish it was handled by keep_together. But that would require some refactoring. For now, we just add it where keep_together is used.
cd1a03b
to
eead3c9
Compare
@@ -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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
eead3c9
to
c9af084
Compare
I think the block also has to break across pages in the scratch document,
at which point it will try to render it a second time.
…On Thu, Nov 28, 2019, 03:11 Guillaume Grossetie ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In spec/example_spec.rb
<#1408 (comment)>
:
> @@ -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]
I did add a footnote before the open block, inside the open block and
after the open block 🤔
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#1408?email_source=notifications&email_token=AAATL57DNKO2VIGS4TPE4R3QV54KNA5CNFSM4JRAHZA2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCNIYVHQ#discussion_r351636946>,
or unsubscribe
</~https://github.com/notifications/unsubscribe-auth/AAATL53YZ2KQZBLM4PF3RO3QV54KNANCNFSM4JRAHZAQ>
.
|
Oh I see, that's a good thing to test (ie. when an unbreakable block does not fit on a page). I will add a test. |
The content of an unbreakable open block will be kept together on the same page (if it fits on one page).
c9af084
to
5f5adf8
Compare
No description provided.