Skip to content

Commit

Permalink
resolves asciidoctor#2158 do not orphan sidebar title
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed May 11, 2022
1 parent 3c3d9d4 commit 72ecbee
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Enhancements::

Bug Fixes::

* do not orphan sidebar title (#2158)
* allow theme to set font style of first line of abstract to `normal_italic` (#2138)
* add support for `:color` option to `Prawn::Text::Formatted::Box` directly and remove workarounds
* preserve columns on subsequent pages in the index section (#2149)
Expand Down
8 changes: 5 additions & 3 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,11 @@ def convert_sidebar node
add_dest_for_block node if node.id
theme_fill_and_stroke_block :sidebar, extent if extent
pad_box @theme.sidebar_padding, node do
theme_font :sidebar_title do
# QUESTION: should we allow margins of sidebar title to be customized?
ink_prose node.title, align: (@theme.sidebar_title_text_align || @theme.heading_text_align || @base_text_align).to_sym, margin_bottom: @theme.heading_margin_bottom, line_height: (@theme.heading_line_height || @theme.base_line_height)
tare_first_page_content_stream do
theme_font :sidebar_title do
# QUESTION: should we allow margins of sidebar title to be customized?
ink_prose node.title, align: (@theme.sidebar_title_text_align || @theme.heading_text_align || @base_text_align).to_sym, margin_bottom: @theme.heading_margin_bottom, line_height: (@theme.heading_line_height || @theme.base_line_height)
end
end if node.title?
theme_font :sidebar do
traverse node
Expand Down
31 changes: 31 additions & 0 deletions spec/sidebar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,37 @@
(expect sidebar_text[:page_number]).to be 2
end

it 'should keep title with content when block is advanced to next page' do
pdf_theme = {
sidebar_border_radius: 0,
sidebar_border_width: 0,
sidebar_background_color: 'DFDFDF',
}
pdf = with_content_spacer 10, 680 do |spacer_path|
to_pdf <<~EOS, pdf_theme: pdf_theme, analyze: true
image::#{spacer_path}[]
.Sidebar Title
****
First block of content.
****
EOS
end

pages = pdf.pages
(expect pages).to have_size 2
title_text = pdf.find_unique_text 'Sidebar Title'
content_text = pdf.find_unique_text 'First block of content.'
(expect title_text[:page_number]).to be 2
(expect content_text[:page_number]).to be 2
(pdf.extract_graphic_states pages[0][:raw_content]).each do |p1_gs|
(expect p1_gs).not_to include '0.87451 0.87451 0.87451 scn'
end
p2_gs = (pdf.extract_graphic_states pages[1][:raw_content])[0]
(expect p2_gs).to have_background color: 'DFDFDF', top_left: [48.24, 805.89], bottom_right: [547.04, 737.63]
end

it 'should split block if it cannot fit on one page' do
pdf = to_pdf <<~EOS, analyze: true
.Sidebar Title
Expand Down

0 comments on commit 72ecbee

Please sign in to comment.