asciidoctor-multipage 0.0.6 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor-multipage.rb +69 -12
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37d22229b52f7ecc747f4c4f80fcfe6b3d097d49a0ba7c1e375de6f72280c950
|
4
|
+
data.tar.gz: 901b657b48543dc3466154c0ba5d00d82d639f1b72a747eae5bb5821cd287cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52c37d84631c4d9bbdd02a272fd61dd5c5cf26b6a60f2e203378ca0dc669edd731284b13bf5d9fdfae601209ae38ddf9647ad8e7091e7a46b6810cb5beb7e6a6
|
7
|
+
data.tar.gz: 7bf7e7e32dac50d8619ee1ac52e9bc501c2d1cb5585e391f7501ed2b6e7bd1ab67b265c7e7d1a4e2df5cc95e0077fcdd768faaf76d1b6e886894140b85669bec
|
@@ -52,6 +52,14 @@ class Asciidoctor::Document
|
|
52
52
|
# nodes are no longer accessible.
|
53
53
|
attr_writer :sectnum
|
54
54
|
|
55
|
+
# A pointer to the original converter (first converter instantiated to
|
56
|
+
# convert the original document). As we create additional documents
|
57
|
+
# ourselves, AsciiDoctor will instantiate additional instances of
|
58
|
+
# MultipageHtml5Converter for each created document. These instances need
|
59
|
+
# to share state, so they can use the original converter instance
|
60
|
+
# for that purpose.
|
61
|
+
attr_accessor :mp_root
|
62
|
+
|
55
63
|
# Override the AbstractBlock sections?() check to enable the Table Of
|
56
64
|
# Contents. This extension may generate short pages that would normally have
|
57
65
|
# no need for a TOC. However, we override the Html5Converter outline() in
|
@@ -101,6 +109,12 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
101
109
|
|
102
110
|
attr_accessor :pages
|
103
111
|
|
112
|
+
# contains the entire outline of the top-level document, used
|
113
|
+
# as a guide-rail for creating TOC elements for documents we
|
114
|
+
# split off. Only expected to be set in the top-level converter
|
115
|
+
# (see AsciiDoctor::Document::mp_root)
|
116
|
+
attr_accessor :full_outline
|
117
|
+
|
104
118
|
def initialize(backend, opts = {})
|
105
119
|
@xml_mode = false
|
106
120
|
@void_element_slash = nil
|
@@ -118,8 +132,29 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
118
132
|
page << block
|
119
133
|
end
|
120
134
|
|
135
|
+
# ensures that the AsciiDoctor::Document::mp_root is correctly
|
136
|
+
# set on the document object. The variable could have already been
|
137
|
+
# set if we created the document ourselves
|
138
|
+
# (see ::MultipageHtml5Converter::convert_section), in which case it's
|
139
|
+
# not changed. If the documented is "nested", then we expect the parent
|
140
|
+
# document to already have it set. Otherwise, this is expected to be
|
141
|
+
# a top-level document, and we assign ourselves as its original converter.
|
142
|
+
def check_root(doc)
|
143
|
+
unless doc.mp_root
|
144
|
+
if doc.nested?
|
145
|
+
doc.mp_root = doc.parent_document.mp_root
|
146
|
+
else
|
147
|
+
doc.mp_root = self
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
121
152
|
# Process Document (either the original full document or a processed page)
|
122
153
|
def convert_document(node)
|
154
|
+
|
155
|
+
# make sure document has original converter reference
|
156
|
+
check_root(node)
|
157
|
+
|
123
158
|
if node.processed
|
124
159
|
# This node (an individual page) can now be handled by
|
125
160
|
# Html5Converter.
|
@@ -166,8 +201,16 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
166
201
|
# Generate navigation links for all pages
|
167
202
|
generate_nav_links(node)
|
168
203
|
|
169
|
-
# Create and save a skeleton document for generating the TOC lists
|
170
|
-
|
204
|
+
# Create and save a skeleton document for generating the TOC lists,
|
205
|
+
# but don't attempt to create outline for nested documents.
|
206
|
+
unless node.nested?
|
207
|
+
# if the original converter has the @full_outline set already, we are about
|
208
|
+
# to replace it. That's not supposed to happen, and probably means we encountered
|
209
|
+
# a document structure we aren't prepared for. Log an error and move on.
|
210
|
+
logger.error "Regenerating document outline, something wrong?" if node.mp_root.full_outline
|
211
|
+
node.mp_root.full_outline = new_outline_doc(node)
|
212
|
+
end
|
213
|
+
|
171
214
|
# Save the document catalog to use for each part/chapter page.
|
172
215
|
@catalog = node.catalog
|
173
216
|
|
@@ -179,7 +222,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
179
222
|
part = block
|
180
223
|
part.convert
|
181
224
|
text = %(<<#{part.id},#{part.captioned_title}>>)
|
182
|
-
if desc = block.attr('desc') then text << %( – #{desc}) end
|
225
|
+
if (desc = block.attr('desc')) then text << %( – #{desc}) end
|
183
226
|
parts_list << Asciidoctor::ListItem.new(parts_list, text)
|
184
227
|
end
|
185
228
|
end
|
@@ -197,6 +240,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
197
240
|
# Process Document in embeddable mode (either the original full document or a
|
198
241
|
# processed page)
|
199
242
|
def convert_embedded(node)
|
243
|
+
# make sure document has original converter reference
|
244
|
+
check_root(node)
|
200
245
|
if node.processed
|
201
246
|
# This node (an individual page) can now be handled by
|
202
247
|
# Html5Converter.
|
@@ -244,7 +289,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
244
289
|
# Generate the actual HTML outline for the TOC. This method is analogous to
|
245
290
|
# Html5Converter convert_outline().
|
246
291
|
def generate_outline(node, opts = {})
|
247
|
-
|
292
|
+
# Do the same as Html5Converter convert_outline() here
|
293
|
+
return unless node.sections? && node.sections.length > 0
|
248
294
|
sectnumlevels = opts[:sectnumlevels] || (node.document.attributes['sectnumlevels'] || 3).to_i
|
249
295
|
toclevels = opts[:toclevels] || (node.document.attributes['toclevels'] || 2).to_i
|
250
296
|
sections = node.sections
|
@@ -254,7 +300,17 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
254
300
|
if section.caption
|
255
301
|
stitle = section.captioned_title
|
256
302
|
elsif section.numbered && slevel <= sectnumlevels
|
257
|
-
|
303
|
+
if slevel < 2 && node.document.doctype == 'book'
|
304
|
+
if section.sectname == 'chapter'
|
305
|
+
stitle = %(#{(signifier = node.document.attributes['chapter-signifier']) ? "#{signifier} " : ''}#{section.sectnum} #{section.title})
|
306
|
+
elsif section.sectname == 'part'
|
307
|
+
stitle = %(#{(signifier = node.document.attributes['part-signifier']) ? "#{signifier} " : ''}#{section.sectnum nil, ':'} #{section.title})
|
308
|
+
else
|
309
|
+
stitle = %(#{section.sectnum} #{section.title})
|
310
|
+
end
|
311
|
+
else
|
312
|
+
stitle = %(#{section.sectnum} #{section.title})
|
313
|
+
end
|
258
314
|
else
|
259
315
|
stitle = section.title
|
260
316
|
end
|
@@ -339,7 +395,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
339
395
|
end
|
340
396
|
|
341
397
|
# From node, create a skeleton document that will be used to generate the
|
342
|
-
# TOC. This is first used to create a full skeleton (
|
398
|
+
# TOC. This is first used to create a full skeleton (@full_outline) from the
|
343
399
|
# original document (for_page=nil). Then it is used for each individual page
|
344
400
|
# to create a second skeleton from the first. In this way, TOC entries are
|
345
401
|
# included that are not part of the current page, or excluded if not
|
@@ -349,8 +405,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
349
405
|
new_document = Document.new([])
|
350
406
|
new_document.mplevel = node.mplevel
|
351
407
|
new_document.id = node.id
|
352
|
-
new_document.
|
353
|
-
new_document.set_attr('toclevels', node.attr(:toclevels))
|
408
|
+
new_document.update_attributes(node.attributes)
|
354
409
|
new_parent = new_document
|
355
410
|
node.sections.each do |section|
|
356
411
|
new_outline_doc(section, new_parent: new_parent,
|
@@ -365,7 +420,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
365
420
|
numbered = node.numbered)
|
366
421
|
new_section.id = node.id
|
367
422
|
new_section.caption = node.caption
|
368
|
-
new_section.title = node.title
|
423
|
+
new_section.title = node.instance_variable_get(:@title)
|
369
424
|
new_section.mplevel = node.mplevel
|
370
425
|
new_parent << new_section
|
371
426
|
new_parent.sections.last.numeral = node.numeral
|
@@ -382,10 +437,10 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
382
437
|
# outline.
|
383
438
|
def convert_outline(node, opts = {})
|
384
439
|
doc = node.document
|
385
|
-
# Find this node in the
|
386
|
-
page_node =
|
440
|
+
# Find this node in the @full_outline skeleton document
|
441
|
+
page_node = doc.mp_root.full_outline.find_by(id: node.id).first
|
387
442
|
# Create a skeleton document for this particular page
|
388
|
-
custom_outline_doc = new_outline_doc(
|
443
|
+
custom_outline_doc = new_outline_doc(doc.mp_root.full_outline, for_page: page_node)
|
389
444
|
opts[:page_id] = node.id
|
390
445
|
# Generate an extra TOC entry for the root page. Add additional styling if
|
391
446
|
# the current page is the root page.
|
@@ -445,6 +500,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
|
|
445
500
|
page.sectnum = node.parent.sectnum
|
446
501
|
end
|
447
502
|
|
503
|
+
page.mp_root = doc.mp_root
|
504
|
+
|
448
505
|
# Process node according to mplevel
|
449
506
|
if node.mplevel == :branch
|
450
507
|
# Retain any part intro blocks, delete others, and add a list
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-multipage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen T. Heisler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.2.18
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 2.2.18
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|