diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-04-27 04:28:52 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2022-04-27 04:29:45 -0600 |
| commit | bd51a9dbc6fad55d5f2847449fd6f2b057cb52a1 (patch) | |
| tree | a0a59eb09214df2200923ea83331946a96fe336f | |
| parent | b61215ead9cc35c3ac9981bb50fd9ea30615226b (diff) | |
delete dests on page before deleting it
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/ext/prawn/extensions.rb | 2 | ||||
| -rw-r--r-- | spec/section_spec.rb | 19 |
3 files changed, 22 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index c5ecd8c3..8285674d 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -21,6 +21,7 @@ Bug Fixes:: * pass through warnings in background SVG to logger (#1940) * keep closing quote with trailing ellipsis in text enclosed in typographic quotes (#321) * collapse space in front of hidden index term (#2061) +* delete dests on page before deleting it (keeps generated PDF clean of obsolete destinations) == 2.0.0.alpha.1 (2022-04-20) - @mojavelinux diff --git a/lib/asciidoctor/pdf/ext/prawn/extensions.rb b/lib/asciidoctor/pdf/ext/prawn/extensions.rb index db33e7cc..fcafe60c 100644 --- a/lib/asciidoctor/pdf/ext/prawn/extensions.rb +++ b/lib/asciidoctor/pdf/ext/prawn/extensions.rb @@ -818,6 +818,8 @@ module Asciidoctor pg = page_number pdf_store = state.store content_id = page.content.identifier + page_ref = page.dictionary + dests.data.children.delete_if {|entry| entry.value.data[0] == page_ref } # NOTE: cannot delete objects and IDs, otherwise references get corrupted; so just reset the value (pdf_store.instance_variable_get :@objects)[content_id] = ::PDF::Core::Reference.new content_id, {} pdf_store.pages.data[:Kids].pop diff --git a/spec/section_spec.rb b/spec/section_spec.rb index 4f36430d..a0fe54f6 100644 --- a/spec/section_spec.rb +++ b/spec/section_spec.rb @@ -748,6 +748,25 @@ describe 'Asciidoctor::PDF::Converter - Section' do (expect appendix_text[:page_number]).to be 5 end + it 'should not leave behind dest for empty section marked with untitled option' do + pdf = to_pdf <<~'EOS' + = Document Title + :doctype: book + + == Chapter + + Musings. + + [colophon%untitled] + == Hidden + EOS + + (expect pdf.pages).to have_size 2 + all_text = pdf.pages.map(&:text).join ?\n + (expect all_text).not_to include 'Hide Me' + (expect get_names pdf).not_to have_key '_hidden' + end + it 'should not promote anonymous preface in book doctype to preface section if preface-title attribute is not set' do input = <<~'EOS' = Book Title |
