asciidoctor-lists-extended 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eea56f2723162b60d59bbb2d93db827851391f3e6ad27868e79e3cd48260087e
4
- data.tar.gz: 0c8f0a1cea5a7afd52c934b43e41557f7e41869e9ffe4fc159a7cfc70fd0ee8d
3
+ metadata.gz: 20b4b4c3fb341f36f3b9dd69840f85583edaed9f6096fd98c5efc3e157b0ce48
4
+ data.tar.gz: 64bd1d98f9bdc723e89201273322ce6e956377fd38279cfad2f8aa9cd0689b8e
5
5
  SHA512:
6
- metadata.gz: 2e901929fc60afc373360eaa07f0822a05a12270c2fc9c6757741d8e52db864702f663b03921d35f497b5583daa884ed63da9eea99ebb88434f0461675ed1c98
7
- data.tar.gz: 92059b3b00548fd752791b1bda2abef6d7288d1dc9b0726b23fe499e0a4e00db9b25e3e64b7a72f3bbc400a698596285af6934175e8f00f22d51f5ecdfc4d03f
6
+ metadata.gz: d4be7d908d7e8c87b414114aca35859a3c7b398e0108b8621546792a14d246cb230f706e2f001fc0d2fcb4935c640c300765f5eb05ae781e0e93970acdf60bf2
7
+ data.tar.gz: 80feadacf0d0fa247540de19d98f308e6693fbd29e3e4073bb51ee11103596bfd117f7b4339fdade68ac9472b8743ce715e36d65620adf69660eac795de52e64
@@ -39,6 +39,8 @@ module Asciidoctor
39
39
  @list_first_entry_margin = nil
40
40
  @list_toc_insert_idx = 0
41
41
  @virtual_list_sections = [] # list-of:: virtual sections, kept for running content
42
+ @virtual_section_indices = {} # section → original index in parent.blocks
43
+ @toc_only_extent = nil # extent of the real ToC pages, without list-of pages
42
44
  end
43
45
 
44
46
  # -----------------------------------------------------------------------
@@ -69,6 +71,20 @@ module Asciidoctor
69
71
  mark_empty_list_sections doc
70
72
  result = super
71
73
  collect_and_allocate_lists doc, num_levels, toc_start_cursor, break_after_toc
74
+ # The extent stored as @toc_extent must cover the list-of pages inserted
75
+ # after the ToC, otherwise page-numbering-start-at/running-content-start-at
76
+ # 'after-toc' and the PDF page labels treat those pages as body content.
77
+ # Keep the unextended extent so ink_running_content can hand core the real
78
+ # ToC page range (core stamps the toc-title on every page of @toc_extent).
79
+ @toc_only_extent = result
80
+ if result && !@list_extents.empty?
81
+ last_to = @list_extents.values.map(&:to).max_by { |pos| [pos.page, -(pos.cursor || 0)] }
82
+ if last_to.page > result.to.page ||
83
+ (last_to.page == result.to.page && (last_to.cursor || 0) < (result.to.cursor || 0))
84
+ result = result.dup
85
+ result.to = last_to.dup
86
+ end
87
+ end
72
88
  result
73
89
  end
74
90
 
@@ -175,6 +191,29 @@ module Asciidoctor
175
191
  # the duration of the indexing pass, then purge again so they cannot leak
176
192
  # into the scratch/final document tree.
177
193
  def ink_running_content(periphery, doc, *args)
194
+ # Core stamps the toc-title on every page covered by @toc_extent, which
195
+ # now also spans the list-of pages (see allocate_toc). Swap in the
196
+ # ToC-only extent so the list-of pages keep their own running titles
197
+ # (supplied by the reinserted virtual sections below).
198
+ widened_toc_extent = @toc_extent
199
+ @toc_extent = @toc_only_extent if @toc_only_extent
200
+ reinsert_virtual_list_sections doc
201
+ super
202
+ ensure
203
+ @toc_extent = widened_toc_extent
204
+ purge_virtual_sections doc
205
+ end
206
+
207
+ # -----------------------------------------------------------------------
208
+ # add_outline override
209
+ # -----------------------------------------------------------------------
210
+ # asciidoctor-pdf builds the PDF bookmark outline from doc.sections after
211
+ # ink_toc has returned, i.e. after ink_toc's ensure already purged the
212
+ # list-of:: virtual sections. Re-insert them for the duration of the
213
+ # outline build (same compensating pattern as ink_running_content), then
214
+ # purge again. add_outline_level's list-exclude-from-outline filter
215
+ # still applies to the reinserted sections.
216
+ def add_outline(doc, *args)
178
217
  reinsert_virtual_list_sections doc
179
218
  super
180
219
  ensure
@@ -182,12 +221,20 @@ module Asciidoctor
182
221
  end
183
222
 
184
223
  # Restore the retained list-of:: virtual sections into their original
185
- # parent so doc.find_by(context: :section) can see them again.
224
+ # parent so doc.find_by(context: :section) can see them again. Each
225
+ # section goes back to the block index recorded by purge_virtual_sections;
226
+ # position matters because doc.sections (derived from blocks order) drives
227
+ # the PDF bookmark outline order in add_outline.
186
228
  def reinsert_virtual_list_sections(doc)
187
229
  @virtual_list_sections.each do |sect|
188
230
  parent = sect.parent || doc
189
- parent.blocks << sect if parent.respond_to?(:blocks) && !(parent.blocks.include? sect)
190
- parent.sections << sect if parent.respond_to?(:sections) && !(parent.sections.include? sect)
231
+ next unless parent.respond_to?(:blocks) && !(parent.blocks.include? sect)
232
+ idx = @virtual_section_indices[sect]
233
+ if idx && idx <= parent.blocks.size
234
+ parent.blocks.insert idx, sect
235
+ else
236
+ parent.blocks << sect
237
+ end
191
238
  end
192
239
  end
193
240
 
@@ -332,12 +379,20 @@ module Asciidoctor
332
379
  # they cannot leak into subsequent passes or downstream section processing.
333
380
  def purge_virtual_sections(doc)
334
381
  return unless doc
335
- doc.find_by(context: :section).each do |sect|
336
- next unless sect.attr? 'list-virtual-section'
382
+ virtuals = doc.find_by(context: :section).select { |sect| sect.attr? 'list-virtual-section' }
383
+ # Record each section's block index before any deletion shifts the
384
+ # indices; reinsert_virtual_list_sections uses them to restore the
385
+ # sections at their original positions.
386
+ virtuals.each do |sect|
387
+ parent = sect.parent
388
+ next unless parent.respond_to? :blocks
389
+ idx = parent.blocks.index sect
390
+ @virtual_section_indices[sect] = idx if idx
391
+ end
392
+ virtuals.each do |sect|
337
393
  parent = sect.parent
338
394
  next unless parent
339
395
  parent.blocks.delete sect if parent.respond_to? :blocks
340
- parent.sections.delete sect if parent.respond_to? :sections
341
396
  end
342
397
  end
343
398
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-lists-extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - 白一百 baiyibai