asciidoctor-reducer 1.1.0 → 1.1.1
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 +4 -4
- data/CHANGELOG.adoc +10 -0
- data/README.adoc +48 -5
- data/lib/asciidoctor/reducer/tree_processor.rb +31 -1
- data/lib/asciidoctor/reducer/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a1fcd2f167e66e18a7876694575d92c1d4cda20b0f1191d6f029d32c888c03d
|
4
|
+
data.tar.gz: 9dd7507a5fe67295f51590f890196cc3b98cb32dbf5cdb61e1d15396caf34143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efd6d82a88c4d6b1fdb4abd2f5b72b3a03df186a3cac990736ad5e199d9eb4a2e42360caff8cd40c3d71c5ad24bf2b44ae4a64187e38e837298380656fb8128b
|
7
|
+
data.tar.gz: 7a365765f4685d936f2f7b06aaf015261a25a7910a5a6f3773cb01a6c2a90210a79586aa39546578dfd4971cd66b27c01e7016af6aa7cd264e88282069cc5421
|
data/CHANGELOG.adoc
CHANGED
@@ -4,6 +4,16 @@
|
|
4
4
|
This document provides a curated view of the changes to Asciidoctor Reducer in each release.
|
5
5
|
For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.
|
6
6
|
|
7
|
+
== 1.1.1 (2025-03-27) - @mojavelinux
|
8
|
+
|
9
|
+
=== Fixed
|
10
|
+
|
11
|
+
* Fall back to iteration-based strategy in compiled JavaScript if built-in Array#flatten method throws RangeError (#63)
|
12
|
+
|
13
|
+
=== Details
|
14
|
+
|
15
|
+
{url-repo}/releases/tag/v1.1.1[git tag] | {url-repo}/compare/v1.1.0\...v1.1.1[full diff]
|
16
|
+
|
7
17
|
== 1.1.0 (2024-11-24) - @mojavelinux
|
8
18
|
|
9
19
|
=== Added
|
data/README.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= {project-name}
|
2
2
|
Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
|
3
|
-
v1.1.
|
3
|
+
v1.1.1, 2025-03-27
|
4
4
|
:idprefix:
|
5
5
|
:idseparator: -
|
6
6
|
ifndef::env-github[:icons: font]
|
@@ -115,21 +115,30 @@ require 'asciidoctor/reducer/api'
|
|
115
115
|
----
|
116
116
|
|
117
117
|
Next, reduce a parent document that contains includes.
|
118
|
-
(This works without having to specify the safe mode since the default safe mode when using this API is `:safe`).
|
119
118
|
|
120
119
|
[,ruby]
|
121
120
|
----
|
122
121
|
doc = Asciidoctor::Reducer.reduce_file 'sample.adoc'
|
123
122
|
----
|
124
123
|
|
125
|
-
|
124
|
+
NOTE: The previous call works without having to specify the safe mode since the default safe mode when using this API is `:safe`.
|
125
|
+
However, if any include target points to a file in an ancestor directory of `docdir`, you'll need to set the safe mode to `:unsafe` by passing the option `safe: :unsafe`.
|
126
|
+
The options that the `reduce_file` method accepts are a superset of the Asciidoctor API options.
|
127
|
+
|
128
|
+
The benefit of this return value is that you can access the reduced source as well as the parsed document that corresponds to it.
|
129
|
+
Use the following call to retrieve the reduced source from the returned document.
|
126
130
|
|
127
131
|
[,ruby]
|
128
132
|
----
|
129
133
|
puts doc.source
|
130
134
|
----
|
131
135
|
|
132
|
-
|
136
|
+
If you want to retrieve the source split into an array of lines, use the following call instead.
|
137
|
+
|
138
|
+
[,ruby]
|
139
|
+
----
|
140
|
+
puts doc.source_lines
|
141
|
+
----
|
133
142
|
|
134
143
|
If you only want AsciiDoctor Reducer to process include directives, leaving preprocessor conditional directives untouched, set the `:preserve_conditionals` option:
|
135
144
|
|
@@ -152,7 +161,37 @@ You can write the reduced source directly to a file by passing a file path to th
|
|
152
161
|
Asciidoctor::Reducer.reduce_file 'sample.adoc', to: 'sample-reduced.adoc'
|
153
162
|
----
|
154
163
|
|
155
|
-
|
164
|
+
=== In Preprocessor
|
165
|
+
|
166
|
+
It's generally not safe to read the lines from the reader in an Asciidoctor preprocessor extension because it introduces side effects.
|
167
|
+
However, Asciidoctor Reducer offers a workaround for that problem.
|
168
|
+
You can use Asciidoctor Reducer to safely retrieve the source lines of the document (with or without resolving preprocessor directives) in order to analyze them or even modify and replace the lines on the reader.
|
169
|
+
|
170
|
+
Let's look at how we can retrieve the source lines in an Asciidoctor preprocessor.
|
171
|
+
What you do with those lines is then up to you.
|
172
|
+
|
173
|
+
[,ruby]
|
174
|
+
----
|
175
|
+
require 'asciidoctor/reducer/api'
|
176
|
+
|
177
|
+
Asciidoctor::Extensions.register do
|
178
|
+
preprocessor do
|
179
|
+
process do |doc, reader|
|
180
|
+
unless doc.options[:extension_registry]&.groups&.include? :reducer
|
181
|
+
reducer_opts = { safe: doc.options[:safe], attributes: doc.options[:attributes].dup }
|
182
|
+
reduced_doc = Asciidoctor::Reducer.reduce_file reader.file, reducer_opts
|
183
|
+
reduced_source_lines = reduced_doc.source_lines
|
184
|
+
...
|
185
|
+
end
|
186
|
+
reader
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
----
|
191
|
+
|
192
|
+
Since the extension is registered globally, it's necessary to short-circuit it when called by reducer.
|
193
|
+
|
194
|
+
=== Extension
|
156
195
|
|
157
196
|
Instead of using the API for this library, you can use the load API provided by Asciidoctor.
|
158
197
|
If you want to register the extension globally, require the library as follows:
|
@@ -407,6 +446,10 @@ When running the `asciidoctor-reducer` command from source, you must prefix the
|
|
407
446
|
|
408
447
|
To avoid having to do this, or to make the `asciidoctor-reducer` command available from anywhere, you need to build the development gem and install it.
|
409
448
|
|
449
|
+
== Authors
|
450
|
+
|
451
|
+
Asciidoctor Reducer was written by Dan Allen of OpenDevise Inc. and contributed to the Asciidoctor project.
|
452
|
+
|
410
453
|
== Copyright and License
|
411
454
|
|
412
455
|
Copyright (C) 2021-present Dan Allen.
|
@@ -23,7 +23,11 @@ module Asciidoctor::Reducer
|
|
23
23
|
end
|
24
24
|
target_lines[idx] = lines if target_lines
|
25
25
|
end
|
26
|
-
|
26
|
+
if RUBY_ENGINE == 'opal'
|
27
|
+
reduced_source_lines = flatten inc_replacements[0][:lines]
|
28
|
+
else
|
29
|
+
reduced_source_lines = inc_replacements[0][:lines].flatten
|
30
|
+
end
|
27
31
|
if doc.sourcemap
|
28
32
|
logger = doc.logger
|
29
33
|
opts = doc.options.merge logger: nil, parse: false, reduced: true
|
@@ -42,5 +46,31 @@ module Asciidoctor::Reducer
|
|
42
46
|
end
|
43
47
|
doc
|
44
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def flatten input_list
|
53
|
+
input_list.flatten
|
54
|
+
rescue ::Exception => e # rubocop:disable Lint/RescueException,Lint/UselessAssignment
|
55
|
+
raise unless %x(e.name) == 'RangeError'
|
56
|
+
result = []
|
57
|
+
stack = [[0, input_list, input_list.length]]
|
58
|
+
until stack.empty?
|
59
|
+
idx, list, len = stack.pop
|
60
|
+
while idx < len
|
61
|
+
if Array === (item = list[idx])
|
62
|
+
if (next_idx = idx + 1) < len
|
63
|
+
stack << [next_idx, list, len]
|
64
|
+
end
|
65
|
+
idx = 0
|
66
|
+
len = (list = item).length
|
67
|
+
else
|
68
|
+
result << item
|
69
|
+
idx += 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
result
|
74
|
+
end
|
45
75
|
end
|
46
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-reducer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Allen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -87,7 +87,7 @@ metadata:
|
|
87
87
|
changelog_uri: https://github.com/asciidoctor/asciidoctor-reducer/blob/main/CHANGELOG.adoc
|
88
88
|
mailing_list_uri: https://chat.asciidoctor.org
|
89
89
|
source_code_uri: https://github.com/asciidoctor/asciidoctor-reducer
|
90
|
-
post_install_message:
|
90
|
+
post_install_message:
|
91
91
|
rdoc_options: []
|
92
92
|
require_paths:
|
93
93
|
- lib
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubygems_version: 3.5.22
|
106
|
-
signing_key:
|
106
|
+
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Reduces an AsciiDoc document containing includes and conditionals to a single
|
109
109
|
AsciiDoc document.
|