diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-05-11 01:11:45 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-05-11 01:19:42 -0600 |
| commit | e8831a5f9c82f82dc463a24b2d02b07270d607bd (patch) | |
| tree | d29f24febffc0d1d2c942633ae209af70f1bc3f7 /spec | |
| parent | 96d57921a328fbaa2f077fe6cd597c4458611d67 (diff) | |
update extended converter that avoids a page break after a heading and use it in the test case
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/floating_title_spec.rb | 35 | ||||
| -rw-r--r-- | spec/section_spec.rb | 36 |
2 files changed, 42 insertions, 29 deletions
diff --git a/spec/floating_title_spec.rb b/spec/floating_title_spec.rb index 398c4f70..ce284d3e 100644 --- a/spec/floating_title_spec.rb +++ b/spec/floating_title_spec.rb @@ -95,6 +95,41 @@ describe 'Asciidoctor::PDF::Converter - Floating Title' do (expect (get_dest pdf, 'buddy')[:page_number]).to eql 2 end + it 'should allow arrange_heading to be reimplemented to always keep heading with content that follows it' do + source_file = doc_file 'modules/extend/examples/pdf-converter-avoid-break-after-heading.rb' + source_lines = (File.readlines source_file).select {|l| l == ?\n || (l.start_with? ' ') } + ext_class = create_class Asciidoctor::Converter.for 'pdf' + backend = %(pdf#{ext_class.object_id}) + source_lines[0] = %( register_for '#{backend}'\n) + ext_class.class_eval source_lines.join, source_file + pdf = to_pdf <<~EOS, backend: backend, analyze: true + [discrete] + == Heading A + + [discrete] + == Heading B + + image::tall.svg[pdfwidth=65mm] + + [discrete] + == Heading C + + [%unbreakable] + -- + keep + + this + + together + -- + EOS + + heading_c_text = pdf.find_unique_text 'Heading C' + (expect heading_c_text[:page_number]).to be 2 + content_text = pdf.find_unique_text 'keep' + (expect content_text[:page_number]).to be 2 + end + it 'should not force discrete heading to next page if min_height_after value is not set' do pdf = with_content_spacer 10, 690 do |spacer_path| to_pdf <<~EOS, pdf_theme: { heading_min_height_after: nil } diff --git a/spec/section_spec.rb b/spec/section_spec.rb index 67e14c8f..976a5273 100644 --- a/spec/section_spec.rb +++ b/spec/section_spec.rb @@ -1023,35 +1023,13 @@ describe 'Asciidoctor::PDF::Converter - Section' do (expect content_text[:page_number]).to be 2 end - it 'should allow arrange_heading to be reimplemented to always keep section with content that follows' do - backend = nil - create_class (Asciidoctor::Converter.for 'pdf') do - register_for (backend = %(pdf#{object_id}).to_sym) - def arrange_heading node, title, opts - orphaned = nil - dry_run single_page: true do - start_page = page - theme_font :heading, level: opts[:level] do - if opts[:part] - layout_part_title node, title, opts - elsif opts[:chapterlike] - layout_chapter_title node, title, opts - else - layout_general_heading node, title, opts - end - end - if page == start_page - page.tare_content_stream - orphaned = stop_if_first_page_empty do - node.context == :section ? (traverse node) : (convert (siblings = node.parent.blocks)[(siblings.index node) + 1]) - end - end - end - start_new_page if orphaned - nil - end - end - + it 'should allow arrange_heading to be reimplemented to always keep section title with content that follows it' do + source_file = doc_file 'modules/extend/examples/pdf-converter-avoid-break-after-heading.rb' + source_lines = (File.readlines source_file).select {|l| l == ?\n || (l.start_with? ' ') } + ext_class = create_class Asciidoctor::Converter.for 'pdf' + backend = %(pdf#{ext_class.object_id}) + source_lines[0] = %( register_for '#{backend}'\n) + ext_class.class_eval source_lines.join, source_file pdf = to_pdf <<~EOS, backend: backend, analyze: true == Section A |
