asciidoctor-lists-extended 1.1.7 → 1.1.8

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: c214e4770c4445a9daa0344bcf022895ce0f4172dfc3a1c1c13c01f36b01faa8
4
- data.tar.gz: 80c15b6379aff0506b06f9b488cc6ac518f97048b775cf99c49271731552c9ce
3
+ metadata.gz: e5957e1ace3164d5cb55fd2a56ec3bdc815b51f20d11a4b1ccf2ce90266f5601
4
+ data.tar.gz: 9aa5f6a0fd2d1dbe1aa708443117ae531f05408d32bb79cdf1dd6ceec01b6a1a
5
5
  SHA512:
6
- metadata.gz: fd41e36b82b84c0d3ebb3bcbf5438d1a27f67b9f6d57d83085c178191e42820a30418c55928fff84b53f608459d1fa96daa77cfef13cf416157bcbbdc861fb8b
7
- data.tar.gz: aa7e49c4c3d4b80638f5dd7e5f4bd9a75eecd3d58d85c129dc313f6f69ae79d31b73b0e60c400f7353846afbabbb3b44790d95e0010cbc9611db50a6185d6c8d
6
+ metadata.gz: '06381153db44ca502bc4e6b121bb1df9815b0beb1733dd143f8c6d45744684f6de7b1a4508d9069b8cdbdc1b548858748d722277c71aa72adec3be615fc6a7f4'
7
+ data.tar.gz: 07e3de4563cff3a8688520829ab6dbda68f3376d3d03ae0ef2e5c738db0a07c598d5ad6cbc508e7eacc7d09494ceec0e576e4789e1ea10f3f86eddd660f02849
data/README.adoc CHANGED
@@ -8,6 +8,8 @@ A converter-aware asciidoctor extension that generates a *List of Figures*, *Lis
8
8
  Replaces and supersedes `asciidoctor-pdf-lofte`.
9
9
  Compatible with the `asciidoctor-lists` macro syntax.
10
10
 
11
+ https://baiyibai-antora.gitlab.io
12
+
11
13
  == Preview
12
14
 
13
15
  .Table of Contents with List of Figures, List of Tables, and List of Examples entries
@@ -35,27 +37,80 @@ image::test/images/pdf-outline.png[PDF bookmark outline panel,pdfwidth=100%]
35
37
 
36
38
  == Installation
37
39
 
38
- Add to the `Gemfile`:
40
+ === Ruby (PDF + HTML5)
41
+
42
+ [source,bash]
43
+ ----
44
+ gem install asciidoctor-lists-extended
45
+ ----
46
+
47
+ Add to a `Gemfile`:
39
48
 
40
49
  [source,ruby]
41
50
  ----
42
- gem 'asciidoctor-lists-extended', path: '/path/to/asciidoctor-lists-extended'
51
+ gem 'asciidoctor-lists-extended'
52
+ ----
53
+
54
+ Require on the command line:
55
+
56
+ [source,bash]
57
+ ----
58
+ asciidoctor-pdf -r asciidoctor-lists-extended document.adoc
59
+ asciidoctor -r asciidoctor-lists-extended document.adoc
43
60
  ----
44
61
 
45
- Or require directly:
62
+ === Node.js / npm (HTML5, Antora, VSCode)
46
63
 
47
64
  [source,bash]
48
65
  ----
49
- asciidoctor-pdf -r /path/to/lib/asciidoctor-lists-extended.rb document.adoc
66
+ npm install asciidoctor-lists-extended
67
+ ----
68
+
69
+ ==== Antora
70
+
71
+ Add to the Antora site's `package.json` dependencies, then reference in the playbook
72
+ under `asciidoc:` — *not* under `antora:` (those are pipeline hooks, not Asciidoctor.js extensions):
73
+
74
+ [source,yaml]
75
+ ----
76
+ asciidoc:
77
+ extensions:
78
+ - asciidoctor-lists-extended
50
79
  ----
51
80
 
52
- For HTML5 only (no `asciidoctor-pdf` needed):
81
+ The `list-of::` macro is then available in all AsciiDoc source files processed by that playbook.
82
+
83
+ ==== VSCode
84
+
85
+ Install globally on the machine hosting the workspace (local or Remote-SSH server):
53
86
 
54
87
  [source,bash]
55
88
  ----
56
- asciidoctor -r /path/to/lib/asciidoctor-lists-extended.rb document.adoc
89
+ npm install -g asciidoctor-lists-extended
90
+ ----
91
+
92
+ Add to `.vscode/settings.json`:
93
+
94
+ [source,json]
95
+ ----
96
+ {
97
+ "asciidoc.asciidoctorExtensions": ["asciidoctor-lists-extended"]
98
+ }
99
+ ----
100
+
101
+ For workspaces where a global install is not available, add a one-line shim at
102
+ `.asciidoctor/lib/lists-extended.js`:
103
+
104
+ [source,javascript]
105
+ ----
106
+ module.exports = require('asciidoctor-lists-extended')
57
107
  ----
58
108
 
109
+ The VSCode AsciiDoc extension auto-loads any `.js` file in `.asciidoctor/lib/`.
110
+
111
+ NOTE: For Remote-SSH, the npm package must be installed on the *remote* machine.
112
+ The VSCode AsciiDoc preview runs server-side.
113
+
59
114
  == Quick Start
60
115
 
61
116
  [source,asciidoc]
@@ -45,6 +45,11 @@ module Asciidoctor
45
45
  exclude_from_outline: attrs['exclude_from_outline'] || pos_flags.include?('exclude_from_outline'),
46
46
  strip_period: attrs['strip_period'] || pos_flags.include?('strip_period'),
47
47
  split_caption: attrs['split_caption'] || pos_flags.include?('split_caption'),
48
+ # site — force document-wide scope regardless of nesting depth.
49
+ # Needed in Antora assembled PDFs where pages are shifted one level deep
50
+ # (what was == Section in the source becomes === Subsection in the assembled
51
+ # document), causing scope_node_for to mis-classify the macro as chapter-scoped.
52
+ scope_global: attrs.key?('site') || pos_flags.include?('site'),
48
53
  caption_prefix: attrs['caption_prefix'],
49
54
  title: attrs['title'],
50
55
  entry_indent: attrs['entry_indent']&.to_f,
@@ -85,7 +90,16 @@ module Asciidoctor
85
90
  end
86
91
 
87
92
  # PDF backend: UUID placeholders are handled by PDFConverterWithLists.
88
- return if document.backend == 'pdf'
93
+ # allocate_toc/ink_toc only fire when the document has a toc attribute set.
94
+ # Warn here so the author sees a clear message instead of raw UUIDs in the PDF.
95
+ if document.backend == 'pdf'
96
+ unless document.attr?('toc')
97
+ logger.warn 'asciidoctor-lists-extended: list-of:: macros in PDF output require ' \
98
+ 'toc::[] in the document (or :toc: in the header); ' \
99
+ 'without it the list will render as a raw UUID placeholder.'
100
+ end
101
+ return
102
+ end
89
103
 
90
104
  # HTML5 and other backends: replace UUID placeholders with xref content.
91
105
  HtmlRenderer.new.render(document)
@@ -22,6 +22,7 @@ module Asciidoctor
22
22
  hide_empty_section = params[:hide_empty_section]
23
23
 
24
24
  scope = scope_node_for(block, document)
25
+ scope = document if params[:scope_global]
25
26
  elements = scope.find_by(
26
27
  traverse_documents: true,
27
28
  context: params[:element].to_sym
@@ -59,9 +59,13 @@ module Asciidoctor
59
59
  # allocate_toc hook
60
60
  # -----------------------------------------------------------------------
61
61
  # Called by asciidoctor-pdf early in document generation to reserve page
62
- # space for the ToC. We call super first (allocate the real ToC), then
63
- # iterate over all list-of:: macros and allocate space for each list.
62
+ # space for the ToC. We mark sections that contain empty list-of:: macros
63
+ # before calling super so that super's dry-run of ink_toc does not count
64
+ # those sections as ToC entries and over-allocate ToC pages. Those sections
65
+ # are removed entirely by collect_and_allocate_lists, so the marker never
66
+ # reaches the final document.
64
67
  def allocate_toc(doc, num_levels, toc_start_cursor, break_after_toc)
68
+ mark_empty_list_sections doc
65
69
  result = super
66
70
  collect_and_allocate_lists doc, num_levels, toc_start_cursor, break_after_toc
67
71
  result
@@ -151,11 +155,13 @@ module Asciidoctor
151
155
  # -----------------------------------------------------------------------
152
156
  # get_entries_for_toc override
153
157
  # -----------------------------------------------------------------------
154
- # Filters out virtual list sections marked with 'list-exclude-from-toc'
155
- # so they are hidden from the rendered Table of Contents while remaining
156
- # present in doc.sections (and therefore still visible in the PDF outline).
158
+ # Filters out:
159
+ # list-exclude-from-toc — virtual list sections the author opted out of the ToC
160
+ # list-toc-measure-skip — original sections for empty lists, temporarily marked
161
+ # by mark_empty_list_sections so allocate_toc's dry-run
162
+ # does not over-allocate ToC pages for them
157
163
  def get_entries_for_toc(node)
158
- super.reject { |s| s.attr? 'list-exclude-from-toc' }
164
+ super.reject { |s| (s.attr? 'list-exclude-from-toc') || (s.attr? 'list-toc-measure-skip') }
159
165
  end
160
166
 
161
167
  # -----------------------------------------------------------------------
@@ -270,6 +276,34 @@ module Asciidoctor
270
276
 
271
277
  private
272
278
 
279
+ # -----------------------------------------------------------------------
280
+ # mark_empty_list_sections
281
+ # -----------------------------------------------------------------------
282
+ # Scans the document for document-wide list-of:: macros whose element type
283
+ # has no captioned/titled entries. Marks the parent section of each such
284
+ # macro with the 'list-toc-measure-skip' attribute so that
285
+ # get_entries_for_toc excludes it during allocate_toc's dry-run measurement.
286
+ #
287
+ # collect_and_allocate_lists removes these sections entirely before the real
288
+ # ink_toc pass, so the attribute never persists into the final document.
289
+ def mark_empty_list_sections(doc)
290
+ doc.find_by do |b|
291
+ b.content_model == :simple &&
292
+ b.lines.size == 1 &&
293
+ ListMacroAttributes.key?(b.lines[0])
294
+ end.each do |block|
295
+ uuid = block.lines[0]
296
+ config = ListMacroAttributes[uuid]
297
+ scope_node = scope_node_for(block)
298
+ scope_node = doc if config[:scope_global]
299
+ next unless scope_node.equal?(doc)
300
+ next unless get_list_entries(scope_node, config[:element]).empty?
301
+
302
+ parent = block.parent
303
+ parent.set_attr 'list-toc-measure-skip', '' if parent.context == :section
304
+ end
305
+ end
306
+
273
307
  # -----------------------------------------------------------------------
274
308
  # collect_and_allocate_lists
275
309
  # -----------------------------------------------------------------------
@@ -288,6 +322,7 @@ module Asciidoctor
288
322
  uuid = block.lines[0]
289
323
  config = ListMacroAttributes[uuid]
290
324
  scope_node = scope_node_for(block)
325
+ scope_node = doc if config[:scope_global]
291
326
  entries = get_list_entries(scope_node, config[:element])
292
327
  parent = block.parent
293
328
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-lists-extended
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - 白一百 baiyibai