asciidoctor-dita-topic 1.4.9 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54897b731c29e283e7a3f6813b8399e583435343d5c480cb2f802e392ad07dfc
4
- data.tar.gz: bb7ebe60820497be880333fa56b0e56b85c0713073314bef65f1fd33237fb0ad
3
+ metadata.gz: 9ac51fea23e9f82cc4dddc459c42eb9877f054b22d474d9d020cb0b7876cbfad
4
+ data.tar.gz: 50287798b45a0571cd0538639a0da114e101bfa2297c4a17e24451ceff634fa2
5
5
  SHA512:
6
- metadata.gz: 87eb3816ce0a31a524c758abefdc15bec4c364654928d974b79baf8cbb88d9ef4bfe2975fb77fec8e7f9564045269ba8d8482796c7507af2d9958544608e8256
7
- data.tar.gz: fbe4b750cba7a0745c45165b337b1ad466874371c3a13d211348e58b12430a035f88f188120c025bf5d4f4f1f10dc06fd037303c6728a44d20b70ef8a0891949
6
+ metadata.gz: 31c8095b9943ad5dde42deb002fff7d0be3975a5bd40a3657612309d38ae6ec39851c170edffd74e38da01d2eef11c8434637c48193cb96cb71e2a79e991f2bd
7
+ data.tar.gz: 8ad53b93870a78a6ec2b0896ce5c620b07a696eee55cc9bd366be8d2ce98962285f6d118533b8684c8254299ce9df3a2f3258657c6dabe5b58ab08f42e7d570a
data/README.adoc CHANGED
@@ -184,7 +184,7 @@ $ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-callouts=off _your_fil
184
184
  ....
185
185
 
186
186
  [#includes]
187
- === Disabling include directives
187
+ === Disabling all include directives
188
188
 
189
189
  By default, Asciidoctor resolves all `include` directives before converting the file. To only convert the contents of the selected file, run the `dita-topic` command with the `-I` option:
190
190
 
@@ -202,6 +202,32 @@ $ **asciidoctor -r dita-topic -b dita-topic -S secure _your_file_.adoc**
202
202
 
203
203
  This disables processing of the include directives, but leaves cross references to the included files in the converted output.
204
204
 
205
+ [#include_filter]
206
+ === Disabling inclusion of assemblies and modules
207
+
208
+ By default, Asciidoctor resolves all `include` directives before converting the file. To only include content from files explicitly marked as attributes or snippets, run the `dita-topic` command with the `-A` option:
209
+
210
+ [literal,subs="+quotes"]
211
+ ....
212
+ $ **dita-topic -A _your_file_.adoc**
213
+ ....
214
+
215
+ To mark a file as an attribute definition file, add the following line at the top of it:
216
+
217
+ [source,asciidoc]
218
+ ----
219
+ :_mod-docs-content-type: ATTRIBUTES
220
+ ----
221
+
222
+ To mark a file as a snippet file, add the following line at the top of it:
223
+
224
+ [source,asciidoc]
225
+ ----
226
+ :_mod-docs-content-type: SNIPPET
227
+ ----
228
+
229
+ Any other files are ignored. This functionality is not available in standard Asciidoctor.
230
+
205
231
  [#abstracts]
206
232
  === Adding short descriptions
207
233
 
@@ -286,19 +312,23 @@ DITA provides four metadata attributes that can be used for conditional processi
286
312
  | DITA Attribute
287
313
  | Description
288
314
 
289
- | `platform:__value__`
315
+ | `platform:__value__` +
316
+ `pl:__value__`
290
317
  | `platform="_value_"`
291
318
  | Operating system or hardware architecture.
292
319
 
293
- | `product:__value__`
320
+ | `product:__value__` +
321
+ `pr:__value__`
294
322
  | `product="_value_"`
295
323
  | Product name.
296
324
 
297
- | `audience:__value__`
325
+ | `audience:__value__` +
326
+ `au:__value__`
298
327
  | `audience="_value_"`
299
328
  | Target audience.
300
329
 
301
- | `otherprops:__value__`
330
+ | `otherprops:__value__` +
331
+ `op:__value__`
302
332
  | `otherprops="_value_"`
303
333
  | Additional properties.
304
334
  |===
@@ -307,7 +337,7 @@ For example, to indicate that a particular paragraph is relevant for Linux and m
307
337
 
308
338
  [source,asciidoc]
309
339
  ----
310
- [role="platform:linux platform:mac audience:beginner"]
340
+ [role="pl:linux pl:mac au:beginner"]
311
341
  For more information, see the *bash*(1) manual page.
312
342
  ----
313
343
 
@@ -25,6 +25,7 @@ require 'optparse'
25
25
  require 'pathname'
26
26
  require 'asciidoctor'
27
27
  require_relative 'version'
28
+ require_relative 'filter'
28
29
  require_relative '../dita-topic'
29
30
 
30
31
  module AsciidoctorDitaTopic
@@ -34,6 +35,7 @@ module AsciidoctorDitaTopic
34
35
  @opts = {
35
36
  :output => false,
36
37
  :standalone => true,
38
+ :modules => true,
37
39
  :no_includes => 0
38
40
  }
39
41
  @prep = []
@@ -71,6 +73,10 @@ module AsciidoctorDitaTopic
71
73
  @opts[:no_includes] += 1
72
74
  end
73
75
 
76
+ opt.on('-A', '--no-modules', 'disable processing of include directives with assemblies and modules') do
77
+ @opts[:modules] = false
78
+ end
79
+
74
80
  opt.separator ''
75
81
 
76
82
  opt.on('-l', '--author-line', 'enable processing of author lines as metadata') do
@@ -125,6 +131,11 @@ module AsciidoctorDitaTopic
125
131
  end
126
132
 
127
133
  def convert_topic input, base_dir
134
+ if not @opts[:modules]
135
+ Asciidoctor::Extensions.register do
136
+ include_processor FilterIncludeDirectives
137
+ end
138
+ end
128
139
  return Asciidoctor.convert input, backend: 'dita-topic', standalone: @opts[:standalone], safe: :unsafe, attributes: @attr, base_dir: base_dir
129
140
  end
130
141
 
@@ -0,0 +1,55 @@
1
+ # Copyright (C) 2026 Jaromir Hradilek
2
+
3
+ # MIT License
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the "Soft-
7
+ # ware"), to deal in the Software without restriction, including without
8
+ # limitation the rights to use, copy, modify, merge, publish, distribute,
9
+ # sublicense, and/or sell copies of the Software, and to permit persons to
10
+ # whom the Software is furnished to do so, subject to the following condi-
11
+ # tions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included
14
+ # in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABI-
18
+ # LITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
+ # SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
20
+ # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ # OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'asciidoctor'
25
+ require 'pathname'
26
+
27
+ class FilterIncludeDirectives < Asciidoctor::Extensions::IncludeProcessor
28
+ def handles? target
29
+ target.end_with? '.adoc', '.asciidoc', '.asc', '.ad'
30
+ end
31
+
32
+ def process doc, reader, target, attributes
33
+ file_path = Pathname.new(doc.base_dir) + target
34
+
35
+ begin
36
+ logger = Asciidoctor::LoggerManager.logger
37
+ include_doc = Asciidoctor.load_file file_path, safe: :secure, logger: false
38
+ ensure
39
+ Asciidoctor::LoggerManager.logger = logger
40
+ end
41
+
42
+ return reader unless supported_type? include_doc.attributes
43
+
44
+ reader.push_include File.read(file_path), target, target, 1, attributes
45
+ return reader
46
+ end
47
+
48
+ def supported_type? attributes
49
+ type = attributes['_mod-docs-content-type'] ? attributes['_mod-docs-content-type'].downcase : nil
50
+ type = attributes['_content-type'] ? attributes['_content-type'].downcase : nil unless type
51
+ type = attributes['_module-type'] ? attributes['_module-type'].downcase : nil unless type
52
+
53
+ ['attributes', 'snippet'].include? type
54
+ end
55
+ end
@@ -24,5 +24,5 @@
24
24
  # frozen_string_literal: true
25
25
 
26
26
  module AsciidoctorDitaTopic
27
- VERSION = '1.4.9'
27
+ VERSION = '1.5.1'
28
28
  end
data/lib/dita-topic.rb CHANGED
@@ -1050,7 +1050,12 @@ class DitaTopic < Asciidoctor::Converter::Base
1050
1050
  result = {}
1051
1051
 
1052
1052
  # Define supported metadata attributes:
1053
- valid = ['platform', 'product', 'audience', 'otherprops']
1053
+ valid = {
1054
+ 'pl' => 'platform',
1055
+ 'pr' => 'product',
1056
+ 'au' => 'audience',
1057
+ 'op' => 'otherprops'
1058
+ }
1054
1059
 
1055
1060
  # Process each role:
1056
1061
  roles.split.each do |role|
@@ -1060,8 +1065,11 @@ class DitaTopic < Asciidoctor::Converter::Base
1060
1065
  # Separate the attribute name from its value:
1061
1066
  attribute, value = role.split ':'
1062
1067
 
1068
+ # Expand the short attribute variant:
1069
+ attribute = valid[attribute] if valid.key? attribute
1070
+
1063
1071
  # Ignore unsupported attribute names:
1064
- next unless valid.include? attribute
1072
+ next unless valid.value? attribute
1065
1073
 
1066
1074
  # Append the value to the attribute:
1067
1075
  if result.key? attribute
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-dita-topic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.9
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaromir Hradilek
@@ -117,6 +117,7 @@ files:
117
117
  - bin/dita-topic
118
118
  - lib/dita-topic.rb
119
119
  - lib/dita-topic/cli.rb
120
+ - lib/dita-topic/filter.rb
120
121
  - lib/dita-topic/version.rb
121
122
  homepage: https://github.com/jhradilek/asciidoctor-dita-topic
122
123
  licenses:
@@ -139,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  - !ruby/object:Gem::Version
140
141
  version: '0'
141
142
  requirements: []
142
- rubygems_version: 3.6.9
143
+ rubygems_version: 4.0.10
143
144
  specification_version: 4
144
145
  summary: A custom AsciiDoc converter that generates individual DITA topics
145
146
  test_files: []