asciidoctor-multipage 0.0.10 → 0.0.14

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 +79 -26
  3. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d54d7b18dc06a853c2c12062714158d3a65914b9f7aacda87ac0a939ddcc941
4
- data.tar.gz: 9857f979f3dcf2a4dc7faed2271549c4ff473a8fb356b8747673ee828a1a35cb
3
+ metadata.gz: ab1f550130f59f72549c38e53b85073052489f9447e9dcfd1122e3ffbc418c8e
4
+ data.tar.gz: 1984fe6907d211571d822451c90725984c14d22c993195508d6e6992d29ce333
5
5
  SHA512:
6
- metadata.gz: c8cd9b2025eddf8cd9a8c54b6dc0705d60b8757dc3d360cc98247e7df2d0569d1cd464892aed4d468e3320b96e31a4fefef1ca9c135798878d571692b367e476
7
- data.tar.gz: 99b46345a15d5e08fabe8a652644b094ef1287d34c2e32333417bbab60c4a63820d9a4f866f66087437cc8e2dae77bafc4662987f52f1083dc405b7201a8b23b
6
+ metadata.gz: 4566ce596a05c9a60866138d7ef8946121bef05d95648a14a304312a4a632ebcd85dbc077eeff045ef0d94d48b85064d8e15d438e9eb84d19ee4f432177f5b9c
7
+ data.tar.gz: 9652cb173af11948e16c3ed1d463922f88a233c4118c044ec2b2005095f9b3c9d0478c6f4d5967ff4f3f1b9b4149b709c68932684f21cdf3cc60e12bf68f3d6f
@@ -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
@@ -77,17 +85,11 @@ class Asciidoctor::Section
77
85
  # Sections. The sectnum is saved in section() below.
78
86
  def sectnum(delimiter = '.', append = nil)
79
87
  append ||= (append == false ? '' : delimiter)
80
- if @level == 1
81
- %(#{@numeral}#{append})
82
- elsif @level > 1
83
- if @parent.class == Asciidoctor::Section ||
84
- (@mplevel && @parent.class == Asciidoctor::Document)
88
+ if @level > 1 and @parent.class == Asciidoctor::Section ||
89
+ (@mplevel && @parent.class == Asciidoctor::Document)
85
90
  %(#{@parent.sectnum(delimiter)}#{@numeral}#{append})
86
- else
87
- %(#{@numeral}#{append})
88
- end
89
- else # @level == 0
90
- %(#{Asciidoctor::Helpers.int_to_roman @numeral}#{append})
91
+ else
92
+ %(#{@numeral}#{append})
91
93
  end
92
94
  end
93
95
  end
@@ -101,6 +103,12 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
101
103
 
102
104
  attr_accessor :pages
103
105
 
106
+ # contains the entire outline of the top-level document, used
107
+ # as a guide-rail for creating TOC elements for documents we
108
+ # split off. Only expected to be set in the top-level converter
109
+ # (see AsciiDoctor::Document::mp_root)
110
+ attr_accessor :full_outline
111
+
104
112
  def initialize(backend, opts = {})
105
113
  @xml_mode = false
106
114
  @void_element_slash = nil
@@ -118,8 +126,29 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
118
126
  page << block
119
127
  end
120
128
 
129
+ # ensures that the AsciiDoctor::Document::mp_root is correctly
130
+ # set on the document object. The variable could have already been
131
+ # set if we created the document ourselves
132
+ # (see ::MultipageHtml5Converter::convert_section), in which case it's
133
+ # not changed. If the documented is "nested", then we expect the parent
134
+ # document to already have it set. Otherwise, this is expected to be
135
+ # a top-level document, and we assign ourselves as its original converter.
136
+ def check_root(doc)
137
+ unless doc.mp_root
138
+ if doc.nested?
139
+ doc.mp_root = doc.parent_document.mp_root
140
+ else
141
+ doc.mp_root = self
142
+ end
143
+ end
144
+ end
145
+
121
146
  # Process Document (either the original full document or a processed page)
122
147
  def convert_document(node)
148
+
149
+ # make sure document has original converter reference
150
+ check_root(node)
151
+
123
152
  if node.processed
124
153
  # This node (an individual page) can now be handled by
125
154
  # Html5Converter.
@@ -166,8 +195,16 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
166
195
  # Generate navigation links for all pages
167
196
  generate_nav_links(node)
168
197
 
169
- # Create and save a skeleton document for generating the TOC lists.
170
- @@full_outline = new_outline_doc(node)
198
+ # Create and save a skeleton document for generating the TOC lists,
199
+ # but don't attempt to create outline for nested documents.
200
+ unless node.nested?
201
+ # if the original converter has the @full_outline set already, we are about
202
+ # to replace it. That's not supposed to happen, and probably means we encountered
203
+ # a document structure we aren't prepared for. Log an error and move on.
204
+ logger.error "Regenerating document outline, something wrong?" if node.mp_root.full_outline
205
+ node.mp_root.full_outline = new_outline_doc(node)
206
+ end
207
+
171
208
  # Save the document catalog to use for each part/chapter page.
172
209
  @catalog = node.catalog
173
210
 
@@ -179,7 +216,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
179
216
  part = block
180
217
  part.convert
181
218
  text = %(<<#{part.id},#{part.captioned_title}>>)
182
- if desc = block.attr('desc') then text << %( – #{desc}) end
219
+ if (desc = block.attr('desc')) then text << %( – #{desc}) end
183
220
  parts_list << Asciidoctor::ListItem.new(parts_list, text)
184
221
  end
185
222
  end
@@ -197,6 +234,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
197
234
  # Process Document in embeddable mode (either the original full document or a
198
235
  # processed page)
199
236
  def convert_embedded(node)
237
+ # make sure document has original converter reference
238
+ check_root(node)
200
239
  if node.processed
201
240
  # This node (an individual page) can now be handled by
202
241
  # Html5Converter.
@@ -223,14 +262,14 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
223
262
  # NOTE: There are some non-breaking spaces (U+00A0) below, in
224
263
  # the "links <<" lines and "links.join" line.
225
264
  if previous_page != parent_page
226
- links << %(← Previous: <<#{previous_page.id}>>)
265
+ links << %(← #{doc.attr('multipage-nav-previous-label') || "Previous"}: <<#{previous_page.id},#{previous_page.captioned_title}>>)
227
266
  end
228
- links << %(↑ Up: <<#{parent_page.id}>>)
229
- links << %(⌂ Home: <<#{home_page.id}>>) if home_page != parent_page
267
+ links << %(↑ #{doc.attr('multipage-nav-up-label') || "Up"}: <<#{parent_page.id},#{parent_page.captioned_title}>>)
268
+ links << %(⌂ #{doc.attr('multipage-nav-home-label') || "Home"}: <<#{home_page.id},#{home_page.captioned_title}>>) if home_page != parent_page
230
269
  end
231
270
  if page_index != pages.length-1
232
271
  next_page = pages[page_index+1]
233
- links << %(Next: <<#{next_page.id}>> →)
272
+ links << %(#{doc.attr('multipage-nav-next-label') || "Next"}: <<#{next_page.id},#{next_page.captioned_title}>> →)
234
273
  end
235
274
  block = Asciidoctor::Block.new(parent = doc,
236
275
  context = :paragraph,
@@ -317,9 +356,17 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
317
356
  else
318
357
  attrs = node.role ? %( class="#{node.role}") : ''
319
358
  unless (text = node.text)
320
- refid = node.attributes['refid']
321
- if AbstractNode === (ref = (@refs ||= node.document.catalog[:refs])[refid])
322
- text = (ref.xreftext node.attr('xrefstyle')) || %([#{refid}])
359
+ if AbstractNode === (ref = (@refs ||= node.document.catalog[:refs])[refid = node.attributes['refid']] || (refid.nil_or_empty? ? (top = get_root_document node) : nil))
360
+ if (@resolving_xref ||= (outer = true)) && outer
361
+ if (text = ref.xreftext node.attr 'xrefstyle', nil, true)
362
+ text = text.gsub DropAnchorRx, '' if text.include? '<a'
363
+ else
364
+ text = top ? '[^top]' : %([#{refid}])
365
+ end
366
+ @resolving_xref = nil
367
+ else
368
+ text = top ? '[^top]' : %([#{refid}])
369
+ end
323
370
  else
324
371
  text = %([#{refid}])
325
372
  end
@@ -350,14 +397,14 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
350
397
  end
351
398
 
352
399
  # 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
400
+ # TOC. This is first used to create a full skeleton (@full_outline) from the
354
401
  # original document (for_page=nil). Then it is used for each individual page
355
402
  # to create a second skeleton from the first. In this way, TOC entries are
356
403
  # included that are not part of the current page, or excluded if not
357
404
  # applicable for the current page.
358
405
  def new_outline_doc(node, new_parent:nil, for_page:nil)
359
406
  if node.class == Document
360
- new_document = Document.new([])
407
+ new_document = Document.new([], {:doctype => node.doctype})
361
408
  new_document.mplevel = node.mplevel
362
409
  new_document.id = node.id
363
410
  new_document.update_attributes(node.attributes)
@@ -374,6 +421,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
374
421
  level = node.level,
375
422
  numbered = node.numbered)
376
423
  new_section.id = node.id
424
+ new_section.sectname = node.sectname
377
425
  new_section.caption = node.caption
378
426
  new_section.title = node.instance_variable_get(:@title)
379
427
  new_section.mplevel = node.mplevel
@@ -392,10 +440,10 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
392
440
  # outline.
393
441
  def convert_outline(node, opts = {})
394
442
  doc = node.document
395
- # Find this node in the @@full_outline skeleton document
396
- page_node = @@full_outline.find_by(id: node.id).first
443
+ # Find this node in the @full_outline skeleton document
444
+ page_node = doc.mp_root.full_outline.find_by(id: node.id).first
397
445
  # Create a skeleton document for this particular page
398
- custom_outline_doc = new_outline_doc(@@full_outline, for_page: page_node)
446
+ custom_outline_doc = new_outline_doc(doc.mp_root.full_outline, for_page: page_node)
399
447
  opts[:page_id] = node.id
400
448
  # Generate an extra TOC entry for the root page. Add additional styling if
401
449
  # the current page is the root page.
@@ -455,6 +503,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
455
503
  page.sectnum = node.parent.sectnum
456
504
  end
457
505
 
506
+ page.mp_root = doc.mp_root
507
+
458
508
  # Process node according to mplevel
459
509
  if node.mplevel == :branch
460
510
  # Retain any part intro blocks, delete others, and add a list
@@ -537,7 +587,6 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
537
587
  # Write remaining part/chapter pages
538
588
  outdir = ::File.dirname(target)
539
589
  ext = ::File.extname(target)
540
- target_name = ::File.basename(target, ext)
541
590
  @pages.each do |doc|
542
591
  chapter_target = doc.id + ext
543
592
  outfile = ::File.join(outdir, chapter_target)
@@ -553,6 +602,10 @@ class MultipageHtml5CSS < Asciidoctor::Extensions::DocinfoProcessor
553
602
  at_location :head
554
603
 
555
604
  def process doc
605
+ # Disable this entirely if the multipage-disable-css attribute is set
606
+ if doc.attr('multipage-disable-css')
607
+ return
608
+ end
556
609
  css = []
557
610
  # Style Table Of Contents entry for current page
558
611
  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.10
4
+ version: 0.0.14
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-06-28 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -116,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.7.6.2
119
+ rubygems_version: 3.2.5
121
120
  signing_key:
122
121
  specification_version: 4
123
122
  summary: Asciidoctor multipage HTML output extension