Skip to content

Commit 0841ecd

Browse files
authored
Merge pull request #170 from metanorma/fix/bibitem-footnote-presxml
footnotes refactor; table source fix
2 parents 2eb4bd7 + 4cb9abf commit 0841ecd

File tree

6 files changed

+828
-107
lines changed

6 files changed

+828
-107
lines changed

Gemfile.devel

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/bibitem-footnote-presxml"
2+
gem "metanorma-iso", git: "https://github.com/metanorma/metanorma-iso", branch: "fix/bibitem-footnote-presxml"
3+
gem "metanorma-jis", git: "https://github.com/metanorma/metanorma-jis", branch: "fix/bibitem-footnote-presxml"

lib/isodoc/plateau/plateau.international-standard.xsl

+10-2
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,11 @@
28532853

28542854
<xsl:template name="refine_table-fmt-fn-label-style">
28552855

2856+
<xsl:attribute name="font-size">60%</xsl:attribute>
2857+
<xsl:attribute name="vertical-align">super</xsl:attribute>
2858+
<xsl:attribute name="padding-right">2mm</xsl:attribute>
2859+
<xsl:attribute name="font-weight">bold</xsl:attribute>
2860+
28562861
</xsl:template>
28572862

28582863
<xsl:attribute-set name="fn-container-body-style">
@@ -5049,11 +5054,14 @@
50495054

50505055
<!-- except gb and bsi -->
50515056

5052-
<xsl:apply-templates select="../*[local-name()='p']"/>
5057+
<!-- https://github.com/metanorma/metanorma-plateau/issues/171 : the order is: definition list, text paragraphs, EXAMPLEs, NOTEs, footnotes, then source at the end -->
50535058
<xsl:apply-templates select="../*[local-name()='dl']"/>
5054-
<xsl:apply-templates select="../*[local-name()='note'][not(@type = 'units')]"/>
5059+
<xsl:apply-templates select="../*[local-name()='p']"/>
50555060
<xsl:apply-templates select="../*[local-name()='example']"/>
5061+
<xsl:apply-templates select="../*[local-name()='note'][not(@type = 'units')]"/>
5062+
<!-- <xsl:copy-of select="$table_fn_block"/> -->
50565063
<xsl:apply-templates select="../*[local-name()='source']"/>
5064+
<!-- renders in tfoot -->
50575065

50585066
<xsl:variable name="isDisplayRowSeparator">
50595067

lib/isodoc/plateau/presentation_xml_convert.rb

+82
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,88 @@ def ol_depth(node)
7979
@iso.ol_depth(node)
8080
end
8181

82+
# how many columns in the table?
83+
def table_col_count(table)
84+
cols = 0
85+
table&.at(ns(".//tr"))&.xpath(ns("./td | ./th"))&.each do |td|
86+
cols += (td["colspan"] ? td["colspan"].to_i : 1)
87+
end
88+
cols
89+
end
90+
91+
# if there is already a full-row cell at the start of tfoot, use that to move content into
92+
# else create a full-row cell at the start of tfoot
93+
def initial_tfoot_cell(node)
94+
colspan = table_col_count(node)
95+
tfoot_start = node.at(ns("./tfoot/tr/td"))
96+
if !tfoot_start
97+
node.at(ns("./tbody")).after("<tfoot><tr><td colspan='#{colspan}'> </td></tr></tfoot>").first
98+
tfoot_start = node.at(ns("./tfoot/tr/td"))
99+
end
100+
if tfoot_start["colspan"] != colspan.to_s
101+
tfoot_start.parent.previous = "<tr><td colspan='#{colspan}'> </td></tr>"
102+
tfoot_start = node.at(ns("./tfoot/tr/td"))
103+
end
104+
tfoot_start
105+
end
106+
107+
# if there is already a full-row cell at the end of tfoot, use that to move content into
108+
# else create a full-row cell at the end of tfoot
109+
def final_tfoot_cell(node)
110+
colspan = table_col_count(node)
111+
tfoot_start = node.at(ns("./tfoot/tr[last()]/td"))
112+
if !tfoot_start
113+
node.at(ns("./tbody")).after("<tfoot><tr><td colspan='#{colspan}'> </td></tr></tfoot>").first
114+
tfoot_start = node.at(ns("./tfoot/tr[last()]/td"))
115+
end
116+
if tfoot_start["colspan"] != colspan.to_s
117+
tfoot_start.parent.next = "<tr><td colspan='#{colspan}'> </td></tr>"
118+
tfoot_start = node.at(ns("./tfoot/tr[last()]/td"))
119+
end
120+
tfoot_start
121+
end
122+
123+
def table1(node)
124+
super
125+
# move dl, notes, footnotes, source, fmt-footnote-container inside tfoot
126+
if node.at(ns("./dl"))
127+
tf = initial_tfoot_cell(node)
128+
node.xpath(ns("./dl")).reverse_each do |x|
129+
tf.children.first.previous = x.remove
130+
end
131+
end
132+
if node.at(ns("./note | ./source | ./example | ./fmt-footnote-container"))
133+
tf = final_tfoot_cell(node)
134+
node.xpath(ns("./example")).each { |x| tf.children.last.next = x.remove }
135+
node.xpath(ns("./note")).each { |x| tf.children.last.next = x.remove }
136+
node.xpath(ns("./fmt-footnote-container")).each { |x| tf.children.last.next = x.remove }
137+
node.xpath(ns("./source")).each do |x|
138+
tf.children.last.next = x.remove
139+
end
140+
end
141+
end
142+
143+
# Undo JIS encoding of figure and table dl as paragraphs
144+
def dl(docxml)
145+
docxml.xpath(ns("//dl")).each { |f| dl1(f) }
146+
docxml.xpath(ns("//table//dl | //figure//dl")).each do |l|
147+
l.at(ns("./dl")) || l.at("./ancestor::xmlns:dl") and next
148+
table_key(l)
149+
end
150+
end
151+
152+
# Insert localised colon at start of dd in table and figure key,
153+
# replacing JIS Word <p class='dl' id='#{dt['id']}'>#{term}: #{bkmk}#{defn}</p>
154+
# with <dt>{term}</dt> <dd>: {defn}<dd>; the space should be stripped and
155+
# the colon double-width for Japanese text
156+
def table_key(node)
157+
node.xpath(ns(".//dd")).each do |dd|
158+
text_node = dd.xpath(".//text()[normalize-space()]").first or next
159+
colon = %w(zh ja ko).include?(@lang) ? ":": ": "
160+
text_node.previous = "<span class='fmt-dt-delim'>#{colon}</span>"
161+
end
162+
end
163+
82164
include Init
83165
end
84166
end

lib/metanorma/plateau/isodoc.rng

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
</zeroOrMore>
3434
</element>
3535
</define>
36+
<define name="fn" combine="interleave">
37+
<optional>
38+
<attribute name="hiddenref">
39+
<a:documentation>If true, number the footnote as normal, but suppress display of the footnote reference in the document body.
40+
This is done if the footnote reference is already presented in some other form, e.g. within a figure image.</a:documentation>
41+
<data type="boolean"/>
42+
</attribute>
43+
</optional>
44+
</define>
3645
<define name="index-primary">
3746
<element name="primary">
3847
<oneOrMore>

spec/isodoc/blocks_spec.rb

+75-21
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@
7373
Split-it-right
7474
<em>sample</em>
7575
divider
76-
<fn reference="1">
76+
<fn reference="1" original-reference="1" target="_" original-id="_">
7777
<p>X</p>
78+
<fmt-fn-label>
79+
<sup>
80+
<semx element="autonum" source="_">1</semx>
81+
</sup>
82+
</fmt-fn-label>
7883
</fn>
7984
</name>
8085
<fmt-name>
@@ -89,8 +94,13 @@
8994
Split-it-right
9095
<em>sample</em>
9196
divider
92-
<fn reference="1">
97+
<fn reference="1" original-reference="1" id="_" target="_">
9398
<p>X</p>
99+
<fmt-fn-label>
100+
<sup>
101+
<semx element="autonum" source="_">1</semx>
102+
</sup>
103+
</fmt-fn-label>
94104
</fn>
95105
</semx>
96106
</fmt-name>
@@ -104,20 +114,34 @@
104114
<image src="rice_images/rice_image1.png" height="20" width="auto" id="_" mimetype="image/png"/>
105115
<image src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" height="20" width="auto" id="_" mimetype="image/png"/>
106116
<image src="data:application/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjw/eG1sLXN0eWxlc2hlZXQgdHlwZT0idGV4dC94c2wiIGhyZWY9Ii4uLy4uLy4uL3hzbC9yZXNfZG9jL2ltZ2ZpbGUueHNsIj8+CjwhRE9DVFlQRSBpbWdmaWxlLmNvbnRlbnQgU1lTVEVNICIuLi8uLi8uLi9kdGQvdGV4dC5lbnQiPgo8aW1nZmlsZS5jb250ZW50IG1vZHVsZT0iZnVuZGFtZW50YWxzX29mX3Byb2R1Y3RfZGVzY3JpcHRpb25fYW5kX3N1cHBvcnQiIGZpbGU9ImFjdGlvbl9zY2hlbWFleHBnMS54bWwiPgo8aW1nIHNyYz0iYWN0aW9uX3NjaGVtYWV4cGcxLmdpZiI+CjxpbWcuYXJlYSBzaGFwZT0icmVjdCIgY29vcmRzPSIyMTAsMTg2LDM0MywyMjciIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9iYXNpY19hdHRyaWJ1dGVfc2NoZW1hL2Jhc2ljX2F0dHJpYnV0ZV9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMTAsMTAsOTYsNTEiIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9hY3Rpb25fc2NoZW1hL2FjdGlvbl9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMjEwLDI2NCwzNTgsMzA1IiBocmVmPSIuLi8uLi9yZXNvdXJjZXMvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEueG1sIiAvPgo8L2ltZz4KPC9pbWdmaWxlLmNvbnRlbnQ+Cg==" height="20" width="auto" id="_" mimetype="application/xml"/>
107-
<fn reference="a)">
108-
<p id="_">
117+
<fn reference="a" id="_" target="_">
118+
<p original-id="_">
109119
The time
110120
<stem type="AsciiMath" id="_">t_90</stem>
111121
<fmt-stem type="AsciiMath">
112122
<semx element="stem" source="_">t_90</semx>
113123
</fmt-stem>
114124
was estimated to be 18,2 min for this example.
115125
</p>
126+
<fmt-fn-label>
127+
<sup>
128+
<semx element="autonum" source="_">a</semx>
129+
<span class="fmt-label-delim">)</span>
130+
</sup>
131+
</fmt-fn-label>
116132
</fn>
117133
<p keep-with-next="true">
118134
<strong>Key</strong>
119135
</p>
120-
<p class="dl">A: B</p>
136+
<dl class="formula_dl">
137+
<dt>A</dt>
138+
<dd>
139+
<p>
140+
<span class="fmt-dt-delim">: </span>
141+
B
142+
</p>
143+
</dd>
144+
</dl>
121145
<source status="generalisation">
122146
[SOURCE:
123147
<origin bibitemid="ISO712" type="inline" citeas="ISO 712" id="_">
@@ -134,6 +158,30 @@
134158
<semx element="modification" source="_">with adjustments</semx>
135159
]
136160
</source>
161+
<fmt-footnote-container>
162+
<fmt-fn-body id="_" target="_" reference="a">
163+
<semx element="fn" source="_">
164+
<p id="_">
165+
<fmt-fn-label>
166+
<sup>
167+
Footnote
168+
<semx element="autonum" source="_">a</semx>
169+
<span class="fmt-label-delim">)</span>
170+
</sup>
171+
<span class="fmt-caption-delim">
172+
<tab/>
173+
</span>
174+
</fmt-fn-label>
175+
The time
176+
<stem type="AsciiMath" id="_">t_90</stem>
177+
<fmt-stem type="AsciiMath">
178+
<semx element="stem" source="_">t_90</semx>
179+
</fmt-stem>
180+
was estimated to be 18,2 min for this example.
181+
</p>
182+
</semx>
183+
</fmt-fn-body>
184+
</fmt-footnote-container>
137185
</figure>
138186
<figure id="figure-B" autonum="1-2">
139187
<fmt-name>
@@ -168,32 +216,38 @@
168216
<img src="rice_images/rice_image1.png" height="20" width="auto"/>
169217
<img src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" height="20" width="auto"/>
170218
<img src="data:application/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjw/eG1sLXN0eWxlc2hlZXQgdHlwZT0idGV4dC94c2wiIGhyZWY9Ii4uLy4uLy4uL3hzbC9yZXNfZG9jL2ltZ2ZpbGUueHNsIj8+CjwhRE9DVFlQRSBpbWdmaWxlLmNvbnRlbnQgU1lTVEVNICIuLi8uLi8uLi9kdGQvdGV4dC5lbnQiPgo8aW1nZmlsZS5jb250ZW50IG1vZHVsZT0iZnVuZGFtZW50YWxzX29mX3Byb2R1Y3RfZGVzY3JpcHRpb25fYW5kX3N1cHBvcnQiIGZpbGU9ImFjdGlvbl9zY2hlbWFleHBnMS54bWwiPgo8aW1nIHNyYz0iYWN0aW9uX3NjaGVtYWV4cGcxLmdpZiI+CjxpbWcuYXJlYSBzaGFwZT0icmVjdCIgY29vcmRzPSIyMTAsMTg2LDM0MywyMjciIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9iYXNpY19hdHRyaWJ1dGVfc2NoZW1hL2Jhc2ljX2F0dHJpYnV0ZV9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMTAsMTAsOTYsNTEiIGhyZWY9Ii4uLy4uL3Jlc291cmNlcy9hY3Rpb25fc2NoZW1hL2FjdGlvbl9zY2hlbWEueG1sIiAvPgo8aW1nLmFyZWEgc2hhcGU9InJlY3QiIGNvb3Jkcz0iMjEwLDI2NCwzNTgsMzA1IiBocmVmPSIuLi8uLi9yZXNvdXJjZXMvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEvc3VwcG9ydF9yZXNvdXJjZV9zY2hlbWEueG1sIiAvPgo8L2ltZz4KPC9pbWdmaWxlLmNvbnRlbnQ+Cg==" height="20" width="auto"/>
171-
<a href="#_" class="TableFootnoteRef">a)</a>
172-
<aside class="footnote">
173-
<div id="fn:_">
174-
<span>
175-
Footnote
176-
<span id="_" class="TableFootnoteRef">a)</span>
177-
 
178-
</span>
179-
<p id="_">
180-
The time
181-
<span class="stem">(#(t_90)#)</span>
182-
was estimated to be 18,2 min for this example.
183-
</p>
184-
</div>
185-
</aside>
219+
<a href="#figureA-1a" class="TableFootnoteRef">a)</a>
186220
<p style="page-break-after: avoid;">
187221
<b>Key</b>
188222
</p>
189-
<p class="dl">A: B</p>
223+
<div class="figdl">
224+
<dl class="formula_dl">
225+
<dt>
226+
<p>A</p>
227+
</dt>
228+
<dd>
229+
<p>
230+
<span class="fmt-dt-delim">: </span>
231+
B
232+
</p>
233+
</dd>
234+
</dl>
235+
</div>
190236
<div class="BlockSource">
191237
<p>
192238
[SOURCE:
193239
<a href="#ISO712">ISO 712, Section 1</a>
194240
— with adjustments]
195241
</p>
196242
</div>
243+
<aside id="fn:figureA-1a" class="footnote">
244+
<p id="_">
245+
<span class="TableFootnoteRef">Footnote a)</span>
246+
  The time
247+
<span class="stem">(#(t_90)#)</span>
248+
was estimated to be 18,2 min for this example.
249+
</p>
250+
</aside>
197251
<p class="FigureTitle" style="text-align:center;">
198252
Figure 1-1 — Split-it-right
199253
<i>sample</i>

0 commit comments

Comments
 (0)