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

Fixes #259 - Sidebars now render on multiple pages #735

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 38 additions & 4 deletions lib/asciidoctor-pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,52 @@ def convert_sidebar node
add_dest_for_block node if node.id
theme_margin :block, :top
keep_together do |box_height = nil|
start_page_number = page_number
start_cursor = cursor
# FIXME? Have to draw graphics once before content to get accurate box_height.
# This is overwritten by the theme_fill_and_stroke_bounds command, so needs drawing twice
pad_box @theme.sidebar_padding do
if node.title?
theme_font :sidebar_title do
# QUESTION should we allow margins of sidebar title to be customized?
layout_heading node.title, align: (@theme.sidebar_title_align || @theme.base_align).to_sym, margin_top: 0
end
end
theme_font :sidebar do
convert_content_for_block node
end
end

if box_height
float do
bounding_box [0, cursor], width: bounds.width, height: box_height do
page_spread = (end_page_number = page_number) - start_page_number + 1
end_cursor = cursor
go_to_page start_page_number
move_cursor_to start_cursor
page_spread.times do |i|
if i == 0
y_draw = cursor
b_height = page_spread > 1 ? y_draw : (y_draw - end_cursor)
else
bounds.move_past_bottom
y_draw = cursor
b_height = page_spread - 1 == i ? (y_draw - end_cursor) : y_draw
end
bounding_box [0, y_draw], width: bounds.width, height: b_height do
theme_fill_and_stroke_bounds :sidebar
end
end
end

go_to_page start_page_number
move_cursor_to start_cursor
pad_box @theme.sidebar_padding do
if node.title?
theme_font :sidebar_title do
# QUESTION should we allow margins of sidebar title to be customized?
layout_heading node.title, align: (@theme.sidebar_title_align || @base_align).to_sym, margin_top: 0
# HACK: The "margin_top: 1" makes things work, but I don't know entirely why.
# Using the blockquote_padding above instead of sidebar_padding makes the blocks render with the wrong padding.
# Using the sidebar_padding it loses the background on subsequent pages unless margin_top is 1 here.
# QUESTION should we allow margins of sidebar title to be customized?
layout_heading node.title, align: (@theme.sidebar_title_align || @theme.base_align).to_sym, margin_top: 1
end
end
theme_font :sidebar do
Expand Down