asciidoctor-multipage 0.0.8 → 0.0.12

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor-multipage.rb +60 -10
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3435558e6b1ec2f99470f6a67d9a027065b468f3748d56e56a46a96277c321dc
4
- data.tar.gz: f29752bc09d665574e6611a6fa1bd12b267b01aecd3f9e9d7d0221ebde712a90
3
+ metadata.gz: 8dde62d4d7f18540dc3e7036e56164735b62d17b4ceb1e59c70cda3be3c7eb1a
4
+ data.tar.gz: ddb2f5f95f7652417ab331d2ce51c142ba182111b2fae2700ef4f0d852e67452
5
5
  SHA512:
6
- metadata.gz: dac5c572a56aa2583f64c9082cb9d849a32cb0fc89125e169d18bf49cae5b0a77652a324d1dedae2948d1904fca8a8eb91161c274400bf3308d4d572e4b84c05
7
- data.tar.gz: 4b0c20879b47c5eafde65125f7fba029e15f0c4f5fea708ef6e8199ce98ee761586b588801b48fce481f3bc3fbdbd2f6d35beb4619d839c645933f6956c811aa
6
+ metadata.gz: 62dbd38773aca9623da5783014315f9b9c42b5b0aefc1fbcf6f3ad4289a167a9908e15ccd5361f8fdf29cfd9372a91da004a0278da302dcff2b2c7872b71c4ab
7
+ data.tar.gz: c5aea9e7d3cc3fbc23171f9ee07fd367c74df8af17bfab0ed0580fc0765538d6fb91ec5f4217adf89901f8d962ccb213f90a7dd7dfd796eac898c46ecad65518
@@ -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
- @@full_outline = new_outline_doc(node)
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.
@@ -245,7 +290,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
245
290
  # Html5Converter convert_outline().
246
291
  def generate_outline(node, opts = {})
247
292
  # Do the same as Html5Converter convert_outline() here
248
- return unless node.sections?
293
+ return unless node.sections? && node.sections.length > 0
249
294
  sectnumlevels = opts[:sectnumlevels] || (node.document.attributes['sectnumlevels'] || 3).to_i
250
295
  toclevels = opts[:toclevels] || (node.document.attributes['toclevels'] || 2).to_i
251
296
  sections = node.sections
@@ -350,7 +395,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
350
395
  end
351
396
 
352
397
  # From node, create a skeleton document that will be used to generate the
353
- # TOC. This is first used to create a full skeleton (@@full_outline) from the
398
+ # TOC. This is first used to create a full skeleton (@full_outline) from the
354
399
  # original document (for_page=nil). Then it is used for each individual page
355
400
  # to create a second skeleton from the first. In this way, TOC entries are
356
401
  # included that are not part of the current page, or excluded if not
@@ -360,8 +405,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
360
405
  new_document = Document.new([])
361
406
  new_document.mplevel = node.mplevel
362
407
  new_document.id = node.id
363
- new_document.set_attr('sectnumlevels', node.attr(:sectnumlevels))
364
- new_document.set_attr('toclevels', node.attr(:toclevels))
408
+ new_document.update_attributes(node.attributes)
365
409
  new_parent = new_document
366
410
  node.sections.each do |section|
367
411
  new_outline_doc(section, new_parent: new_parent,
@@ -393,10 +437,10 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
393
437
  # outline.
394
438
  def convert_outline(node, opts = {})
395
439
  doc = node.document
396
- # Find this node in the @@full_outline skeleton document
397
- page_node = @@full_outline.find_by(id: node.id).first
440
+ # Find this node in the @full_outline skeleton document
441
+ page_node = doc.mp_root.full_outline.find_by(id: node.id).first
398
442
  # Create a skeleton document for this particular page
399
- custom_outline_doc = new_outline_doc(@@full_outline, for_page: page_node)
443
+ custom_outline_doc = new_outline_doc(doc.mp_root.full_outline, for_page: page_node)
400
444
  opts[:page_id] = node.id
401
445
  # Generate an extra TOC entry for the root page. Add additional styling if
402
446
  # the current page is the root page.
@@ -456,6 +500,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
456
500
  page.sectnum = node.parent.sectnum
457
501
  end
458
502
 
503
+ page.mp_root = doc.mp_root
504
+
459
505
  # Process node according to mplevel
460
506
  if node.mplevel == :branch
461
507
  # Retain any part intro blocks, delete others, and add a list
@@ -554,6 +600,10 @@ class MultipageHtml5CSS < Asciidoctor::Extensions::DocinfoProcessor
554
600
  at_location :head
555
601
 
556
602
  def process doc
603
+ # Disable this entirely if the multipage-disable-css attribute is set
604
+ if doc.attr('multipage-disable-css')
605
+ return
606
+ end
557
607
  css = []
558
608
  # Style Table Of Contents entry for current page
559
609
  css << %(.toc-current{font-weight: bold;})
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.8
4
+ version: 0.0.12
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-02-28 00:00:00.000000000 Z
11
+ date: 2021-07-19 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: '1'
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: '1'
40
+ version: 2.2.18
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement