Skip to content

Commit 3abddfb

Browse files
committed
consistent width of terms in definition list tables: #473
1 parent 6d95d8e commit 3abddfb

File tree

4 files changed

+138
-38
lines changed

4 files changed

+138
-38
lines changed

lib/isodoc/itu/presentation_xml_convert.rb

+33
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,39 @@ def title_footnotes(isoxml)
208208
ret
209209
end
210210

211+
def block(docxml)
212+
super
213+
dl docxml
214+
end
215+
216+
def dl(xml)
217+
(xml.xpath(ns("//dl")) -
218+
xml.xpath(ns("//table//dl | //figure//dl | //formula//dl")))
219+
.each do |d|
220+
dl1(d)
221+
end
222+
end
223+
224+
def dl1(dlist)
225+
ret = dl2tbody(dlist)
226+
n = dlist.at(ns("./name")) and ret = "#{n.remove.to_xml}#{ret}"
227+
dlist.name = "table"
228+
dlist["class"] = "dl"
229+
dlist.children.first.previous = ret
230+
end
231+
232+
def dl2tbody(dlist)
233+
ret = ""
234+
dlist.elements.select { |n| %w{dt dd}.include? n.name }
235+
.each_slice(2) do |dt, dd|
236+
ret += "<tr><th width='20%'>#{dt.children.to_xml}</th>" \
237+
"<td width='80%'>#{dd.children.to_xml}</td></tr>"
238+
dt.replace(" ")
239+
dd.remove
240+
end
241+
"<tbody>#{ret}</tbody>"
242+
end
243+
211244
include Init
212245
end
213246
end

spec/isodoc/blocks_spec.rb

+47
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,53 @@
3030
.to be_equivalent_to xmlpp(output)
3131
end
3232

33+
it "processes dl" do
34+
input = <<~INPUT
35+
<itu-standard xmlns="https://www.calconnect.org/standards/itu">
36+
<preface>
37+
<clause type="toc" id="_" displayorder="1">
38+
<title depth="1">Table of Contents</title>
39+
</clause>
40+
<foreword displayorder="2">
41+
<dl id="A"><name>Deflist</name>
42+
<dt>A</dt><dd>B</dd>
43+
<dt>C</dt><dd>D</dd>
44+
<note>hien?</note>
45+
</dl>
46+
</foreword></preface>
47+
</itu-standard>
48+
INPUT
49+
output = <<~OUTPUT
50+
<itu-standard xmlns="https://www.calconnect.org/standards/itu" type="presentation">
51+
<preface>
52+
<foreword displayorder="1">
53+
<table id="A" class="dl">
54+
<name>Deflist</name>
55+
<tbody>
56+
<tr>
57+
<th width="20%">A</th>
58+
<td width="80%">B</td>
59+
</tr>
60+
<tr>
61+
<th width="20%">C</th>
62+
<td width="80%">D</td>
63+
</tr>
64+
</tbody>
65+
<note><name>NOTE</name>hien?</note>
66+
</table>
67+
</foreword>
68+
<clause type="toc" id="_" displayorder="2">
69+
<title depth="1">Table of Contents</title>
70+
</clause>
71+
</preface>
72+
</itu-standard>
73+
OUTPUT
74+
expect(xmlpp(strip_guid(IsoDoc::ITU::PresentationXMLConvert
75+
.new(presxml_options)
76+
.convert("test", input, true))))
77+
.to be_equivalent_to xmlpp(output)
78+
end
79+
3380
it "processes formulae" do
3481
input = <<~INPUT
3582
<iso-standard xmlns="http://riboseinc.com/isoxml">

spec/isodoc/i18n_spec.rb

+32-20
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@
5353
</term>
5454
</terms>
5555
<definitions id="L" displayorder="12"><title>4.</title>
56-
<dl>
57-
<dt>Symbol</dt>
58-
<dd>Definition</dd>
59-
</dl>
56+
<table class="dl">
57+
<tbody>
58+
<tr>
59+
<th width="20%">Symbol</th>
60+
<td width="80%">Definition</td>
61+
</tr>
62+
</tbody>
63+
</table>
6064
</definitions>
6165
<clause id="M" inline-header="false" obligation="normative" displayorder="13">
6266
<title depth="1">5.<tab/>Clause 4</title><clause id="N" inline-header="false" obligation="normative">
@@ -131,12 +135,14 @@
131135
</div>
132136
<div id="L" class="Symbols">
133137
<h1>4.</h1>
134-
<dl>
135-
<dt>
136-
<p>Symbol</p>
137-
</dt>
138-
<dd>Definition</dd>
139-
</dl>
138+
<table class="dl" style="">
139+
<tbody>
140+
<tr>
141+
<th style="font-weight:bold;" scope="row">Symbol</th>
142+
<td style="">Definition</td>
143+
</tr>
144+
</tbody>
145+
</table>
140146
</div>
141147
<div id="M">
142148
<h1>5.&#160; Clause 4</h1>
@@ -236,10 +242,14 @@
236242
</term>
237243
</terms>
238244
<definitions id="L" displayorder="11"><title>4.</title>
239-
<dl>
240-
<dt>Symbol</dt>
241-
<dd>Definition</dd>
242-
</dl>
245+
<table class="dl">
246+
<tbody>
247+
<tr>
248+
<th width="20%">Symbol</th>
249+
<td width="80%">Definition</td>
250+
</tr>
251+
</tbody>
252+
</table>
243253
</definitions>
244254
<clause id="M" inline-header="false" obligation="normative" displayorder="12">
245255
<title depth="1">5.<tab/>Clause 4</title><clause id="N" inline-header="false" obligation="normative">
@@ -317,12 +327,14 @@
317327
</div>
318328
<div id='L' class='Symbols'>
319329
<h1>4.</h1>
320-
<dl>
321-
<dt>
322-
<p>Symbol</p>
323-
</dt>
324-
<dd>Definition</dd>
325-
</dl>
330+
<table class="dl" style="">
331+
<tbody>
332+
<tr>
333+
<th style="font-weight:bold;" scope="row">Symbol</th>
334+
<td style="">Definition</td>
335+
</tr>
336+
</tbody>
337+
</table>
326338
</div>
327339
<div id='M'>
328340
<h1>5.&#12288;Clause 4</h1>

spec/isodoc/section_spec.rb

+26-18
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,14 @@
280280
</term>
281281
</terms>
282282
<definitions id="L" displayorder="12"><title>4.</title>
283-
<dl>
284-
<dt>Symbol</dt>
285-
<dd>Definition</dd>
286-
</dl>
283+
<table class="dl">
284+
<tbody>
285+
<tr>
286+
<th width="20%">Symbol</th>
287+
<td width="80%">Definition</td>
288+
</tr>
289+
</tbody>
290+
</table>
287291
</definitions>
288292
<clause id="M" inline-header="false" obligation="normative" displayorder="13">
289293
<title depth="1">5.<tab/>Clause 4</title><clause id="N" inline-header="false" obligation="normative">
@@ -358,12 +362,14 @@
358362
</div>
359363
<div id="L" class="Symbols">
360364
<h1>4.</h1>
361-
<dl>
362-
<dt>
363-
<p>Symbol</p>
364-
</dt>
365-
<dd>Definition</dd>
366-
</dl>
365+
<table class="dl" style="">
366+
<tbody>
367+
<tr>
368+
<th style="font-weight:bold;" scope="row">Symbol</th>
369+
<td style="">Definition</td>
370+
</tr>
371+
</tbody>
372+
</table>
367373
</div>
368374
<div id="M">
369375
<h1>5.&#160; Clause 4</h1>
@@ -466,14 +472,16 @@
466472
</div>
467473
<div id="L" class="Symbols">
468474
<h1>4.</h1>
469-
<table class="dl">
470-
<tr>
471-
<td valign="top" align="left">
472-
<p align="left" style="margin-left:0pt;text-align:left;">Symbol</p>
473-
</td>
474-
<td valign="top">Definition</td>
475-
</tr>
476-
</table>
475+
<div align="center" class="table_container">
476+
<table class="dl" style="mso-table-anchor-horizontal:column;mso-table-overlap:never;">
477+
<tbody>
478+
<tr>
479+
<th valign="top" style="font-weight:bold;page-break-after:auto;">Symbol</th>
480+
<td valign="top" style="page-break-after:auto;">Definition</td>
481+
</tr>
482+
</tbody>
483+
</table>
484+
</div>
477485
</div>
478486
<div id="M">
479487
<h1>5.<span style="mso-tab-count:1">&#160; </span>Clause 4</h1>

0 commit comments

Comments
 (0)