asciidoctor-dita-topic 1.0.4 → 1.0.5

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dita-topic.rb +96 -21
  3. metadata +45 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d45cb29a7858229349b8b0e0720e743bb4ef1f64e1b0a8bab45881857cb99d4b
4
- data.tar.gz: 702f56d97c748811b7e7debd9863ffdc040e60c139e096dfde85add9c6657ff1
3
+ metadata.gz: 5d8849df85b9b5beff0e0e583464b4e1398ca56fe49b52255dd27a9f072ddf9a
4
+ data.tar.gz: dff16a2d22920219d867521ed689df99cde217c750394010e5057c10a7b68730
5
5
  SHA512:
6
- metadata.gz: 989fba23583530694c22087ce3939545b5ebcaeb7eb1f68de87eb69da44be5a5c2ec73362bb89e0bffb9c625e489761d615b35eb0b2682caa18e12f2cea417b9
7
- data.tar.gz: 992a47a33f10c3aa5ec87e57d5ca78df2bbc7e6df22fc48cfbe62b50ac4244ae1e3ecb29bf3cb61e8d6e00364c97bf131d613842cbf0265a2e1907fd356a6235
6
+ metadata.gz: 01752f000d44a620eb19726e23a86b2d67eb9fe5559dd1a7949d75af941ce7dfabdb9e7d49aa7342a8c5742984d078149d029062d6778fed9e3b0d21071e926b
7
+ data.tar.gz: fe84a2ebe09d0376897a9d1858b214c8103519236e4456f66d6496d152cb6d9838f3de14cce5db9576b5aa916a53f1ab956f122ac6e9a591675ebf2acd997302
data/lib/dita-topic.rb CHANGED
@@ -35,11 +35,17 @@ class DitaTopic < Asciidoctor::Converter::Base
35
35
 
36
36
  # Enable floating and block titles by default:
37
37
  @titles_allowed = true
38
+
39
+ # Enable callouts by default:
40
+ @callouts_allowed = true
38
41
  end
39
42
 
40
43
  def convert_document node
41
44
  # Check if floating and block titles are enabled:
42
- @titles_allowed = false if (node.attr 'dita-topic-titles') == 'strict'
45
+ @titles_allowed = false if (node.attr 'dita-topic-titles') == 'off'
46
+
47
+ # Check if callouts are enabled:
48
+ @callouts_allowed = false if (node.attr 'dita-topic-callouts') == 'off'
43
49
 
44
50
  # Check if a specific topic type is provided:
45
51
  if (value = node.attr 'dita-topic-type') =~ /^(concept|reference|task)$/
@@ -90,12 +96,55 @@ class DitaTopic < Asciidoctor::Converter::Base
90
96
  return ''
91
97
  end
92
98
 
93
- # FIXME: Figure out how to handle this along with convert_inline_callout.
94
- # A definition list looks like a reasonable option.
95
99
  def convert_colist node
96
- # Issue a warning if a callout list is present:
97
- logger.warn "#{NAME}: Callout list support not implemented"
98
- return ''
100
+ # Issue a warning if callouts are disabled:
101
+ unless @callouts_allowed
102
+ logger.warn "#{NAME}: Callouts not supported in DITA"
103
+ return ''
104
+ end
105
+
106
+ # Reset the counter:
107
+ number = 0
108
+
109
+ # Open the table:
110
+ result = ['<table>']
111
+ result << %(<tgroup cols="2">)
112
+ result << %(<colspec colwidth="#{node.attr 'labelwidth', 15}*" />)
113
+ result << %(<colspec colwidth="#{node.attr 'itemwidth', 85}*" />)
114
+ result << %(<tbody>)
115
+
116
+ # Process individual list items:
117
+ node.items.each do |item|
118
+ # Increment the counter:
119
+ number += 1
120
+
121
+ # Open the table row:
122
+ result << %(<row>)
123
+
124
+ # Compose the callout number:
125
+ result << %(<entry>#{compose_circled_number number}</entry>)
126
+
127
+ # Check if description contains multiple block elements:
128
+ if item.blocks
129
+ result << %(<entry>)
130
+ result << %(<p>#{item.text}</p>)
131
+ result << item.content
132
+ result << %(</entry>)
133
+ else
134
+ result << %(<entry>#{item.text}</entry>)
135
+ end
136
+
137
+ # Close the row:
138
+ result << %(</row>)
139
+ end
140
+
141
+ # Close the table:
142
+ result << %(</tbody>)
143
+ result << %(</tgroup>)
144
+ result << %(</table>)
145
+
146
+ # Return the XML output:
147
+ result.join LF
99
148
  end
100
149
 
101
150
  def convert_dlist node
@@ -163,21 +212,25 @@ class DitaTopic < Asciidoctor::Converter::Base
163
212
  %(<p outputclass="title sect#{node.level}"><b>#{node.title}</b></p>)
164
213
  end
165
214
 
166
- # FIXME: Add support for additional attributes.
167
- def convert_image node
215
+ def convert_image(node)
216
+ # Check if additional attributes are specified:
217
+ width = (node.attr? 'width') ? %( width="#{node.attr 'width'}") : ''
218
+ height = (node.attr? 'height') ? %( height="#{node.attr 'height'}") : ''
219
+ scale = (node.attr? 'scale') ? %( scale="#{(node.attr 'scale').tr('%', '')}") : ''
220
+
168
221
  # Check if the image has a title specified:
169
222
  if node.title?
170
223
  <<~EOF.chomp
171
224
  <fig>
172
225
  <title>#{node.title}</title>
173
- <image href="#{node.image_uri(node.attr 'target')}" placement="break">
226
+ <image href="#{node.image_uri(node.attr 'target')}"#{width}#{height}#{scale} placement="break">
174
227
  <alt>#{node.alt}</alt>
175
228
  </image>
176
229
  </fig>
177
230
  EOF
178
231
  else
179
232
  <<~EOF.chomp
180
- <image href="#{node.image_uri(node.attr 'target')}" placement="break">
233
+ <image href="#{node.image_uri(node.attr 'target')}"#{width}#{height}#{scale} placement="break">
181
234
  <alt>#{node.alt}</alt>
182
235
  </image>
183
236
  EOF
@@ -250,9 +303,14 @@ class DitaTopic < Asciidoctor::Converter::Base
250
303
  end
251
304
 
252
305
  def convert_inline_callout node
253
- # Issue a warning if an inline callout is present:
254
- logger.warn "#{NAME}: Callout list support not implemented"
255
- return ''
306
+ # Issue a warning if callouts are disabled:
307
+ unless @callouts_allowed
308
+ logger.warn "#{NAME}: Callouts not supported in DITA"
309
+ return ''
310
+ end
311
+
312
+ # Return the XML entity:
313
+ compose_circled_number node.text.to_i
256
314
  end
257
315
 
258
316
  # FIXME: Add support for footnoteref equivalent.
@@ -260,9 +318,13 @@ class DitaTopic < Asciidoctor::Converter::Base
260
318
  %(<fn>#{node.text}</fn>)
261
319
  end
262
320
 
263
- # FIXME: Add support for additional attributes.
264
321
  def convert_inline_image node
265
- %(<image href="#{node.image_uri node.target}" placement="inline"><alt>#{node.alt}</alt></image>)
322
+ # Check if additional attributes are specified:
323
+ width = (node.attr? 'width') ? %( width="#{node.attr 'width'}") : ''
324
+ height = (node.attr? 'height') ? %( height="#{node.attr 'height'}") : ''
325
+
326
+ # Return the XML output:
327
+ %(<image href="#{node.image_uri node.target}"#{width}#{height} placement="inline"><alt>#{node.alt}</alt></image>)
266
328
  end
267
329
 
268
330
  def convert_inline_indexterm node
@@ -504,7 +566,7 @@ class DitaTopic < Asciidoctor::Converter::Base
504
566
  # Process each row:
505
567
  rows.each do |row|
506
568
  # Open the row:
507
- result <<%(<row>)
569
+ result << %(<row>)
508
570
 
509
571
  # Process each cell:
510
572
  row.each do |cell|
@@ -537,7 +599,7 @@ class DitaTopic < Asciidoctor::Converter::Base
537
599
  end
538
600
 
539
601
  # Close the row:
540
- result <<%(</row>)
602
+ result << %(</row>)
541
603
  end
542
604
 
543
605
  # Close the section:
@@ -648,13 +710,9 @@ class DitaTopic < Asciidoctor::Converter::Base
648
710
  def compose_horizontal_dlist node
649
711
  # Open the table:
650
712
  result = ['<table>']
651
-
652
- # Define the table properties and open the tgroup:
653
713
  result << %(<tgroup cols="2">)
654
714
  result << %(<colspec colwidth="#{node.attr 'labelwidth', 15}*" />)
655
715
  result << %(<colspec colwidth="#{node.attr 'itemwidth', 85}*" />)
656
-
657
- # Open the table body:
658
716
  result << %(<tbody>)
659
717
 
660
718
  # Process individual list items:
@@ -752,5 +810,22 @@ class DitaTopic < Asciidoctor::Converter::Base
752
810
  def compose_id id
753
811
  id ? %( id="#{id}") : ''
754
812
  end
813
+
814
+ def compose_circled_number number
815
+ # Verify the number is in a supported range:
816
+ if number < 1 || number > 50
817
+ logger.warn "#{NAME}: Callout number not in range between 1 and 50"
818
+ return number
819
+ end
820
+
821
+ # Compose the XML entity:
822
+ if number < 21
823
+ %(&##{9311 + number};)
824
+ elsif number < 36
825
+ %(&##{12860 + number};)
826
+ else
827
+ %(&##{12941 + number};)
828
+ end
829
+ end
755
830
  end
756
831
  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
4
+ version: 1.0.5
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-07-02 00:00:00.000000000 Z
11
+ date: 2024-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -30,6 +30,48 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 12.3.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 12.3.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 5.22.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 5.22.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rexml
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 3.2.6
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 3.2.6
33
75
  description: An extension for AsciiDoctor that converts a single AsciiDoc file to
34
76
  a DITA topic.
35
77
  email: jhradilek@gmail.com
@@ -60,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
102
  - !ruby/object:Gem::Version
61
103
  version: '0'
62
104
  requirements: []
63
- rubygems_version: 3.5.9
105
+ rubygems_version: 3.5.11
64
106
  signing_key:
65
107
  specification_version: 4
66
108
  summary: A custom AsciiDoc converter that generates individual DITA topics