asciidoctor-dita-topic 1.0.1 → 1.0.2
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 +87 -41
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6f5805b63c0d48906d76f8f7e1b2bd5c639db80d455435040f8a2bad2f9e9d4
|
4
|
+
data.tar.gz: 1f09b2c11281e306607e0a128579373cd5cf9ef996b2cf2da67ec89804674e0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98822e7e8089ece8e20ee5b31404474ca32c181b2451142e03f62aaf0ef3d7d99201557996a5a5d5a69d9c9fb90fae14858354807932be0e8bc8de28b58d306b
|
7
|
+
data.tar.gz: d9147d53564a175c223aac1886cc6272fcfbe82e6bb61cb15f835412a662170aae28ec9cfe63b3bccdaa0910fafbc57341d82824a0cf9f378f425030c0b07a79
|
data/lib/dita-topic.rb
CHANGED
@@ -25,28 +25,43 @@
|
|
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 (type = node.attr 'dita-topic-type') =~ /^(concept|reference|task)$/
|
46
|
+
element = type
|
47
|
+
body = (type == 'task') ? 'taskbody' : %(#{type[0,3]}body)
|
48
|
+
else
|
49
|
+
element = '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
59
|
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
|
45
|
-
|
60
|
+
<#{element}#{compose_id (node.id or node.attributes['docname'])}#{outputclass}>
|
46
61
|
<title>#{node.doctitle}</title>
|
47
|
-
|
62
|
+
<#{body}>
|
48
63
|
#{node.content}
|
49
|
-
|
64
|
+
</#{body}>
|
50
65
|
</topic>
|
51
66
|
EOF
|
52
67
|
end
|
@@ -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.2
|
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
|
@@ -30,6 +30,34 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 2.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: minitest
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 5.22.0
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 5.22.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rexml
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.6
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.2.6
|
33
61
|
description: An extension for AsciiDoctor that converts a single AsciiDoc file to
|
34
62
|
a DITA topic.
|
35
63
|
email: jhradilek@gmail.com
|