asciidoctor-dita-topic 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dita-topic.rb +89 -43
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52c01d2fe1eed871381b9c7ccac78c70de1b2d3078fee28eab23a4b7ff0a261b
|
4
|
+
data.tar.gz: 39a4e1da5ba838141a929c610060a9a2e8189c292d714028af19dad236cc78bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87721774c580b3a509ed62189fc31fcca4077bd0007a98234610f497430d3b8c6cf8adc0e71a7d752e672255e043bb2f6f335a28231fe12983772b3c1902dc58
|
7
|
+
data.tar.gz: 7a934f1f00886a4e7e8f512a1cd923b0ade242c8782810e564737075d3d3e5dea80a61c92f215162051c0de2471c9242acf5761555275c6d5f829aca9f5cb28c
|
data/lib/dita-topic.rb
CHANGED
@@ -25,29 +25,44 @@
|
|
25
25
|
# frozen_string_literal: true
|
26
26
|
|
27
27
|
module Asciidoctor
|
28
|
-
class
|
28
|
+
class DitaTopic < Asciidoctor::Converter::Base
|
29
29
|
NAME = 'dita-topic'
|
30
30
|
register_for NAME
|
31
31
|
|
32
32
|
def initialize *args
|
33
33
|
super
|
34
34
|
outfilesuffix '.dita'
|
35
|
+
|
36
|
+
# Enable floating and block titles by default:
|
37
|
+
@titles_allowed = true
|
35
38
|
end
|
36
39
|
|
37
40
|
def convert_document node
|
41
|
+
# Check if floating and block titles are enabled:
|
42
|
+
@titles_allowed = false if (node.attr 'dita-topic-titles') == 'strict'
|
43
|
+
|
44
|
+
# Check if a specific topic type is provided:
|
45
|
+
if (value = node.attr 'dita-topic-type') =~ /^(concept|reference|task)$/
|
46
|
+
type = value
|
47
|
+
body = (type == 'task') ? 'taskbody' : %(#{type[0,3]}body)
|
48
|
+
else
|
49
|
+
type = 'topic'
|
50
|
+
body = 'body'
|
51
|
+
end
|
52
|
+
|
38
53
|
# Check if the modular documentation content type is specified:
|
39
|
-
|
54
|
+
outputclass = (node.attr? '_mod-docs-content-type') ? %( outputclass="#{(node.attr '_mod-docs-content-type').downcase}") : ''
|
40
55
|
|
41
56
|
# Return the XML output:
|
42
57
|
<<~EOF.chomp
|
43
58
|
<?xml version='1.0' encoding='utf-8' ?>
|
44
|
-
<!DOCTYPE
|
45
|
-
|
59
|
+
<!DOCTYPE #{type} PUBLIC "-//OASIS//DTD DITA #{type.capitalize}//EN" "#{type}.dtd">
|
60
|
+
<#{type}#{compose_id (node.id or node.attributes['docname'])}#{outputclass}>
|
46
61
|
<title>#{node.doctitle}</title>
|
47
|
-
|
62
|
+
<#{body}>
|
48
63
|
#{node.content}
|
49
|
-
|
50
|
-
|
64
|
+
</#{body}>
|
65
|
+
</#{type}>
|
51
66
|
EOF
|
52
67
|
end
|
53
68
|
|
@@ -58,7 +73,7 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
58
73
|
|
59
74
|
# Issue a warning if the admonition has a title:
|
60
75
|
if node.title?
|
61
|
-
logger.warn "#{NAME}: Admonition
|
76
|
+
logger.warn "#{NAME}: Admonition titles not supported in DITA"
|
62
77
|
end
|
63
78
|
|
64
79
|
# Return the XML output:
|
@@ -83,7 +98,6 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
83
98
|
return ''
|
84
99
|
end
|
85
100
|
|
86
|
-
# FIXME: Add support for a title.
|
87
101
|
def convert_dlist node
|
88
102
|
# Check if a different list style is set:
|
89
103
|
return compose_horizontal_dlist node if node.style == 'horizontal'
|
@@ -123,19 +137,30 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
123
137
|
result << '</dl>'
|
124
138
|
|
125
139
|
# Return the XML output:
|
126
|
-
result.join LF
|
140
|
+
add_block_title (result.join LF), node.title, 'dlist'
|
127
141
|
end
|
128
142
|
|
129
143
|
def convert_example node
|
130
144
|
<<~EOF.chomp
|
131
145
|
<example#{compose_id node.id}>
|
132
|
-
#{
|
146
|
+
#{node.title ? %(<title>#{node.title}</title>\n) : ''}#{node.content}
|
133
147
|
</example>
|
134
148
|
EOF
|
135
149
|
end
|
136
150
|
|
137
151
|
def convert_floating_title node
|
138
|
-
|
152
|
+
# NOTE: Unlike AsciiDoc, DITA does not have a dedicated element for
|
153
|
+
# floating titles. As a workaround, I decided to use a paragraph with
|
154
|
+
# the outputclass attribute.
|
155
|
+
|
156
|
+
# Issue a warning if floating titles are disabled:
|
157
|
+
unless @titles_allowed
|
158
|
+
logger.warn "#{NAME}: Floating titles not supported in DITA"
|
159
|
+
return ''
|
160
|
+
end
|
161
|
+
|
162
|
+
# Return the XML output:
|
163
|
+
%(<p outputclass="title sect#{node.level}"><b>#{node.title}</b></p>)
|
139
164
|
end
|
140
165
|
|
141
166
|
# FIXME: Add support for additional attributes.
|
@@ -246,8 +271,6 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
246
271
|
return ''
|
247
272
|
end
|
248
273
|
|
249
|
-
# FIXME: Investigate if there is an equivalent of <span> in DITA that
|
250
|
-
# would group individual <uicontrol> elements together.
|
251
274
|
def convert_inline_kbd node
|
252
275
|
# Check if there is more than one key:
|
253
276
|
if (keys = node.attr 'keys').size == 1
|
@@ -299,31 +322,37 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
299
322
|
# Check whether the source language is defined:
|
300
323
|
language = (node.attributes.key? 'language') ? %( outputclass="language-#{node.attributes['language']}") : ''
|
301
324
|
|
302
|
-
#
|
303
|
-
<<~EOF.chomp
|
325
|
+
# Compose the XML output:
|
326
|
+
result = <<~EOF.chomp
|
304
327
|
<codeblock#{language}>
|
305
328
|
#{node.content}
|
306
329
|
</codeblock>
|
307
330
|
EOF
|
308
331
|
else
|
309
|
-
#
|
310
|
-
<<~EOF.chomp
|
332
|
+
# Compose the XML output:
|
333
|
+
result = <<~EOF.chomp
|
311
334
|
<screen>
|
312
335
|
#{node.content}
|
313
336
|
</screen>
|
314
337
|
EOF
|
315
338
|
end
|
339
|
+
|
340
|
+
# Return the XML output:
|
341
|
+
add_block_title result, node.title, 'listing'
|
316
342
|
end
|
317
343
|
|
318
344
|
def convert_literal node
|
319
|
-
|
345
|
+
# Compose the XML output:
|
346
|
+
result = <<~EOF.chomp
|
320
347
|
<pre>
|
321
348
|
#{node.content}
|
322
349
|
</pre>
|
323
350
|
EOF
|
351
|
+
|
352
|
+
# Return the XML output:
|
353
|
+
add_block_title result, node.title, 'literal'
|
324
354
|
end
|
325
355
|
|
326
|
-
# FIXME: Add support for titles.
|
327
356
|
def convert_olist node
|
328
357
|
# Open the ordered list:
|
329
358
|
result = ['<ol>']
|
@@ -345,7 +374,7 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
345
374
|
result << '</ol>'
|
346
375
|
|
347
376
|
# Return the XML output:
|
348
|
-
result.join LF
|
377
|
+
add_block_title (result.join LF), node.title, 'olist'
|
349
378
|
end
|
350
379
|
|
351
380
|
# FIXME: This is not the top priority.
|
@@ -364,16 +393,7 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
364
393
|
end
|
365
394
|
|
366
395
|
def convert_paragraph node
|
367
|
-
|
368
|
-
if node.title?
|
369
|
-
<<~EOF.chomp
|
370
|
-
<div outputclass="paragraph">
|
371
|
-
#{compose_floating_title node.title}<p>#{node.content}</p>
|
372
|
-
</div>
|
373
|
-
EOF
|
374
|
-
else
|
375
|
-
%(<p>#{node.content}</p>)
|
376
|
-
end
|
396
|
+
add_block_title %(<p>#{node.content}</p>), node.title, 'paragraph'
|
377
397
|
end
|
378
398
|
|
379
399
|
def convert_preamble node
|
@@ -542,7 +562,6 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
542
562
|
%(<p outputclass="thematic-break"></p>)
|
543
563
|
end
|
544
564
|
|
545
|
-
# FIXME: Add support for titles.
|
546
565
|
def convert_ulist node
|
547
566
|
# Open the unordered list:
|
548
567
|
result = ['<ul>']
|
@@ -571,7 +590,7 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
571
590
|
result << '</ul>'
|
572
591
|
|
573
592
|
# Returned the XML output:
|
574
|
-
result.join LF
|
593
|
+
add_block_title (result.join LF), node.title, 'ulist'
|
575
594
|
end
|
576
595
|
|
577
596
|
def convert_verse node
|
@@ -623,7 +642,7 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
623
642
|
result << '</ol>'
|
624
643
|
|
625
644
|
# Return the XML output:
|
626
|
-
result.join LF
|
645
|
+
add_block_title (result.join LF), node.title, 'qanda'
|
627
646
|
end
|
628
647
|
|
629
648
|
def compose_horizontal_dlist node
|
@@ -678,27 +697,54 @@ class DitaConverter < Asciidoctor::Converter::Base
|
|
678
697
|
result << %(</table>)
|
679
698
|
|
680
699
|
# Return the XML output:
|
681
|
-
result.join LF
|
700
|
+
add_block_title (result.join LF), node.title, 'horizontal'
|
701
|
+
end
|
702
|
+
|
703
|
+
# Helper methods
|
704
|
+
|
705
|
+
def add_block_title content, title, context='wrapper'
|
706
|
+
# NOTE: Unlike AsciiDoc, DITA does not support titles assigned to
|
707
|
+
# certain block elements. As a workaround, I decided to use a paragraph
|
708
|
+
# with the outputclass attribute and wrap the block in a div element.
|
709
|
+
|
710
|
+
# Check if the title is defined:
|
711
|
+
return content unless title
|
712
|
+
|
713
|
+
# Issue a warning if block titles are disabled:
|
714
|
+
unless @titles_allowed
|
715
|
+
logger.warn "#{NAME}: Block titles not supported in DITA"
|
716
|
+
return content
|
717
|
+
end
|
718
|
+
|
719
|
+
# Return the XML output:
|
720
|
+
<<~EOF.chomp
|
721
|
+
<div outputclass="#{context}">
|
722
|
+
<p outputclass="title"><b>#{title}</b></p>
|
723
|
+
#{content}
|
724
|
+
</div>
|
725
|
+
EOF
|
682
726
|
end
|
683
727
|
|
684
|
-
def compose_floating_title title
|
728
|
+
def compose_floating_title title
|
685
729
|
# NOTE: Unlike AsciiDoc, DITA does not support floating titles or
|
686
730
|
# titles assigned to certain block elements. As a workaround, I decided
|
687
731
|
# to use a paragraph with the outputclass attribute.
|
688
732
|
|
689
|
-
# Check
|
690
|
-
|
733
|
+
# Check if the title is defined:
|
734
|
+
return '' unless title
|
735
|
+
|
736
|
+
# Issue a warning if floating titles are disabled:
|
737
|
+
unless @titles_allowed
|
738
|
+
logger.warn "#{NAME}: Floating titles not supported in DITA"
|
739
|
+
return ''
|
740
|
+
end
|
691
741
|
|
692
742
|
# Return the XML output:
|
693
|
-
|
743
|
+
%(<p outputclass="title"><b>#{title}</b></p>\n)
|
694
744
|
end
|
695
745
|
|
696
746
|
def compose_id id
|
697
747
|
id ? %( id="#{id}") : ''
|
698
748
|
end
|
699
|
-
|
700
|
-
def compose_title title
|
701
|
-
title ? %(<title>#{title}</title>\n) : ''
|
702
|
-
end
|
703
749
|
end
|
704
750
|
end
|
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.
|
4
|
+
version: 1.0.3
|
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-06-
|
11
|
+
date: 2024-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|