asciidoctor-dita-topic 1.2.2 → 1.3.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/README.adoc +67 -18
- data/lib/dita-topic.rb +104 -66
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62fa0187c3b7c336aefe18fe37acf00f67c477ca621852712bffa72c4f376a5a
|
4
|
+
data.tar.gz: 4f758d9811bfd1417499cc2f32bc66f5a6a46c48917156ed3807d7351968bc31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aa4841c7b6302ce390c71c94de4e7f68ef8c69beca991f01a8d75c59e69b76026490f4892232dffeb6a630f88c99f151c453f954f68a8c22f7f7f75f024157b
|
7
|
+
data.tar.gz: 4d1c4bb35c464b7c00dcb6dfb9a6977b1265a65e027a99319cc021ae7277d67f3281d0e7f6f1d0abe5005419ccba7efc97d8681bc4fb36dd28e9da17cb98f8d2
|
data/README.adoc
CHANGED
@@ -2,27 +2,34 @@
|
|
2
2
|
|
3
3
|
`dita-topic` is a custom converter for Asciidoctor that converts a single AsciiDoc file to a corresponding DITA 1.3 topic.
|
4
4
|
|
5
|
-
In combination with link:https://github.com/jhradilek/asciidoctor-dita-vale[asciidoctor-dita-vale]
|
5
|
+
In combination with link:https://github.com/jhradilek/asciidoctor-dita-vale[asciidoctor-dita-vale], link:https://github.com/jhradilek/dita-custom-xslt#installation[dita-convert], and link:https://github.com/jhradilek/fix-dita-links[dita-cleanup], this project can be used to rapidly convert AsciiDoc content to DITA:
|
6
6
|
|
7
7
|
. Identify incompatible markup in the AsciiDoc source file:
|
8
8
|
+
|
9
9
|
[literal,subs="+quotes"]
|
10
10
|
....
|
11
|
-
$ *vale
|
11
|
+
$ *vale _source_file.adoc_*
|
12
12
|
....
|
13
13
|
|
14
14
|
. Convert the AsciiDoc file to a generic DITA topic:
|
15
15
|
+
|
16
16
|
[literal,subs="+quotes"]
|
17
17
|
....
|
18
|
-
$ *asciidoctor -r dita-topic -b dita-topic
|
18
|
+
$ *asciidoctor -r dita-topic -b dita-topic _source_file.adoc_*
|
19
19
|
....
|
20
20
|
|
21
21
|
. Convert the generic DITA topic to a specialized DITA concept, reference, or task:
|
22
22
|
+
|
23
23
|
[literal,subs="+quotes"]
|
24
24
|
....
|
25
|
-
$ *dita-convert -
|
25
|
+
$ *dita-convert -g _source_file.dita_ -o _output_file.dita_*
|
26
|
+
....
|
27
|
+
|
28
|
+
. _Optional:_ Clean up the resulting DITA file if necessary:
|
29
|
+
+
|
30
|
+
[literal,subs="+quotes"]
|
31
|
+
....
|
32
|
+
$ *dita-cleanup -iI -D ../images -X . _output_file.dita_*
|
26
33
|
....
|
27
34
|
|
28
35
|
[#install]
|
@@ -120,18 +127,6 @@ To enable processing of author lines as metadata, set the value of the `dita-top
|
|
120
127
|
$ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-authors=on _your_file_.adoc**
|
121
128
|
....
|
122
129
|
|
123
|
-
[#callouts]
|
124
|
-
=== Enabling callouts
|
125
|
-
|
126
|
-
Unlike AsciiDoc, DITA does not support callouts as a method to add annotations to specific lines in verbatim blocks. For this reason, the conversion of callouts is disabled by default.
|
127
|
-
|
128
|
-
If callouts are required, the `dita-topic` converter can use XML entities for circled numbers in place of callouts. To enable this behavior, set the value of the `dita-topic-callouts` to `on`:
|
129
|
-
|
130
|
-
[literal,subs="+quotes"]
|
131
|
-
....
|
132
|
-
$ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-callouts=on _your_file_.adoc**
|
133
|
-
....
|
134
|
-
|
135
130
|
[#titles]
|
136
131
|
=== Disabling floating titles
|
137
132
|
|
@@ -149,6 +144,18 @@ To disable this behavior, set the value of the `dita-topic-titles` to `off`:
|
|
149
144
|
$ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-titles=off _your_file_.adoc**
|
150
145
|
....
|
151
146
|
|
147
|
+
[#callouts]
|
148
|
+
=== Disabling callouts
|
149
|
+
|
150
|
+
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
|
+
|
152
|
+
To disable this behavior, set the value of the `dita-topic-callouts` to `off`:
|
153
|
+
|
154
|
+
[literal,subs="+quotes"]
|
155
|
+
....
|
156
|
+
$ **asciidoctor -r dita-topic -b dita-topic -a dita-topic-callouts=off _your_file_.adoc**
|
157
|
+
....
|
158
|
+
|
152
159
|
[#includes]
|
153
160
|
=== Disabling include directives
|
154
161
|
|
@@ -183,25 +190,31 @@ An introductory paragraph.
|
|
183
190
|
|
184
191
|
Unlike AsciiDoc, DITA provides a number of semantic elements for software components such as file names, commands, or command-line options. To replicate this behavior, the `dita-topic` converter recognizes the following link:https://docs.asciidoctor.org/asciidoc/latest/attributes/role/#assign-roles-to-formatted-inline-elements[roles] assigned to monospace (```) inline text:
|
185
192
|
|
186
|
-
[cols="1,1"]
|
193
|
+
[cols="1,1,2"]
|
187
194
|
|===
|
188
195
|
| AsciiDoc Role
|
189
196
|
| DITA Element
|
197
|
+
| Description
|
190
198
|
|
191
199
|
| command
|
192
200
|
| `<cmdname>`
|
201
|
+
| A command name.
|
193
202
|
|
194
203
|
| directory
|
195
204
|
| `<filepath>`
|
205
|
+
| A directory name.
|
196
206
|
|
197
207
|
| filename
|
198
208
|
| `<filepath>`
|
209
|
+
| A file name.
|
199
210
|
|
200
211
|
| option
|
201
212
|
| `<option>`
|
213
|
+
| An command-line option.
|
202
214
|
|
203
215
|
| variable
|
204
216
|
| `<varname>`
|
217
|
+
| A variable name.
|
205
218
|
|===
|
206
219
|
|
207
220
|
For example, to describe a file name, use the following AsciiDoc markup:
|
@@ -212,10 +225,46 @@ Read the [filename]`/etc/passwd` file to see the complete list of
|
|
212
225
|
available user accounts.
|
213
226
|
----
|
214
227
|
|
228
|
+
[#metadata]
|
229
|
+
=== Adding metadata
|
230
|
+
|
231
|
+
DITA provides four metadata attributes that can be used for conditional processing. To replicate this behavior, the `dita-topic` converter recognizes the following link:https://docs.asciidoctor.org/asciidoc/latest/attributes/role/#assign-roles-to-formatted-inline-elements[roles] assigned to inline and block elements:
|
232
|
+
|
233
|
+
[cols="1,1,2"]
|
234
|
+
|===
|
235
|
+
| AsciiDoc Role
|
236
|
+
| DITA Attribute
|
237
|
+
| Description
|
238
|
+
|
239
|
+
| `platform:__value__`
|
240
|
+
| `platform="_value_"`
|
241
|
+
| Operating system or hardware architecture.
|
242
|
+
|
243
|
+
| `product:__value__`
|
244
|
+
| `product="_value_"`
|
245
|
+
| Product name.
|
246
|
+
|
247
|
+
| `audience:__value__`
|
248
|
+
| `audience="_value_"`
|
249
|
+
| Target audience.
|
250
|
+
|
251
|
+
| `otherprops:__value__`
|
252
|
+
| `otherprops="_value_"`
|
253
|
+
| Additional properties.
|
254
|
+
|===
|
255
|
+
|
256
|
+
For example, to indicate that a particular paragraph is relevant for Linux and macOS and is intended for beginners, use the following AsciiDoc markup:
|
257
|
+
|
258
|
+
[source,asciidoc]
|
259
|
+
----
|
260
|
+
[role="platform:linux platform:mac audience:beginner"]
|
261
|
+
For more information, see the *bash*(1) manual page.
|
262
|
+
----
|
263
|
+
|
215
264
|
[#warnings]
|
216
265
|
== Warnings
|
217
266
|
|
218
|
-
Despite aspiring to avoid losing content during conversion and produce
|
267
|
+
Despite aspiring to avoid losing content during conversion and produce 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:
|
219
268
|
|
220
269
|
[literal,subs="+quotes"]
|
221
270
|
....
|
data/lib/dita-topic.rb
CHANGED
@@ -39,7 +39,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
39
39
|
@authors_allowed = false
|
40
40
|
|
41
41
|
# Enable callouts by default:
|
42
|
-
@callouts_allowed =
|
42
|
+
@callouts_allowed = true
|
43
43
|
|
44
44
|
# Enable floating and block titles by default:
|
45
45
|
@titles_allowed = true
|
@@ -56,7 +56,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
56
56
|
@authors_allowed = true if (node.attr 'dita-topic-authors') == 'on'
|
57
57
|
|
58
58
|
# Check if callouts are enabled:
|
59
|
-
@callouts_allowed =
|
59
|
+
@callouts_allowed = false if (node.attr 'dita-topic-callouts') == 'off'
|
60
60
|
|
61
61
|
# Check if floating and block titles are enabled:
|
62
62
|
@titles_allowed = false if (node.attr 'dita-topic-titles') == 'off'
|
@@ -130,9 +130,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
130
130
|
|
131
131
|
# Return the XML output:
|
132
132
|
<<~EOF.chomp
|
133
|
-
<note type="#{node.attr 'name'}">
|
134
|
-
#{node.content}
|
135
|
-
</note>
|
133
|
+
<note type="#{node.attr 'name'}"#{compose_metadata node.role}>#{node.content}</note>
|
136
134
|
EOF
|
137
135
|
end
|
138
136
|
|
@@ -140,12 +138,12 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
140
138
|
# Check if the audio macro has a title specified:
|
141
139
|
if node.title?
|
142
140
|
<<~EOF.chomp
|
143
|
-
<object data="#{node.media_uri(node.attr 'target')}">
|
141
|
+
<object data="#{node.media_uri(node.attr 'target')}"#{compose_metadata node.role}>
|
144
142
|
<desc>#{node.title}</desc>
|
145
143
|
</object>
|
146
144
|
EOF
|
147
145
|
else
|
148
|
-
%(<object data="#{node.media_uri(node.attr 'target')}" />)
|
146
|
+
%(<object data="#{node.media_uri(node.attr 'target')}"#{compose_metadata node.role} />)
|
149
147
|
end
|
150
148
|
end
|
151
149
|
|
@@ -160,7 +158,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
160
158
|
number = 0
|
161
159
|
|
162
160
|
# Open the definition list:
|
163
|
-
result = [
|
161
|
+
result = [%(<dl outputclass="callout-list"#{compose_metadata node.role}>)]
|
164
162
|
|
165
163
|
# Process individual list items:
|
166
164
|
node.items.each do |item|
|
@@ -200,7 +198,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
200
198
|
return compose_qanda_dlist node if node.style == 'qanda'
|
201
199
|
|
202
200
|
# Open the definition list:
|
203
|
-
result = [
|
201
|
+
result = [%(<dl#{compose_metadata node.role}>)]
|
204
202
|
|
205
203
|
# Process individual list items:
|
206
204
|
node.items.each do |terms, description|
|
@@ -230,10 +228,10 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
230
228
|
end
|
231
229
|
|
232
230
|
# Close the definition list:
|
233
|
-
result <<
|
231
|
+
result << %(</dl>)
|
234
232
|
|
235
233
|
# Return the XML output:
|
236
|
-
add_block_title (result.join LF), node
|
234
|
+
add_block_title (result.join LF), node
|
237
235
|
end
|
238
236
|
|
239
237
|
def convert_example node
|
@@ -244,7 +242,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
244
242
|
|
245
243
|
# Return the XML output:
|
246
244
|
<<~EOF.chomp
|
247
|
-
<example#{compose_id node.id}>
|
245
|
+
<example#{compose_id node.id}#{compose_metadata node.role}>
|
248
246
|
#{node.title ? %(<title>#{node.title}</title>\n) : ''}#{node.content}
|
249
247
|
</example>
|
250
248
|
EOF
|
@@ -262,7 +260,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
262
260
|
end
|
263
261
|
|
264
262
|
# Return the XML output:
|
265
|
-
%(<p outputclass="title sect#{node.level}"><b>#{node.title}</b></p>)
|
263
|
+
%(<p outputclass="title sect#{node.level}"#{compose_metadata node.role}><b>#{node.title}</b></p>)
|
266
264
|
end
|
267
265
|
|
268
266
|
def convert_image node
|
@@ -278,7 +276,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
278
276
|
# Check if the image has a title specified:
|
279
277
|
if node.title?
|
280
278
|
<<~EOF.chomp
|
281
|
-
<fig>
|
279
|
+
<fig#{compose_metadata node.role}>
|
282
280
|
<title>#{node.title}</title>
|
283
281
|
<image href="#{node.image_uri(node.attr 'target')}"#{width}#{height}#{scale} placement="break">
|
284
282
|
<alt>#{node.alt}</alt>
|
@@ -287,7 +285,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
287
285
|
EOF
|
288
286
|
else
|
289
287
|
<<~EOF.chomp
|
290
|
-
<image href="#{node.image_uri(node.attr 'target')}"#{width}#{height}#{scale} placement="break">
|
288
|
+
<image href="#{node.image_uri(node.attr 'target')}"#{width}#{height}#{scale} placement="break"#{compose_metadata node.role}>
|
291
289
|
<alt>#{node.alt}</alt>
|
292
290
|
</image>
|
293
291
|
EOF
|
@@ -299,7 +297,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
299
297
|
case node.type
|
300
298
|
when :link
|
301
299
|
# Compose an external link:
|
302
|
-
%(<xref href="#{node.target}" scope="external">#{node.text}</xref>)
|
300
|
+
%(<xref href="#{node.target}" scope="external"#{compose_metadata node.role}>#{node.text}</xref>)
|
303
301
|
when :xref
|
304
302
|
# NOTE: While AsciiDoc is happy to reference an ID that is not
|
305
303
|
# defined in the same AsciiDoc file, DITA requires the topic ID as
|
@@ -314,7 +312,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
314
312
|
logger.warn format_message "Possible invalid reference: #{node.target}" if node.target.include? '#'
|
315
313
|
|
316
314
|
# Compose a cross reference:
|
317
|
-
return %(<xref href="#{node.target}">#{node.text || path}</xref>)
|
315
|
+
return %(<xref href="#{node.target}"#{compose_metadata node.role}>#{node.text || path}</xref>)
|
318
316
|
end
|
319
317
|
|
320
318
|
# Determine whether the ID reference target is in this document:
|
@@ -322,18 +320,18 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
322
320
|
# Determine whether the ID reference target is the document id:
|
323
321
|
if target == node.document.id
|
324
322
|
# Compose the unchanged cross reference:
|
325
|
-
return node.text ? %(<xref href="##{target}">#{node.text}</xref>) : %(<xref href="##{target}" />)
|
323
|
+
return node.text ? %(<xref href="##{target}"#{compose_metadata node.role}>#{node.text}</xref>) : %(<xref href="##{target}" />)
|
326
324
|
end
|
327
325
|
|
328
326
|
# Compose the adjusted cross reference:
|
329
|
-
return node.text ? %(<xref href="#./#{target}">#{node.text}</xref>) : %(<xref href="#./#{target}" />)
|
327
|
+
return node.text ? %(<xref href="#./#{target}"#{compose_metadata node.role}>#{node.text}</xref>) : %(<xref href="#./#{target}" />)
|
330
328
|
end
|
331
329
|
|
332
330
|
# Issue a warning as the cross reference is unlikely to work:
|
333
331
|
logger.warn format_message "Possible invalid reference: #{node.target}"
|
334
332
|
|
335
333
|
# Compose the cross reference:
|
336
|
-
node.text ? %(<xref href="#{node.target}">#{node.text}</xref>) : %(<xref href="#{node.target}" />)
|
334
|
+
node.text ? %(<xref href="#{node.target}"#{compose_metadata node.role}>#{node.text}</xref>) : %(<xref href="#{node.target}" />)
|
337
335
|
when :ref
|
338
336
|
# NOTE: DITA does not have a dedicated element for inline anchors or
|
339
337
|
# a direct equivalent of the <span> element from HTML. The solution
|
@@ -405,7 +403,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
405
403
|
height = '' if height.include? '%'
|
406
404
|
|
407
405
|
# Return the XML output:
|
408
|
-
%(<image href="#{node.image_uri node.target}"#{width}#{height} placement="inline"><alt>#{node.alt}</alt></image>)
|
406
|
+
%(<image href="#{node.image_uri node.target}"#{width}#{height} placement="inline"#{compose_metadata node.role}><alt>#{node.alt}</alt></image>)
|
409
407
|
end
|
410
408
|
|
411
409
|
def convert_inline_indexterm node
|
@@ -455,11 +453,14 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
455
453
|
# Determine the inline markup type:
|
456
454
|
case node.type
|
457
455
|
when :emphasis
|
458
|
-
%(<i>#{node.text}</i>)
|
456
|
+
%(<i#{compose_metadata node.role}>#{node.text}</i>)
|
459
457
|
when :strong
|
460
|
-
%(<b>#{node.text}</b>)
|
458
|
+
%(<b#{compose_metadata node.role}>#{node.text}</b>)
|
461
459
|
when :monospaced
|
462
|
-
#
|
460
|
+
# Set the default element value:
|
461
|
+
element = 'codeph'
|
462
|
+
|
463
|
+
# Check if the role is provided:
|
463
464
|
if node.role
|
464
465
|
# Define supported roles:
|
465
466
|
semantic_markup = {
|
@@ -470,19 +471,19 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
470
471
|
'variable' => 'varname'
|
471
472
|
}
|
472
473
|
|
473
|
-
#
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
474
|
+
# Process each role:
|
475
|
+
node.role.split.each do |role|
|
476
|
+
# Select the appropriate semantic element:
|
477
|
+
element = semantic_markup[role] if semantic_markup.key? role
|
478
|
+
end
|
478
479
|
end
|
479
480
|
|
480
481
|
# Return the result:
|
481
|
-
%(<#{element}>#{node.text}</#{element}>)
|
482
|
+
%(<#{element}#{compose_metadata node.role}>#{node.text}</#{element}>)
|
482
483
|
when :superscript
|
483
|
-
%(<sup>#{node.text}</sup>)
|
484
|
+
%(<sup#{compose_metadata node.role}>#{node.text}</sup>)
|
484
485
|
when :subscript
|
485
|
-
%(<sub>#{node.text}</sub>)
|
486
|
+
%(<sub#{compose_metadata node.role}>#{node.text}</sub>)
|
486
487
|
when :double
|
487
488
|
%(“#{node.text}”)
|
488
489
|
when :single
|
@@ -500,7 +501,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
500
501
|
# Add comments around the STEM content:
|
501
502
|
%(<!-- latexmath start -->#{node.text}<!-- latexmath end -->)
|
502
503
|
else
|
503
|
-
node.text
|
504
|
+
%(<ph#{compose_metadata node.role}>#{node.text}</ph>)
|
504
505
|
end
|
505
506
|
end
|
506
507
|
|
@@ -510,40 +511,40 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
510
511
|
|
511
512
|
# Compose the XML output:
|
512
513
|
result = <<~EOF.chomp
|
513
|
-
<codeblock#{language}>
|
514
|
+
<codeblock#{language}#{compose_metadata node.role}>
|
514
515
|
#{node.content}
|
515
516
|
</codeblock>
|
516
517
|
EOF
|
517
518
|
|
518
519
|
# Return the XML output:
|
519
|
-
add_block_title result, node
|
520
|
+
add_block_title result, node
|
520
521
|
end
|
521
522
|
|
522
523
|
def convert_literal node
|
523
524
|
# Compose the XML output:
|
524
525
|
result = <<~EOF.chomp
|
525
|
-
<pre>
|
526
|
+
<pre#{compose_metadata node.role}>
|
526
527
|
#{node.content}
|
527
528
|
</pre>
|
528
529
|
EOF
|
529
530
|
|
530
531
|
# Return the XML output:
|
531
|
-
add_block_title result, node
|
532
|
+
add_block_title result, node
|
532
533
|
end
|
533
534
|
|
534
535
|
def convert_olist node
|
535
536
|
# Open the ordered list:
|
536
|
-
result = [
|
537
|
+
result = [%(<ol#{compose_metadata node.role}>)]
|
537
538
|
|
538
539
|
# Process individual list items:
|
539
540
|
node.items.each do |item|
|
540
541
|
# Check if the list item contains multiple block elements:
|
541
542
|
if item.blocks?
|
542
|
-
result << %(<li>#{item.text})
|
543
|
+
result << %(<li#{compose_metadata item.role}>#{item.text})
|
543
544
|
result << item.content
|
544
545
|
result << %(</li>)
|
545
546
|
else
|
546
|
-
result << %(<li>#{item.text}</li>)
|
547
|
+
result << %(<li#{compose_metadata item.role}>#{item.text}</li>)
|
547
548
|
end
|
548
549
|
end
|
549
550
|
|
@@ -551,7 +552,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
551
552
|
result << '</ol>'
|
552
553
|
|
553
554
|
# Return the XML output:
|
554
|
-
add_block_title (result.join LF), node
|
555
|
+
add_block_title (result.join LF), node
|
555
556
|
end
|
556
557
|
|
557
558
|
def convert_open node
|
@@ -565,12 +566,12 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
565
566
|
node.content
|
566
567
|
elsif node.content_model == :compound
|
567
568
|
<<~EOF.chomp
|
568
|
-
<div#{(node.style == 'abstract') ? ' outputclass="abstract"' : ''}>
|
569
|
+
<div#{(node.style == 'abstract') ? ' outputclass="abstract"' : ''}#{compose_metadata node.role}>
|
569
570
|
#{compose_floating_title node.title}#{node.content}
|
570
571
|
</div>
|
571
572
|
EOF
|
572
573
|
else
|
573
|
-
%(#{compose_floating_title node.title}<p#{(node.style == 'abstract') ? ' outputclass="abstract"' : ''}>#{node.content}</p>)
|
574
|
+
%(#{compose_floating_title node.title}<p#{(node.style == 'abstract') ? ' outputclass="abstract"' : ''}#{compose_metadata node.role}>#{node.content}</p>)
|
574
575
|
end
|
575
576
|
end
|
576
577
|
|
@@ -585,10 +586,10 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
585
586
|
end
|
586
587
|
|
587
588
|
def convert_paragraph node
|
588
|
-
if (node.attr 'role')
|
589
|
-
add_block_title %(<p outputclass="abstract">#{node.content}</p>), node
|
589
|
+
if (node.attr 'role') and (node.attr 'role').split.include? '_abstract'
|
590
|
+
add_block_title %(<p outputclass="abstract"#{compose_metadata node.role}>#{node.content}</p>), node
|
590
591
|
else
|
591
|
-
add_block_title %(<p>#{node.content}</p>), node
|
592
|
+
add_block_title %(<p#{compose_metadata node.role}>#{node.content}</p>), node
|
592
593
|
end
|
593
594
|
end
|
594
595
|
|
@@ -606,13 +607,13 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
606
607
|
# Check if the content contains multiple block elements:
|
607
608
|
if node.content_model == :compound
|
608
609
|
<<~EOF.chomp
|
609
|
-
<lq>
|
610
|
+
<lq#{compose_metadata node.role}>
|
610
611
|
#{compose_floating_title node.title}#{node.content}#{author}#{source}
|
611
612
|
</lq>
|
612
613
|
EOF
|
613
614
|
else
|
614
615
|
<<~EOF.chomp
|
615
|
-
<lq>
|
616
|
+
<lq#{compose_metadata node.role}>
|
616
617
|
#{compose_floating_title node.title}<p>#{node.content}</p>#{author}#{source}
|
617
618
|
</lq>
|
618
619
|
EOF
|
@@ -638,7 +639,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
638
639
|
|
639
640
|
# Return the XML output:
|
640
641
|
<<~EOF.chomp
|
641
|
-
<section#{compose_id node.id}#{outputclass}>
|
642
|
+
<section#{compose_id node.id}#{outputclass}#{compose_metadata node.role}>
|
642
643
|
<title>#{node.title}</title>
|
643
644
|
#{node.content}
|
644
645
|
</section>
|
@@ -658,13 +659,13 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
658
659
|
# Check if the content contains multiple block elements:
|
659
660
|
if node.content_model == :compound
|
660
661
|
<<~EOF.chomp
|
661
|
-
<div outputclass="sidebar">
|
662
|
+
<div outputclass="sidebar"#{compose_metadata node.role}>
|
662
663
|
#{compose_floating_title node.title}#{node.content}
|
663
664
|
</div>
|
664
665
|
EOF
|
665
666
|
else
|
666
667
|
<<~EOF.chomp
|
667
|
-
<div outputclass="sidebar">
|
668
|
+
<div outputclass="sidebar"#{compose_metadata node.role}>
|
668
669
|
#{compose_floating_title node.title}<p>#{node.content}</p>
|
669
670
|
</div>
|
670
671
|
EOF
|
@@ -679,7 +680,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
679
680
|
|
680
681
|
def convert_table node
|
681
682
|
# Open the table:
|
682
|
-
result = [
|
683
|
+
result = [%(<table#{compose_metadata node.role}>)]
|
683
684
|
|
684
685
|
# Check if the title is specified:
|
685
686
|
result << %(<title>#{node.title}</title>) if node.title?
|
@@ -769,7 +770,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
769
770
|
|
770
771
|
def convert_ulist node
|
771
772
|
# Open the unordered list:
|
772
|
-
result = [
|
773
|
+
result = [%(<ul#{compose_metadata node.role}>)]
|
773
774
|
|
774
775
|
# Process individual list items:
|
775
776
|
node.items.each do |item|
|
@@ -782,11 +783,11 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
782
783
|
|
783
784
|
# Check if the list item contains multiple block elements:
|
784
785
|
if item.blocks?
|
785
|
-
result << %(<li>#{check_box}#{item.text})
|
786
|
+
result << %(<li#{compose_metadata item.role}>#{check_box}#{item.text})
|
786
787
|
result << item.content
|
787
788
|
result << %(</li>)
|
788
789
|
else
|
789
|
-
result << %(<li>#{check_box}#{item.text}</li>)
|
790
|
+
result << %(<li#{compose_metadata item.role}>#{check_box}#{item.text}</li>)
|
790
791
|
end
|
791
792
|
end
|
792
793
|
|
@@ -794,7 +795,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
794
795
|
result << '</ul>'
|
795
796
|
|
796
797
|
# Returned the XML output:
|
797
|
-
add_block_title (result.join LF), node
|
798
|
+
add_block_title (result.join LF), node
|
798
799
|
end
|
799
800
|
|
800
801
|
def convert_verse node
|
@@ -806,7 +807,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
806
807
|
|
807
808
|
# Return the XML output:
|
808
809
|
<<~EOF.chomp
|
809
|
-
<lines>
|
810
|
+
<lines#{compose_metadata node.role}>
|
810
811
|
#{node.content}#{author}#{source}
|
811
812
|
</lines>
|
812
813
|
EOF
|
@@ -841,18 +842,18 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
841
842
|
# Check if the audio macro has a title specified:
|
842
843
|
if node.title?
|
843
844
|
<<~EOF.chomp
|
844
|
-
<object data="#{target_url}"#{width}#{height}>
|
845
|
+
<object data="#{target_url}"#{width}#{height}#{compose_metadata node.role}>
|
845
846
|
<desc>#{node.title}</desc>
|
846
847
|
</object>
|
847
848
|
EOF
|
848
849
|
else
|
849
|
-
%(<object data="#{target_url}"#{width}#{height} />)
|
850
|
+
%(<object data="#{target_url}"#{width}#{height}#{compose_metadata node.role} />)
|
850
851
|
end
|
851
852
|
end
|
852
853
|
|
853
854
|
def compose_qanda_dlist node
|
854
855
|
# Open the ordered list:
|
855
|
-
result = [
|
856
|
+
result = [%(<ol#{compose_metadata node.role}>)]
|
856
857
|
|
857
858
|
# Process individual list items:
|
858
859
|
node.items.each do |terms, description|
|
@@ -875,15 +876,15 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
875
876
|
end
|
876
877
|
|
877
878
|
# Close the ordered list:
|
878
|
-
result <<
|
879
|
+
result << %(</ol>)
|
879
880
|
|
880
881
|
# Return the XML output:
|
881
|
-
add_block_title (result.join LF), node
|
882
|
+
add_block_title (result.join LF), node
|
882
883
|
end
|
883
884
|
|
884
885
|
def compose_horizontal_dlist node
|
885
886
|
# Open the table:
|
886
|
-
result = [
|
887
|
+
result = [%(<table outputclass="horizontal-dlist"#{compose_metadata node.role}>)]
|
887
888
|
|
888
889
|
# Check if the title is specified:
|
889
890
|
result << %(<title>#{node.title}</title>) if node.title?
|
@@ -945,13 +946,13 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
945
946
|
|
946
947
|
# Helper methods
|
947
948
|
|
948
|
-
def add_block_title content,
|
949
|
+
def add_block_title content, node
|
949
950
|
# NOTE: Unlike AsciiDoc, DITA does not support titles assigned to
|
950
951
|
# certain block elements. As a workaround, I decided to use a paragraph
|
951
952
|
# with the outputclass attribute.
|
952
953
|
|
953
954
|
# Check if the title is defined:
|
954
|
-
return content unless title
|
955
|
+
return content unless node.title
|
955
956
|
|
956
957
|
# Issue a warning if block titles are disabled:
|
957
958
|
unless @titles_allowed
|
@@ -961,7 +962,7 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
961
962
|
|
962
963
|
# Return the XML output:
|
963
964
|
<<~EOF.chomp
|
964
|
-
<p outputclass="title"><b>#{title}</b></p>
|
965
|
+
<p outputclass="title"#{compose_metadata node.role}><b>#{node.title}</b></p>
|
965
966
|
#{content}
|
966
967
|
EOF
|
967
968
|
end
|
@@ -1023,6 +1024,43 @@ class DitaTopic < Asciidoctor::Converter::Base
|
|
1023
1024
|
return outputclass
|
1024
1025
|
end
|
1025
1026
|
|
1027
|
+
def compose_metadata roles
|
1028
|
+
# Check if the role is defined:
|
1029
|
+
return '' unless roles
|
1030
|
+
|
1031
|
+
# Set the initial value:
|
1032
|
+
result = {}
|
1033
|
+
|
1034
|
+
# Define supported metadata attributes:
|
1035
|
+
valid = ['platform', 'product', 'audience', 'otherprops']
|
1036
|
+
|
1037
|
+
# Process each role:
|
1038
|
+
roles.split.each do |role|
|
1039
|
+
# Ignore roles that do not follow the attribute:value format:
|
1040
|
+
next unless role.include? ':'
|
1041
|
+
|
1042
|
+
# Separate the attribute name from its value:
|
1043
|
+
attribute, value = role.split ':'
|
1044
|
+
|
1045
|
+
# Ignore unsupported attribute names:
|
1046
|
+
next unless valid.include? attribute
|
1047
|
+
|
1048
|
+
# Append the value to the attribute:
|
1049
|
+
if result.key? attribute
|
1050
|
+
result[attribute] << %( #{value})
|
1051
|
+
else
|
1052
|
+
result[attribute] = %(#{value})
|
1053
|
+
end
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
# Return the list of metadata attributes otherwise:
|
1057
|
+
if result.empty?
|
1058
|
+
return ''
|
1059
|
+
else
|
1060
|
+
return ' ' + result.map { |k, v| %(#{k}="#{v}") unless v.empty? }.join(' ')
|
1061
|
+
end
|
1062
|
+
end
|
1063
|
+
|
1026
1064
|
def format_message message
|
1027
1065
|
# Compose the warning or error message:
|
1028
1066
|
file_name = (defined? @file_name) ? %( #{@file_name}:) : ''
|