asciidoctor-dita-topic 1.0.8 → 1.1.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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +1 -0
  3. data/LICENSE +21 -0
  4. data/README.adoc +180 -0
  5. data/lib/dita-topic.rb +92 -21
  6. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 073b164893413640198b0938df78f0b180a4a25366a34bee47cf85585efddd51
4
- data.tar.gz: 75b381d82f68f838a237b666fe8a38929dbc99101f0024086888d83a4c59471a
3
+ metadata.gz: 134df897545adafba05f060ea22079c3fa927204b47fff2eec8ffbc8ae5ef84a
4
+ data.tar.gz: 354b8abadd320b9a4c63b3c170a85974a2231836da07851e1cde58da06aafff3
5
5
  SHA512:
6
- metadata.gz: f1b4cf1080f6ab776de1d62c122f89c190f68d03836bd3a41e2612c4b673ab97e2947abab161f9f4c1f976acddc9a41acf9ffcbdbfd7308a4c0e1bc64da87e17
7
- data.tar.gz: 9acb585946816133087779410d66279ec4567118a3ed14a9ec318c353a647e50dcb5ee46adf835bfa9a94a511b0a8ec772e49fe224bac042946021ad902c5902
6
+ metadata.gz: 4b7e9fcd688f450a2e05effca4c30d5969db15d7056cd23b6c1829d6f65de79cc95e0208f5dc543b5bd2f87117aa972f49dcff76963ef8b67879f5a40a97af6f
7
+ data.tar.gz: 05122aac651d614082cc4cb350197bdbb897d2b7436189eb225a230ffc3f8ad2f3ee5d66f1b882f78bab39d4fd38d18caaeba0d1b5dd965c98ccd7f52a530f97
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Jaromir Hradilek <jhradilek@gmail.com>
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (C) 2024, 2025 Jaromir Hradilek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the "Software"),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.
data/README.adoc ADDED
@@ -0,0 +1,180 @@
1
+ = dita-topic
2
+
3
+ `dita-topic` is a custom converter for Asciidoctor that converts a single AsciiDoc file to a corresponding DITA topic. To convert the produced DITA topic to a specialized DITA concept, reference, or task, use the link:https://github.com/jhradilek/dita-custom-xslt[dita_convert Python package].
4
+
5
+ [#install]
6
+ == Installation
7
+
8
+ Install the `asciidoctor-dita-topic` Ruby gem:
9
+
10
+ [literal,subs="+quotes"]
11
+ ....
12
+ $ *gem install asciidoctor-dita-topic*
13
+ ....
14
+
15
+ [#use]
16
+ == Usage
17
+
18
+ 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`:
19
+
20
+ [literal,subs="+quotes"]
21
+ ....
22
+ $ *asciidoctor -r dita-topic -b dita-topic _your_file_.adoc*
23
+ ....
24
+
25
+ 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:
26
+
27
+ [literal,subs="+quotes"]
28
+ ....
29
+ $ **asciidoctor -r dita-topic -b dita-topic *.adoc**
30
+ ....
31
+
32
+ [IMPORTANT]
33
+ ====
34
+ `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:
35
+
36
+ [literal,subs="+quotes"]
37
+ ....
38
+ $ **dita -i _converted_file_.dita -f xhtml**
39
+ ....
40
+
41
+ To produce slightly more readable errors, you can also use `xmlstarlet`:
42
+
43
+ [literal,subs="+quotes"]
44
+ ....
45
+ $ **xmlstarlet val -e -s _path_to_dita-ot_directory_/plugins/org.oasis-open.dita.v1_3/schema-url/technicalContent/xsd/topic.xsd _converted_file_.dita**
46
+ ....
47
+ ====
48
+
49
+ [#attributes]
50
+ === Supplying attribute definitions
51
+
52
+ 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:
53
+
54
+ [literal,subs="+quotes"]
55
+ ....
56
+ $ **asciidoctor -r dita-topic -b dita-topic -a _attribute_=_value_ _your_file_.adoc**
57
+ ....
58
+
59
+ 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.
60
+
61
+ .Providing a product version to resolve `ifeval` conditions
62
+ ====
63
+ Your AsciiDoc files include a number of `ifeval` statements that provide different content for different versions of the product you are documenting:
64
+
65
+ [source]
66
+ ----
67
+ \ifeval::["{ProductNumber}" == "1"]
68
+ ...
69
+ \endif::[]
70
+ \ifeval::["{ProductNumber}" == "2"]
71
+ ...
72
+ \endif::[]
73
+ ----
74
+
75
+ To ensure that the converted DITA files include all content for version 2 of your product, run:
76
+
77
+ [literal,subs="+quotes"]
78
+ ....
79
+ $ **asciidoctor -r dita-topic -b dita-topic -a ProductNumber=2 *.adoc**
80
+ ....
81
+ ====
82
+
83
+ [#authors]
84
+ === Enabling author lines
85
+
86
+ 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.
87
+
88
+ To enable processing of author lines as metadata, set the value of the `dita-topic-authors` to `on`:
89
+
90
+ [literal,subs="+quotes"]
91
+ ....
92
+ $ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-authors=on _your_file_.adoc**
93
+ ....
94
+
95
+ [#titles]
96
+ === Disabling floating titles
97
+
98
+ Unlike AsciiDoc, DITA does not support floating titles and only allows titles to be assigned to a limited number of elements. To avoid losing content during conversion, as a workaround, the `dita-topic` converter uses the following markup by default:
99
+
100
+ [source,xml]
101
+ ----
102
+ <p outputclass="title"><b>Floating title</b></p>
103
+ ----
104
+
105
+ To disable this behavior, set the value of the `dita-topic-titles` to `off`:
106
+
107
+ [literal,subs="+quotes"]
108
+ ....
109
+ $ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-titles=off _your_file_.adoc**
110
+ ....
111
+
112
+ [#callouts]
113
+ === Disabling callouts
114
+
115
+ 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.
116
+
117
+ To disable this behavior, set the value of the `dita-topic-callouts` to `off`:
118
+
119
+ [literal,subs="+quotes"]
120
+ ....
121
+ $ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-callouts=off _your_file_.adoc**
122
+ ....
123
+
124
+ [#includes]
125
+ === Disabling include directives
126
+
127
+ 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:
128
+
129
+ [literal,subs="+quotes"]
130
+ ....
131
+ $ **asciidoctor -r dita-topic -b dita-topic -S secure _your_file_.adoc**
132
+ ....
133
+
134
+ [#warnings]
135
+ == Warnings
136
+
137
+ Despite aspiring to avoid losing content during conversion and produce a valid DITA output, there are limitations to what is possible because of the differences between the two markup languages. When the `dita-topic` converter encounters a possible problem, it prints a warning to standard error output in the following format:
138
+
139
+ [literal,subs="+quotes"]
140
+ ....
141
+ asciidoctor: WARNING: dita-topic: _The warning message_
142
+ ....
143
+
144
+ This possible warning messages are as follows:
145
+
146
+ [horizontal]
147
+ Admonition titles not supported in DITA:: AsciiDoc allows you to add a custom title to any admonition by including `._Admonition title_` on the line above it. Unlike AsciiDoc, DITA does not allow titles for admonitions. `dita-topic` issues this warning whenever an admonition has a title defined in the converted AsciiDoc file.
148
+
149
+ Audio macro not supported:: AsciiDoc allows you to embed audio content in your documents by using the `audio::__audio_file__[]` macro. `dita-topic` does not implement this feature and issues this warning whenever the `audio` macro is present in the converted AsciiDoc file.
150
+
151
+ Author lines not enabled for topics:: AsciiDoc interprets the first line that directly follows the document title as an author line. Because topics are not expected to have author lines, `dita-topic` issues this warning when an author line is present in the converted AsciiDoc file.
152
+
153
+ Block titles not supported in DITA:: AsciiDoc allows you to include `._Block title_` on the line above most of the block elements to assign a custom title to them. Unlike AsciiDoc, DITA only allows titles to be assigned to a limited number of elements. `dita-topic` issues this warning when the `-a dita-topic-titles=off` option is specified and a block title is present in the converted AsciiDoc file.
154
+
155
+ Callouts not supported in DITA:: AsciiDoc allows you to use `<1>`, `<2>`, `<3>` and so on in verbatim blocks to add annotations to the specific lines. Unlike AsciiDoc, DITA does not provide a direct equivalent for this functionality. `dita-topic` issues this warning when the `-a dita-topic-callouts=off` option is specified and these annotations are present in the converted AsciiDoc file.
156
+
157
+ Floating titles not supported in DITA:: AsciiDoc allows you to use floating titles anywhere in the document. Unlike AsciiDoc, DITA does not support floating titles. `dita-topic` issues this warning when the `-a dita-topic-titles=off` option is specified and a floating title is present in the converted AsciiDoc file.
158
+
159
+ Inline breaks not supported in DITA:: AsciiDoc provides multiple ways to insert line breaks in paragraphs, such as inserting `{nbsp}+` at the end of the line or specifying `[%hardbreaks]` on the line preceding the paragraph. Unlike AsciiDoc, DITA does not provide direct equivalent for this functionality. `dita-topic` issues this warning whenever an inline line break is present in the converted AsciiDoc file and places the `<!-- break -\->` comment in the output file to mark its place.
160
+
161
+ Nesting of sections not supported in DITA:: AsciiDoc allows you to nest sections up to 5 levels deep. Unlike AsciiDoc, DITA does not allow the `<section>` elements to be nested. `dita-topic` issues a warning whenever nested sections are present in the converted AsciiDoc file.
162
+
163
+ Page breaks not supported in DITA:: AsciiDoc allows you to use `<<<` on a separate line to enforce a page break in output formats that support it. Unlike AsciiDoc, DITA does not support page breaks. `dita-topic` issues this warning whenever a page break is present in the converted AsciiDoc file and places the `<p outputclass="page-break"></p>` in the output file to mark its place.
164
+
165
+ Possible invalid reference: _reference_:: AsciiDoc allows you to cross reference by using an ID no matter if this ID is defined within or outside of the converted document. Unlike AsciiDoc, DITA requires both the target ID and the ID of the target topic to be included in the cross reference if the reference leads outside of the current file. As `dita-topic` is meant to be run on individual AsciiDoc files, it does not have access to information from referenced files during conversion. `dita-topic` issues this warning whenever a cross reference is present in the converted AsciiDoc file.
166
+
167
+ STEM support not implemented:: AsciiDoc provides multiple ways to insert Science, Technology, Engineering and Math (STEM) expressions in the document, including the `\stem:[_formula_]` inline macro and the `[stem]` delimited block. `dita-topic` does not implement this feature and issues this warning whenever such an expression is present in the converted AsciiDoc file.
168
+
169
+ Table footers not supported in DITA:: AsciiDoc allows you to set the `footer` option to mark the last table row as a table footer. Unlike AsciiDoc, DITA does not support table footers. `dita-topic` issues this warning whenever a table footer is present in the converted AsciiDoc file.
170
+
171
+ Thematic breaks not supported in DITA:: Asciidoc allows you to use `'''`, `---`, or `\***` (the last two with possible optional spaces in between the characters) to insert a thematic break in between two blocks, most commonly represented by a horizontal line. Unlike AsciiDoc, DITA does not support thematic breaks. `dita-topic` issues this warning whenever a thematic break is present in the converted AsciiDoc file.
172
+
173
+ Video macro not supported:: AsciiDoc allows you to embed video content in your documents by using the `video::__video_file__[]` macro. `dita-topic` does not implement this feature and issues this warning whenever the `video` macro is present in the converted AsciiDoc file.
174
+
175
+ [#copyright]
176
+ == Copyright
177
+
178
+ Copyright (C) 2024, 2025 Jaromir Hradilek
179
+
180
+ This program is free software, released under the terms of the link:LICENSE[MIT license]. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
data/lib/dita-topic.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # A custom AsciiDoc converter that generates individual DITA topics
2
- # Copyright (C) 2024 Jaromir Hradilek
2
+ # Copyright (C) 2024, 2025 Jaromir Hradilek
3
3
 
4
4
  # MIT License
5
5
  #
@@ -33,34 +33,70 @@ class DitaTopic < Asciidoctor::Converter::Base
33
33
  super
34
34
  outfilesuffix '.dita'
35
35
 
36
- # Enable floating and block titles by default:
37
- @titles_allowed = true
36
+ # Disable the author line by default:
37
+ @authors_allowed = false
38
38
 
39
39
  # Enable callouts by default:
40
40
  @callouts_allowed = true
41
+
42
+ # Enable floating and block titles by default:
43
+ @titles_allowed = true
41
44
  end
42
45
 
43
46
  def convert_document node
44
- # Check if floating and block titles are enabled:
45
- @titles_allowed = false if (node.attr 'dita-topic-titles') == 'off'
47
+ # Check if the author line is enabled:
48
+ @authors_allowed = true if (node.attr 'dita-topic-authors') == 'on'
46
49
 
47
50
  # Check if callouts are enabled:
48
51
  @callouts_allowed = false if (node.attr 'dita-topic-callouts') == 'off'
49
52
 
53
+ # Check if floating and block titles are enabled:
54
+ @titles_allowed = false if (node.attr 'dita-topic-titles') == 'off'
55
+
50
56
  # Check if the modular documentation content type is specified:
51
- outputclass = (node.attr? '_mod-docs-content-type') ? %( outputclass="#{(node.attr '_mod-docs-content-type').downcase}") : ''
57
+ outputclass = ''
58
+ outputclass = %( outputclass="#{(node.attr '_content-type').downcase}") if node.attr? '_content-type'
59
+ outputclass = %( outputclass="#{(node.attr '_mod-docs-content-type').downcase}") if node.attr? '_mod-docs-content-type'
60
+
61
+ # Open the document:
62
+ result = ["<?xml version='1.0' encoding='utf-8' ?>"]
63
+ result << %(<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">)
64
+ result << %(<topic#{compose_id (node.id or node.attributes['docname'])}#{outputclass}>)
65
+ result << %(<title>#{node.doctitle}</title>)
66
+
67
+ # Check if the author line is enabled and defined:
68
+ if @authors_allowed && !node.authors.empty?
69
+ # Open the prolog:
70
+ result << %(<prolog>)
71
+
72
+ # Process individual author names:
73
+ node.authors.each do |author|
74
+ result << %(<author>#{compose_author author, node}</author>)
75
+ end
76
+
77
+ # Close the prolog:
78
+ result << %(</prolog>)
79
+ end
80
+
81
+ # Open the document body:
82
+ result << %(<body>)
83
+
84
+ # Check if the author line defined while disabled:
85
+ if !@authors_allowed && !node.authors.empty?
86
+ # Issue a warning as inline content is not going to be processed:
87
+ logger.warn "#{NAME}: Author lines not enabled for topics"
88
+
89
+ # Process the author line as a plain paragraph:
90
+ result << %(<p>#{node.authors.map {|author| compose_author author, node}.join('; ')}</p>)
91
+ end
92
+
93
+ # Close the document body:
94
+ result << node.content
95
+ result << %(</body>)
96
+ result << %(</topic>)
52
97
 
53
98
  # Return the XML output:
54
- <<~EOF.chomp
55
- <?xml version='1.0' encoding='utf-8' ?>
56
- <!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
57
- <topic#{compose_id (node.id or node.attributes['docname'])}#{outputclass}>
58
- <title>#{node.doctitle}</title>
59
- <body>
60
- #{node.content}
61
- </body>
62
- </topic>
63
- EOF
99
+ result.join LF
64
100
  end
65
101
 
66
102
  def convert_admonition node
@@ -319,9 +355,23 @@ class DitaTopic < Asciidoctor::Converter::Base
319
355
  end
320
356
 
321
357
  def convert_inline_indexterm node
322
- # Issue a warning if an inline index term is present:
323
- logger.warn "#{NAME}: Inline index terms not implemented"
324
- return ''
358
+ # Check if the index term appears in the flow of the text:
359
+ if node.type == :visible
360
+ return %(<indexterm>#{node.text}</indexterm>#{node.text})
361
+ end
362
+
363
+ # Get primary, secondary, and tertiary index terms:
364
+ terms = node.attr 'terms'
365
+
366
+ # Determine the number of terms:
367
+ case terms.size
368
+ when 1
369
+ %(<indexterm>#{terms[0]}</indexterm>)
370
+ when 2
371
+ %(<indexterm>#{terms[0]}<indexterm>#{terms[1]}</indexterm></indexterm>)
372
+ else
373
+ %(<indexterm>#{terms[0]}<indexterm>#{terms[1]}<indexterm>#{terms[2]}</indexterm></indexterm></indexterm>)
374
+ end
325
375
  end
326
376
 
327
377
  def convert_inline_kbd node
@@ -420,9 +470,24 @@ class DitaTopic < Asciidoctor::Converter::Base
420
470
  add_block_title (result.join LF), node.title
421
471
  end
422
472
 
423
- # FIXME: This is not the top priority.
424
473
  def convert_open node
425
- ''
474
+ # NOTE: Although DITA provides an <abstract> element that is intended
475
+ # for this purpose, it is placed alongside the <body> element and not
476
+ # inside of ot. As there is no clean way to place it there, I use
477
+ # a workaround.
478
+
479
+ # Determine the node type:
480
+ if node.style == 'partintro'
481
+ node.content
482
+ elsif node.content_model == :compound
483
+ <<~EOF.chomp
484
+ <div#{(node.style == 'abstract') ? ' outputclass="abstract"' : ''}>
485
+ #{compose_floating_title node.title}#{node.content}
486
+ </div>
487
+ EOF
488
+ else
489
+ %(#{compose_floating_title node.title}<p#{(node.style == 'abstract') ? ' outputclass="abstract"' : ''}>#{node.content}</p>)
490
+ end
426
491
  end
427
492
 
428
493
  def convert_page_break node
@@ -773,6 +838,12 @@ class DitaTopic < Asciidoctor::Converter::Base
773
838
  EOF
774
839
  end
775
840
 
841
+ def compose_author author, node
842
+ name = node.sub_replacements author.name
843
+ mail = %( &lt;#{node.sub_replacements author.email}&gt;) if author.email
844
+ return %(#{name}#{mail})
845
+ end
846
+
776
847
  def compose_floating_title title
777
848
  # NOTE: Unlike AsciiDoc, DITA does not support floating titles or
778
849
  # titles assigned to certain block elements. As a workaround, I decided
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-dita-topic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaromir Hradilek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-13 00:00:00.000000000 Z
11
+ date: 2025-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -79,6 +79,9 @@ executables: []
79
79
  extensions: []
80
80
  extra_rdoc_files: []
81
81
  files:
82
+ - AUTHORS
83
+ - LICENSE
84
+ - README.adoc
82
85
  - lib/dita-topic.rb
83
86
  homepage: https://github.com/jhradilek/asciidoctor-dita-topic
84
87
  licenses:
@@ -102,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
105
  - !ruby/object:Gem::Version
103
106
  version: '0'
104
107
  requirements: []
105
- rubygems_version: 3.5.16
108
+ rubygems_version: 3.5.22
106
109
  signing_key:
107
110
  specification_version: 4
108
111
  summary: A custom AsciiDoc converter that generates individual DITA topics