asciidoctor-dita-topic 1.3.4 → 1.4.0

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: 62056b90729ed2ccfcfad7a3fa3613938cf943c67b535d4f6653b1aa009a79a9
4
- data.tar.gz: 558a40909a4eea3b5a1bae2327e12c3116d679d5fbbd71cf4f70f990fd23fabf
3
+ metadata.gz: e2450b8d59daacc0f3b75a5d1d30e4527260f5c41696dd4eca6180b2dd922c8d
4
+ data.tar.gz: 3d1fbc5d40698c9fbfa3045e8319d2d8a774b97419287c5bfbd082f35f5dae51
5
5
  SHA512:
6
- metadata.gz: 84b3e6f51d7712fb8974fce8c4c3f184b90f1853cf442306ec24d8ab3a32e01f49ee9cec24885baeb26eafb6f7837a76117ffce14f4c7187436f153209864013
7
- data.tar.gz: 2c53bb543c270dcc48597b8cc9c16e914ec62393dec275064ae6e5423ed7b8c4898e3df59ffa83145779ef9f8124555b1f6cae5c2a51e6d539ac39356276ea6a
6
+ metadata.gz: 7eb3def3e75ac2d610667cacdf1f247aba118dea8f758895c5e2ef2ab5d1e0c0133a67506cc1b1b57bf72e8f5cdf212ef01a1e67787de07cf7a1f3682f8dd3d4
7
+ data.tar.gz: a44b76667c70adea284ad5ce7078c74a1271ddaa6ff6628cf75959e0e0957f1cff9dce07103d8026da2e06003495ba918116d23fb1a3edb50b78bdd050962c6a
data/README.adoc CHANGED
@@ -15,7 +15,7 @@ $ *vale _source_file.adoc_*
15
15
  +
16
16
  [literal,subs="+quotes"]
17
17
  ....
18
- $ *asciidoctor -r dita-topic -b dita-topic _source_file.adoc_*
18
+ $ *dita-topic _source_file.adoc_*
19
19
  ....
20
20
 
21
21
  . Convert the generic DITA topic to a specialized DITA concept, reference, or task:
@@ -50,27 +50,34 @@ On macOS, `asciidoctor` installed with Homebrew expects Ruby gems in a different
50
50
  [#use]
51
51
  == Usage
52
52
 
53
- To use the custom converter on the command line, load it with the `-r dita-topic` option and then select `dita-topic` as the backend output format with `-b dita-topic`:
53
+ To convert an AsciiDoc file to a generic DITA topic, run the supplied `dita-topic` command-line interface as follows:
54
54
 
55
55
  [literal,subs="+quotes"]
56
56
  ....
57
- $ *asciidoctor -r dita-topic -b dita-topic _your_file_.adoc*
57
+ $ *dita-topic _your_file_.adoc*
58
58
  ....
59
59
 
60
60
  This creates a new file, `_your_file_.dita`, in the same directory as `_your_file_.adoc`. You can also convert multiple files at the same time:
61
61
 
62
62
  [literal,subs="+quotes"]
63
63
  ....
64
- $ **asciidoctor -r dita-topic -b dita-topic *.adoc**
64
+ $ **dita-topic *.adoc**
65
+ ....
66
+
67
+ The command-line interface simplifies the code execution and provides a few options in addition to the conversion. However, if you prefer to use Asciidoctor directly, load the converter with the `-r dita-topic` option and then select `dita-topic` as the backend output format with `-b dita-topic`:
68
+
69
+ [literal,subs="+quotes"]
70
+ ....
71
+ $ *asciidoctor -r dita-topic -b dita-topic _your_file_.adoc*
65
72
  ....
66
73
 
67
74
  [IMPORTANT]
68
75
  ====
69
- `dita-topic` does not validate the converted content. If you have link:https://www.dita-ot.org/[DITA Open Toolkit] installed, you can check that the converted file can be built as follows:
76
+ `dita-topic` does not validate the converted content. If you have link:https://www.dita-ot.org/[DITA Open Toolkit] installed, you can verify that the converted file can be built as follows:
70
77
 
71
78
  [literal,subs="+quotes"]
72
79
  ....
73
- $ **dita -i _converted_file_.dita -f xhtml**
80
+ $ **dita -i _your_file_.dita -f xhtml**
74
81
  ....
75
82
 
76
83
  To produce slightly more readable errors, you can also use `xmlstarlet`:
@@ -82,45 +89,51 @@ $ **xmlstarlet val -e -s _path_to_dita-ot_directory_/plugins/org.oasis-open.dita
82
89
  ====
83
90
 
84
91
  [#attributes]
85
- === Supplying attribute definitions
92
+ === Supplying individual attribute definitions
86
93
 
87
94
  If your AsciiDoc files use attributes that are defined outside of these files, you can supply the attribute definitions on the command line with the `-a _attribute_=_value_` option:
88
95
 
89
96
  [literal,subs="+quotes"]
90
97
  ....
91
- $ **asciidoctor -r dita-topic -b dita-topic -a _attribute_=_value_ _your_file_.adoc**
98
+ $ **dita-topic -a _attribute_=_value_ _your_file_.adoc**
92
99
  ....
93
100
 
94
- You can provide multiple `-a _attribute_=_value_` options at the same time. Providing relevant attribute definitions is especially important if your document contains conditional content.
101
+ If you prefer to use Asciidoctor directly, supply the attribute definitions with the `-a _attribute_=_value_` option as follows:
95
102
 
96
- .Providing a product version to resolve `ifeval` conditions
97
- ====
98
- Your AsciiDoc files include a number of `ifeval` statements that provide different content for different versions of the product you are documenting:
103
+ [literal,subs="+quotes"]
104
+ ....
105
+ $ **asciidoctor -r dita-topic -b dita-topic -a _attribute_=_value_ _your_file_.adoc**
106
+ ....
99
107
 
100
- [source]
101
- ----
102
- \ifeval::["{ProductNumber}" == "1"]
103
- ...
104
- \endif::[]
105
- \ifeval::["{ProductNumber}" == "2"]
106
- ...
107
- \endif::[]
108
- ----
108
+ You can provide multiple `-a` options at the same time. Providing relevant attribute definitions is especially important if your document contains conditional content.
109
109
 
110
- To ensure that the converted DITA files include all content for version 2 of your product, run:
110
+ [#attribute_files]
111
+ === Supplying attribute definition files
112
+
113
+ If listing individual attribute definitions is impractical, you can use the `-p _definition_file_.adoc` option to supply another AsciiDoc file with attribute definitions in it:
111
114
 
112
115
  [literal,subs="+quotes"]
113
116
  ....
114
- $ **asciidoctor -r dita-topic -b dita-topic -a ProductNumber=2 *.adoc**
117
+ $ **dita-topic -p _definition_file_.adoc _your_file_.adoc**
115
118
  ....
116
- ====
119
+
120
+ The supplied file is automatically prepended to each AsciiDoc file during conversion. You can provide multiple `-p` options at the same time or use a combination `-p` and `-a` options to construct your attribute definitions. If you define the same attribute twice this way, the value defined by using the `-a` option takes precedence.
121
+
122
+ This functionality is not available in standard Asciidoctor.
117
123
 
118
124
  [#authors]
119
125
  === Enabling author lines
120
126
 
121
127
  AsciiDoc topics are expected to be included in other files and therefore should not contain link:https://docs.asciidoctor.org/asciidoc/latest/document/author-line/[author line] definitions. In most cases, lines that directly follow the topic title are intended as first paragraphs. For this reason, author lines are disabled by default. To avoid losing content during conversion, as a workaround, the `dita-topic` converter interprets the raw content of the author line as a paragraph and issues a warning.
122
128
 
123
- To enable processing of author lines as metadata, set the value of the `dita-topic-authors` to `on`:
129
+ To enable processing of author lines as metadata, run the `dita-topic` command with the `-l` option:
130
+
131
+ [literal,subs="+quotes"]
132
+ ....
133
+ $ **dita-topic -l _your_file_.adoc**
134
+ ....
135
+
136
+ If you prefer to use Asciidoctor directly, set the value of the `dita-topic-authors` to `on`:
124
137
 
125
138
  [literal,subs="+quotes"]
126
139
  ....
@@ -137,7 +150,14 @@ Unlike AsciiDoc, DITA does not support floating titles and only allows titles to
137
150
  <p outputclass="title"><b>Floating title</b></p>
138
151
  ----
139
152
 
140
- To disable this behavior, set the value of the `dita-topic-titles` to `off`:
153
+ To disable this behavior, run the `dita-topic` command with the `-T` option:
154
+
155
+ [literal,subs="+quotes"]
156
+ ....
157
+ $ **dita-topic -T _your_file_.adoc**
158
+ ....
159
+
160
+ If you prefer to use Asciidoctor directly, set the value of the `dita-topic-titles` to `off`:
141
161
 
142
162
  [literal,subs="+quotes"]
143
163
  ....
@@ -149,7 +169,14 @@ $ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-titles=off _your_file_
149
169
 
150
170
  Unlike AsciiDoc, DITA does not support callouts as a method to add annotations to specific lines in verbatim blocks. To avoid losing content during conversion, as a workaround, the `dita-topic` converter uses XML entities for circled numbers.
151
171
 
152
- To disable this behavior, set the value of the `dita-topic-callouts` to `off`:
172
+ To disable this behavior, run the `dita-topic` command with the `-C` option:
173
+
174
+ [literal,subs="+quotes"]
175
+ ....
176
+ $ **dita-topic -C _your_file_.adoc**
177
+ ....
178
+
179
+ If you prefer to use Asciidoctor directly, set the value of the `dita-topic-callouts` to `off`:
153
180
 
154
181
  [literal,subs="+quotes"]
155
182
  ....
@@ -159,13 +186,22 @@ $ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-callouts=off _your_fil
159
186
  [#includes]
160
187
  === Disabling include directives
161
188
 
162
- By default, Asciidoctor resolves all `include` directives before converting the file. To only convert the contents of the selected file, specify the `-S secure` option:
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
+
191
+ [literal,subs="+quotes"]
192
+ ....
193
+ $ **dita-topic -I _your_file_.adoc**
194
+ ....
195
+
196
+ If you prefer to use Asciidoctor directly, there is no direct equivalent to this functionality. As a workaround, you can specify the `-S secure` option:
163
197
 
164
198
  [literal,subs="+quotes"]
165
199
  ....
166
200
  $ **asciidoctor -r dita-topic -b dita-topic -S secure _your_file_.adoc**
167
201
  ....
168
202
 
203
+ This disables processing of the include directives, but leaves cross references to the included files in the converted output.
204
+
169
205
  [#abstracts]
170
206
  === Adding short descriptions
171
207
 
data/bin/dita-topic ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (C) 2025 Jaromir Hradilek
4
+
5
+ # MIT License
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining
8
+ # a copy of this software and associated documentation files (the "Soft-
9
+ # ware"), to deal in the Software without restriction, including without
10
+ # limitation the rights to use, copy, modify, merge, publish, distribute,
11
+ # sublicense, and/or sell copies of the Software, and to permit persons to
12
+ # whom the Software is furnished to do so, subject to the following condi-
13
+ # tions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be included
16
+ # in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABI-
20
+ # LITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21
+ # SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
22
+ # OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
+ # OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ require (cli = File.absolute_path '../lib/dita-topic/cli.rb', __dir__) ? cli : 'dita-topic/cli'
27
+
28
+ begin
29
+ name = File.basename($0)
30
+ converter = AsciidoctorDitaTopic::Cli.new name, ARGV
31
+ converter.run
32
+ rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument => error
33
+ abort "#{name}: #{error.message}"
34
+ end
@@ -0,0 +1,139 @@
1
+ # Copyright (C) 2025 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 'optparse'
25
+ require 'asciidoctor'
26
+ require_relative 'version'
27
+ require_relative '../dita-topic'
28
+
29
+ module AsciidoctorDitaTopic
30
+ class Cli
31
+ def initialize name, argv
32
+ @attr = ['experimental']
33
+ @opts = {:output => true, :includes => true, :standalone => true}
34
+ @prep = []
35
+ @name = name
36
+ @args = self.parse_args argv
37
+ end
38
+
39
+ def parse_args argv
40
+ parser = OptionParser.new do |opt|
41
+ opt.banner = "Usage: #{@name} [OPTION...] FILE...\n"
42
+ opt.banner += " #{@name} -h|-v\n\n"
43
+
44
+ opt.on('-o', '--out-file FILE', 'output file; by default, the output file name is based on the input file') do |output|
45
+ @opts[:output] = (output.strip == '-') ? $stdout : output
46
+ end
47
+
48
+ opt.on('-a', '--attribute ATTRIBUTE', 'document attribute to set in the form of name, name!, or name=value pair') do |value|
49
+ @attr.append value
50
+ end
51
+
52
+ opt.on('-p', '--prepend-file FILE', 'file to prepend to all input files') do |file|
53
+ raise OptionParser::InvalidArgument, "not a file: #{file}" unless File.exist? file and File.file? file
54
+ raise OptionParser::InvalidArgument, "file not readable: #{file}" unless File.readable? file
55
+
56
+ @prep.append file
57
+ end
58
+
59
+ opt.on('-I', '--no-includes', 'disable processing of include directives') do
60
+ @opts[:includes] = false
61
+ end
62
+
63
+ opt.on('-s', '--no-header-footer', 'disable enclosing the content in <topic> and generating <title>') do
64
+ @opts[:standalone] = false
65
+ end
66
+
67
+ opt.separator ''
68
+
69
+ opt.on('-l', '--author-line', 'enable processing of author lines as metadata') do
70
+ @attr.append 'dita-topic-authors=on'
71
+ end
72
+
73
+ opt.on('-t', '--section-type', 'add content type as outputclass to sections') do
74
+ @attr.append 'dita-topic-type=on'
75
+ end
76
+
77
+ opt.on('-C', '--no-callouts', 'disable processing of callouts') do
78
+ @attr.append 'dita-topic-callouts=off'
79
+ end
80
+
81
+ opt.on('-S', '--no-sidebars', 'disable processing of sidebars') do
82
+ @attr.append 'dita-topic-sidebars=off'
83
+ end
84
+
85
+ opt.on('-T', '--no-titles', 'disable processing of floating titles') do
86
+ @attr.append 'dita-topic-titles=off'
87
+ end
88
+
89
+ opt.separator ''
90
+
91
+ opt.on('-h', '--help', 'display this help and exit') do
92
+ puts opt
93
+ exit
94
+ end
95
+
96
+ opt.on('-v', '--version', 'display version information and exit') do
97
+ puts "#{@name} #{VERSION}"
98
+ exit
99
+ end
100
+ end
101
+
102
+ args = parser.parse argv
103
+
104
+ if args.length == 0 or args[0].strip == '-'
105
+ return [$stdin]
106
+ end
107
+
108
+ args.each do |file|
109
+ raise OptionParser::InvalidArgument, "not a file: #{file}" unless File.exist? file and File.file? file
110
+ raise OptionParser::InvalidArgument, "file not readable: #{file}" unless File.readable? file
111
+ end
112
+
113
+ return args
114
+ end
115
+
116
+ def run
117
+ prepended = ''
118
+
119
+ @prep.each do |file|
120
+ prepended << File.read(file)
121
+ prepended << "\n"
122
+ end
123
+
124
+ @args.each do |file|
125
+ if file == $stdin
126
+ input = $stdin.read
127
+ output = (@opts[:output] == true) ? $stdout : @opts[:output]
128
+ else
129
+ input = File.read(file)
130
+ output = (@opts[:output] == true) ? Pathname.new(file).sub_ext('.dita').to_s : @opts[:output]
131
+ end
132
+
133
+ input.gsub!(Asciidoctor::IncludeDirectiveRx, '//\&') unless @opts[:includes]
134
+
135
+ Asciidoctor.convert prepended + input, backend: 'dita-topic', standalone: @opts[:standalone], safe: :unsafe, attributes: @attr, to_file: output
136
+ end
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,28 @@
1
+ # Copyright (C) 2025 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
+ # frozen_string_literal: true
25
+
26
+ module AsciidoctorDitaTopic
27
+ VERSION = '1.4.0'
28
+ end
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.3.4
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaromir Hradilek
@@ -74,14 +74,18 @@ dependencies:
74
74
  description: An extension for AsciiDoctor that converts a single AsciiDoc file to
75
75
  a DITA topic.
76
76
  email: jhradilek@gmail.com
77
- executables: []
77
+ executables:
78
+ - dita-topic
78
79
  extensions: []
79
80
  extra_rdoc_files: []
80
81
  files:
81
82
  - AUTHORS
82
83
  - LICENSE
83
84
  - README.adoc
85
+ - bin/dita-topic
84
86
  - lib/dita-topic.rb
87
+ - lib/dita-topic/cli.rb
88
+ - lib/dita-topic/version.rb
85
89
  homepage: https://github.com/jhradilek/asciidoctor-dita-topic
86
90
  licenses:
87
91
  - MIT