asciidoctor-lists-extended 1.1.10 → 1.2.2
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eea56f2723162b60d59bbb2d93db827851391f3e6ad27868e79e3cd48260087e
|
|
4
|
+
data.tar.gz: 0c8f0a1cea5a7afd52c934b43e41557f7e41869e9ffe4fc159a7cfc70fd0ee8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e901929fc60afc373360eaa07f0822a05a12270c2fc9c6757741d8e52db864702f663b03921d35f497b5583daa884ed63da9eea99ebb88434f0461675ed1c98
|
|
7
|
+
data.tar.gz: 92059b3b00548fd752791b1bda2abef6d7288d1dc9b0726b23fe499e0a4e00db9b25e3e64b7a72f3bbc400a698596285af6934175e8f00f22d51f5ecdfc4d03f
|
|
@@ -38,6 +38,7 @@ 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
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
# -----------------------------------------------------------------------
|
|
@@ -82,15 +83,20 @@ module Asciidoctor
|
|
|
82
83
|
def ink_toc(doc, num_levels, toc_page_number, start_cursor, num_front_matter_pages = 0)
|
|
83
84
|
@inline_num_front_matter_pages = num_front_matter_pages
|
|
84
85
|
@list_toc_insert_idx = 0
|
|
86
|
+
@virtual_list_sections = []
|
|
85
87
|
|
|
86
88
|
# toc-in-toc: insert the Table of Contents itself as the first entry in
|
|
87
89
|
# the PDF ToC, before any list-of:: sections. Excluded from the bookmark
|
|
88
90
|
# outline because asciidoctor-pdf's add_outline already adds a ToC bookmark.
|
|
89
|
-
|
|
91
|
+
# IMPORTANT: do this in both scratch and final passes. During scratch,
|
|
92
|
+
# @toc_extent may not yet be set; fall back to toc_page_number so the
|
|
93
|
+
# dry-run ToC entry count/height matches the final pass.
|
|
94
|
+
if doc.attr? 'toc-in-toc'
|
|
90
95
|
toc_entry_title = doc.attr('toc-title') || 'Table of Contents'
|
|
91
|
-
|
|
96
|
+
toc_entry_range = @toc_extent&.page_range || (toc_page_number..toc_page_number)
|
|
97
|
+
insert_list_into_toc_section doc, toc_entry_title, toc_entry_range,
|
|
92
98
|
'_toc_in_toc', @list_toc_insert_idx,
|
|
93
|
-
pdf_dest: dest_top(@toc_extent.page_range.first),
|
|
99
|
+
pdf_dest: (@toc_extent ? dest_top(@toc_extent.page_range.first) : nil),
|
|
94
100
|
exclude_from_outline: true
|
|
95
101
|
@list_toc_insert_idx += 1
|
|
96
102
|
end
|
|
@@ -107,10 +113,13 @@ module Asciidoctor
|
|
|
107
113
|
# Bare macros (no parent section and no title= attribute) have no
|
|
108
114
|
# meaningful label for the ToC or outline — skip the virtual section.
|
|
109
115
|
unless list_title.nil_or_empty?
|
|
110
|
-
insert_list_into_toc_section doc, list_title, list_page_nums, list_id, @list_toc_insert_idx,
|
|
116
|
+
virtual_section = insert_list_into_toc_section doc, list_title, list_page_nums, list_id, @list_toc_insert_idx,
|
|
111
117
|
pdf_dest: @last_list_dest || dest_top(list_page_nums.first),
|
|
112
118
|
exclude_from_toc: resolve_exclude_from_toc(config),
|
|
113
119
|
exclude_from_outline: resolve_exclude_from_outline(config)
|
|
120
|
+
# Retain a reference so running content can show the list title on its
|
|
121
|
+
# own pages; the section itself is purged from the tree below.
|
|
122
|
+
@virtual_list_sections << virtual_section
|
|
114
123
|
@list_toc_insert_idx += 1
|
|
115
124
|
end
|
|
116
125
|
end
|
|
@@ -118,6 +127,7 @@ module Asciidoctor
|
|
|
118
127
|
result = super
|
|
119
128
|
|
|
120
129
|
# Phase 2: render deferred inline section-scoped lists.
|
|
130
|
+
|
|
121
131
|
# traverse doc has completed before ink_toc is called, so all
|
|
122
132
|
# pdf-page-start attributes are now set and page numbers are real.
|
|
123
133
|
unless @inline_render_positions.empty?
|
|
@@ -150,6 +160,35 @@ module Asciidoctor
|
|
|
150
160
|
end
|
|
151
161
|
|
|
152
162
|
result
|
|
163
|
+
ensure
|
|
164
|
+
purge_virtual_sections doc
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# -----------------------------------------------------------------------
|
|
168
|
+
# ink_running_content override
|
|
169
|
+
# -----------------------------------------------------------------------
|
|
170
|
+
# asciidoctor-pdf builds its per-page running-content title map from
|
|
171
|
+
# doc.find_by(context: :section), keyed by each section's pdf-page-start.
|
|
172
|
+
# Our list-of:: virtual sections carry both a title and a pdf-page-start,
|
|
173
|
+
# but they were purged in ink_toc's ensure (which runs before this), so the
|
|
174
|
+
# list-of pages fall back to the preface/chapter title. Re-insert them for
|
|
175
|
+
# the duration of the indexing pass, then purge again so they cannot leak
|
|
176
|
+
# into the scratch/final document tree.
|
|
177
|
+
def ink_running_content(periphery, doc, *args)
|
|
178
|
+
reinsert_virtual_list_sections doc
|
|
179
|
+
super
|
|
180
|
+
ensure
|
|
181
|
+
purge_virtual_sections doc
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# Restore the retained list-of:: virtual sections into their original
|
|
185
|
+
# parent so doc.find_by(context: :section) can see them again.
|
|
186
|
+
def reinsert_virtual_list_sections(doc)
|
|
187
|
+
@virtual_list_sections.each do |sect|
|
|
188
|
+
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)
|
|
191
|
+
end
|
|
153
192
|
end
|
|
154
193
|
|
|
155
194
|
# -----------------------------------------------------------------------
|
|
@@ -175,6 +214,16 @@ module Asciidoctor
|
|
|
175
214
|
super outline, filtered, num_levels, expand_levels
|
|
176
215
|
end
|
|
177
216
|
|
|
217
|
+
# -----------------------------------------------------------------------
|
|
218
|
+
# convert_section override
|
|
219
|
+
# -----------------------------------------------------------------------
|
|
220
|
+
# Virtual sections inserted only to drive ToC/outline entries should not
|
|
221
|
+
# be rendered as normal body headings during document traversal.
|
|
222
|
+
def convert_section(node, *args)
|
|
223
|
+
return if node.attr? 'list-virtual-section'
|
|
224
|
+
super node, *args
|
|
225
|
+
end
|
|
226
|
+
|
|
178
227
|
# -----------------------------------------------------------------------
|
|
179
228
|
# convert_paragraph override
|
|
180
229
|
# -----------------------------------------------------------------------
|
|
@@ -276,6 +325,22 @@ module Asciidoctor
|
|
|
276
325
|
|
|
277
326
|
private
|
|
278
327
|
|
|
328
|
+
# -----------------------------------------------------------------------
|
|
329
|
+
# purge_virtual_sections
|
|
330
|
+
# -----------------------------------------------------------------------
|
|
331
|
+
# Remove synthetic sections inserted only for ToC/outline generation so
|
|
332
|
+
# they cannot leak into subsequent passes or downstream section processing.
|
|
333
|
+
def purge_virtual_sections(doc)
|
|
334
|
+
return unless doc
|
|
335
|
+
doc.find_by(context: :section).each do |sect|
|
|
336
|
+
next unless sect.attr? 'list-virtual-section'
|
|
337
|
+
parent = sect.parent
|
|
338
|
+
next unless parent
|
|
339
|
+
parent.blocks.delete sect if parent.respond_to? :blocks
|
|
340
|
+
parent.sections.delete sect if parent.respond_to? :sections
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
279
344
|
# -----------------------------------------------------------------------
|
|
280
345
|
# mark_empty_list_sections
|
|
281
346
|
# -----------------------------------------------------------------------
|
|
@@ -115,11 +115,25 @@ module Asciidoctor
|
|
|
115
115
|
base_idx = 0
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
+
# If a virtual section with this id was already inserted during an earlier
|
|
119
|
+
# pass (e.g. scratch before final), refresh it in place rather than
|
|
120
|
+
# inserting a duplicate that would skew ToC height and entry count.
|
|
121
|
+
if (existing = grandparent_section.blocks.find { |b| b.context == :section && b.id == list_id })
|
|
122
|
+
existing.title = list_title
|
|
123
|
+
existing.set_attr 'pdf-destination', pdf_dest if pdf_dest
|
|
124
|
+
existing.set_attr 'pdf-page-start', list_page_nums.first
|
|
125
|
+
existing.set_attr 'list-virtual-section', ''
|
|
126
|
+
exclude_from_toc ? existing.set_attr('list-exclude-from-toc', '') : existing.remove_attr('list-exclude-from-toc')
|
|
127
|
+
exclude_from_outline ? existing.set_attr('list-exclude-from-outline', '') : existing.remove_attr('list-exclude-from-outline')
|
|
128
|
+
return existing
|
|
129
|
+
end
|
|
130
|
+
|
|
118
131
|
list_section = Asciidoctor::Section.new grandparent_section, toc_level, false
|
|
119
132
|
list_section.set_attr 'pdf-destination', pdf_dest if pdf_dest
|
|
120
133
|
list_section.title = list_title
|
|
121
134
|
list_section.id = list_id
|
|
122
135
|
list_section.set_attr 'pdf-page-start', list_page_nums.first
|
|
136
|
+
list_section.set_attr 'list-virtual-section', ''
|
|
123
137
|
list_section.set_attr 'list-exclude-from-toc', '' if exclude_from_toc
|
|
124
138
|
list_section.set_attr 'list-exclude-from-outline', '' if exclude_from_outline
|
|
125
139
|
grandparent_section.blocks.insert base_idx + insert_idx, list_section
|