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

Conversation

ggrossetie
Copy link
Member

No description provided.

@mojavelinux mojavelinux self-requested a review November 28, 2019 06:09
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'
Copy link
Member

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'

Copy link
Member Author

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]

https://www.methods.co.nz/asciidoc/faq.html#_how_can_i_control_page_breaks_when_printing_html_outputs

Copy link
Member

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]

layout_caption node.title if node.title?
convert_content_for_block node
if node.has_role? 'keep-together'
keep_together do
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.

@ggrossetie ggrossetie force-pushed the issue-1407-keep-together-block branch from cd1a03b to eead3c9 Compare November 28, 2019 07:46
@@ -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]
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.

@ggrossetie ggrossetie force-pushed the issue-1407-keep-together-block branch from eead3c9 to c9af084 Compare November 28, 2019 07:49
@mojavelinux
Copy link
Member

mojavelinux commented Nov 28, 2019 via email

@ggrossetie
Copy link
Member Author

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).
@ggrossetie ggrossetie force-pushed the issue-1407-keep-together-block branch from c9af084 to 5f5adf8 Compare November 28, 2019 16:18
@mojavelinux mojavelinux merged commit dfd34f6 into asciidoctor:master Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants