asciidoctor-lists-extended 1.2.1 → 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 +4 -4
- data/lib/asciidoctor-lists-extended/pdf_converter.rb +91 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20b4b4c3fb341f36f3b9dd69840f85583edaed9f6096fd98c5efc3e157b0ce48
|
|
4
|
+
data.tar.gz: 64bd1d98f9bdc723e89201273322ce6e956377fd38279cfad2f8aa9cd0689b8e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4be7d908d7e8c87b414114aca35859a3c7b398e0108b8621546792a14d246cb230f706e2f001fc0d2fcb4935c640c300765f5eb05ae781e0e93970acdf60bf2
|
|
7
|
+
data.tar.gz: 80feadacf0d0fa247540de19d98f308e6693fbd29e3e4073bb51ee11103596bfd117f7b4339fdade68ac9472b8743ce715e36d65620adf69660eac795de52e64
|
|
@@ -38,6 +38,9 @@ module Asciidoctor
|
|
|
38
38
|
@list_entry_indent = nil
|
|
39
39
|
@list_first_entry_margin = nil
|
|
40
40
|
@list_toc_insert_idx = 0
|
|
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
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
# -----------------------------------------------------------------------
|
|
@@ -68,6 +71,20 @@ module Asciidoctor
|
|
|
68
71
|
mark_empty_list_sections doc
|
|
69
72
|
result = super
|
|
70
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
|
|
71
88
|
result
|
|
72
89
|
end
|
|
73
90
|
|
|
@@ -82,6 +99,7 @@ module Asciidoctor
|
|
|
82
99
|
def ink_toc(doc, num_levels, toc_page_number, start_cursor, num_front_matter_pages = 0)
|
|
83
100
|
@inline_num_front_matter_pages = num_front_matter_pages
|
|
84
101
|
@list_toc_insert_idx = 0
|
|
102
|
+
@virtual_list_sections = []
|
|
85
103
|
|
|
86
104
|
# toc-in-toc: insert the Table of Contents itself as the first entry in
|
|
87
105
|
# the PDF ToC, before any list-of:: sections. Excluded from the bookmark
|
|
@@ -111,10 +129,13 @@ module Asciidoctor
|
|
|
111
129
|
# Bare macros (no parent section and no title= attribute) have no
|
|
112
130
|
# meaningful label for the ToC or outline — skip the virtual section.
|
|
113
131
|
unless list_title.nil_or_empty?
|
|
114
|
-
insert_list_into_toc_section doc, list_title, list_page_nums, list_id, @list_toc_insert_idx,
|
|
132
|
+
virtual_section = insert_list_into_toc_section doc, list_title, list_page_nums, list_id, @list_toc_insert_idx,
|
|
115
133
|
pdf_dest: @last_list_dest || dest_top(list_page_nums.first),
|
|
116
134
|
exclude_from_toc: resolve_exclude_from_toc(config),
|
|
117
135
|
exclude_from_outline: resolve_exclude_from_outline(config)
|
|
136
|
+
# Retain a reference so running content can show the list title on its
|
|
137
|
+
# own pages; the section itself is purged from the tree below.
|
|
138
|
+
@virtual_list_sections << virtual_section
|
|
118
139
|
@list_toc_insert_idx += 1
|
|
119
140
|
end
|
|
120
141
|
end
|
|
@@ -159,6 +180,64 @@ module Asciidoctor
|
|
|
159
180
|
purge_virtual_sections doc
|
|
160
181
|
end
|
|
161
182
|
|
|
183
|
+
# -----------------------------------------------------------------------
|
|
184
|
+
# ink_running_content override
|
|
185
|
+
# -----------------------------------------------------------------------
|
|
186
|
+
# asciidoctor-pdf builds its per-page running-content title map from
|
|
187
|
+
# doc.find_by(context: :section), keyed by each section's pdf-page-start.
|
|
188
|
+
# Our list-of:: virtual sections carry both a title and a pdf-page-start,
|
|
189
|
+
# but they were purged in ink_toc's ensure (which runs before this), so the
|
|
190
|
+
# list-of pages fall back to the preface/chapter title. Re-insert them for
|
|
191
|
+
# the duration of the indexing pass, then purge again so they cannot leak
|
|
192
|
+
# into the scratch/final document tree.
|
|
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)
|
|
217
|
+
reinsert_virtual_list_sections doc
|
|
218
|
+
super
|
|
219
|
+
ensure
|
|
220
|
+
purge_virtual_sections doc
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Restore the retained list-of:: virtual sections into their original
|
|
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.
|
|
228
|
+
def reinsert_virtual_list_sections(doc)
|
|
229
|
+
@virtual_list_sections.each do |sect|
|
|
230
|
+
parent = sect.parent || doc
|
|
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
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
|
|
162
241
|
# -----------------------------------------------------------------------
|
|
163
242
|
# get_entries_for_toc override
|
|
164
243
|
# -----------------------------------------------------------------------
|
|
@@ -300,12 +379,20 @@ module Asciidoctor
|
|
|
300
379
|
# they cannot leak into subsequent passes or downstream section processing.
|
|
301
380
|
def purge_virtual_sections(doc)
|
|
302
381
|
return unless doc
|
|
303
|
-
doc.find_by(context: :section).
|
|
304
|
-
|
|
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|
|
|
305
393
|
parent = sect.parent
|
|
306
394
|
next unless parent
|
|
307
395
|
parent.blocks.delete sect if parent.respond_to? :blocks
|
|
308
|
-
parent.sections.delete sect if parent.respond_to? :sections
|
|
309
396
|
end
|
|
310
397
|
end
|
|
311
398
|
|