asciidoctor-multipage 0.0.3 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor-multipage.rb +37 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a5ff94840e2e4523863cb2af46b47b5aceff1c29134981ad340bedf7a4f7a98
4
- data.tar.gz: '09b697ab1f70e465671a91a9ec5c3298a46b09d2dab339e11480fd2ef8c77b9a'
3
+ metadata.gz: 3435558e6b1ec2f99470f6a67d9a027065b468f3748d56e56a46a96277c321dc
4
+ data.tar.gz: f29752bc09d665574e6611a6fa1bd12b267b01aecd3f9e9d7d0221ebde712a90
5
5
  SHA512:
6
- metadata.gz: 3ef5c6fb1342caf81d3d5de94df89618ef511642832e1b95103ac7d1058fb7e4339f01b6e3e684f2a2c996dcc958d76aac0e087eec5cf46a08c71888f38593ce
7
- data.tar.gz: 7c87db46a76d677f09d96b6dfcde997f37e4ea08aea5467e130a5511a25b81626bed2c5d312d2dfc270ad3dc6fe2eba7f33cb258dfdee36236dc8c65872b1a28
6
+ metadata.gz: dac5c572a56aa2583f64c9082cb9d849a32cb0fc89125e169d18bf49cae5b0a77652a324d1dedae2948d1904fca8a8eb91161c274400bf3308d4d572e4b84c05
7
+ data.tar.gz: 4b0c20879b47c5eafde65125f7fba029e15f0c4f5fea708ef6e8199ce98ee761586b588801b48fce481f3bc3fbdbd2f6d35beb4619d839c645933f6956c811aa
@@ -17,6 +17,7 @@ class Asciidoctor::AbstractNode
17
17
  node_tree << current
18
18
  current = current.parent
19
19
  end
20
+ node_tree << current
20
21
  if node_tree.include?(self) ||
21
22
  node_tree.include?(self.parent)
22
23
  return true
@@ -120,7 +121,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
120
121
  # Process Document (either the original full document or a processed page)
121
122
  def convert_document(node)
122
123
  if node.processed
123
- # This node can now be handled by Html5Converter.
124
+ # This node (an individual page) can now be handled by
125
+ # Html5Converter.
124
126
  super
125
127
  else
126
128
  # This node is the original full document which has not yet been
@@ -146,6 +148,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
146
148
  # Set multipage chunk types
147
149
  set_multipage_attrs(node)
148
150
 
151
+ # FIXME: This can result in a duplicate ID without a warning.
149
152
  # Set the "id" attribute for the Document, using the "docname", which is
150
153
  # based on the file name. Then register the document ID using the
151
154
  # document title. This allows cross-references to refer to (1) the
@@ -195,12 +198,13 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
195
198
  # processed page)
196
199
  def convert_embedded(node)
197
200
  if node.processed
198
- # This node can now be handled by Html5Converter.
201
+ # This node (an individual page) can now be handled by
202
+ # Html5Converter.
199
203
  super
200
204
  else
201
205
  # This node is the original full document which has not yet been
202
- # processed; it can be handled by document().
203
- document(node)
206
+ # processed; it can be handled by convert_document().
207
+ convert_document(node)
204
208
  end
205
209
  end
206
210
 
@@ -216,7 +220,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
216
220
  previous_page = pages[page_index-1]
217
221
  parent_page = page.parent
218
222
  home_page = doc
219
- # NOTE, there are some non-breaking spaces (U+00A0) below.
223
+ # NOTE: There are some non-breaking spaces (U+00A0) below, in
224
+ # the "links <<" lines and "links.join" line.
220
225
  if previous_page != parent_page
221
226
  links << %(← Previous: <<#{previous_page.id}>>)
222
227
  end
@@ -237,12 +242,12 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
237
242
  end
238
243
 
239
244
  # Generate the actual HTML outline for the TOC. This method is analogous to
240
- # Html5Converter outline().
245
+ # Html5Converter convert_outline().
241
246
  def generate_outline(node, opts = {})
242
- # This is the same as Html5Converter outline()
247
+ # Do the same as Html5Converter convert_outline() here
243
248
  return unless node.sections?
244
- sectnumlevels = opts[:sectnumlevels] || (node.document.attr 'sectnumlevels', 3).to_i
245
- toclevels = opts[:toclevels] || (node.document.attr 'toclevels', 2).to_i
249
+ sectnumlevels = opts[:sectnumlevels] || (node.document.attributes['sectnumlevels'] || 3).to_i
250
+ toclevels = opts[:toclevels] || (node.document.attributes['toclevels'] || 2).to_i
246
251
  sections = node.sections
247
252
  result = [%(<ul class="sectlevel#{sections[0].level}">)]
248
253
  sections.each do |section|
@@ -250,7 +255,17 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
250
255
  if section.caption
251
256
  stitle = section.captioned_title
252
257
  elsif section.numbered && slevel <= sectnumlevels
253
- stitle = %(#{section.sectnum} #{section.title})
258
+ if slevel < 2 && node.document.doctype == 'book'
259
+ if section.sectname == 'chapter'
260
+ stitle = %(#{(signifier = node.document.attributes['chapter-signifier']) ? "#{signifier} " : ''}#{section.sectnum} #{section.title})
261
+ elsif section.sectname == 'part'
262
+ stitle = %(#{(signifier = node.document.attributes['part-signifier']) ? "#{signifier} " : ''}#{section.sectnum nil, ':'} #{section.title})
263
+ else
264
+ stitle = %(#{section.sectnum} #{section.title})
265
+ end
266
+ else
267
+ stitle = %(#{section.sectnum} #{section.title})
268
+ end
254
269
  else
255
270
  stitle = section.title
256
271
  end
@@ -277,12 +292,12 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
277
292
  end
278
293
  result << %(<li><a href="#{link}">#{stitle}</a>)
279
294
 
280
- # Finish in a manner similar to Html5Converter outline()
295
+ # Finish in a manner similar to Html5Converter convert_outline()
281
296
  if slevel < toclevels &&
282
297
  (child_toc_level = generate_outline section,
283
- :toclevels => toclevels,
284
- :secnumlevels => sectnumlevels,
285
- :page_id => opts[:page_id])
298
+ toclevels: toclevels,
299
+ secnumlevels: sectnumlevels,
300
+ page_id: opts[:page_id])
286
301
  result << child_toc_level
287
302
  end
288
303
  result << '</li>'
@@ -361,7 +376,7 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
361
376
  numbered = node.numbered)
362
377
  new_section.id = node.id
363
378
  new_section.caption = node.caption
364
- new_section.title = node.title
379
+ new_section.title = node.instance_variable_get(:@title)
365
380
  new_section.mplevel = node.mplevel
366
381
  new_parent << new_section
367
382
  new_parent.sections.last.numeral = node.numeral
@@ -374,7 +389,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
374
389
  return new_document
375
390
  end
376
391
 
377
- # Override Html5Converter outline() to return a custom TOC outline
392
+ # Override Html5Converter convert_outline() to return a custom TOC
393
+ # outline.
378
394
  def convert_outline(node, opts = {})
379
395
  doc = node.document
380
396
  # Find this node in the @@full_outline skeleton document
@@ -486,7 +502,8 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
486
502
  doc = node.document
487
503
  node.mplevel = :root if node.class == Asciidoctor::Document
488
504
  node.sections.each do |section|
489
- # Check custom multipage-level attribute on section
505
+ # Check custom multipage-level attribute on section; warn and
506
+ # discard if invalid
490
507
  if section.attr?('multipage-level', nil, false) &&
491
508
  section.attr('multipage-level').to_i <
492
509
  node.attr('multipage-level').to_i
@@ -494,15 +511,15 @@ class MultipageHtml5Converter < Asciidoctor::Converter::Html5Converter
494
511
  %(section cannot be less than the parent section value)
495
512
  section.set_attr('multipage-level', nil)
496
513
  end
497
- # Propogate custom multipage-level value to child node
514
+ # Propagate custom multipage-level value to child node
498
515
  if !section.attr?('multipage-level', nil, false) &&
499
516
  node.attr('multipage-level') != doc.attr('multipage-level')
500
517
  section.set_attr('multipage-level', node.attr('multipage-level'))
501
518
  end
502
519
  # Set section type
503
- if section.level < section.attr('multipage-level').to_i
520
+ if section.level < section.attr('multipage-level', nil, true).to_i
504
521
  section.mplevel = :branch
505
- elsif section.level == section.attr('multipage-level').to_i
522
+ elsif section.level == section.attr('multipage-level', nil, true).to_i
506
523
  section.mplevel = :leaf
507
524
  else
508
525
  section.mplevel = :content
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.3
4
+ version: 0.0.8
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-01 00:00:00.000000000 Z
11
+ date: 2021-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal