metanorma-iso 3.4.6 → 3.4.7

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.
@@ -84,15 +84,11 @@ module IsoDoc
84
84
  insert_biblio_callout(elem)
85
85
  end
86
86
 
87
- # TODO share with metanorma dir
88
- ISO_PUBLISHER_XPATH = <<~XPATH.freeze
89
- ./contributor[role/@type = 'publisher']/organization[abbreviation = 'ISO' or abbreviation = 'IEC' or name = 'International Organization for Standardization' or name = 'International Electrotechnical Commission']
90
- XPATH
91
-
92
87
  def insert_biblio_callout(elem)
93
88
  semx = elem.document.at("//*[@id = '#{elem['source']}']") or return
94
89
  if ref = @bibitem_lookup[semx["bibitemid"]]
95
- ref.at(ns(ISO_PUBLISHER_XPATH)) and return
90
+ Metanorma::Iso::PublisherIdentity
91
+ .iso_iec_publisher?(ref, ns: method(:ns)) and return
96
92
  # is this reference cited with a [n],
97
93
  # even if it has its own SDO identifier?
98
94
  citeas = ref.at(ns("./docidentifier[@type = 'metanorma-ordinal']")) ||
@@ -16,7 +16,11 @@ module IsoDoc
16
16
  end
17
17
 
18
18
  def convert1(docxml, filename, dir)
19
- @iso_class = instance_of?(IsoDoc::Iso::PresentationXMLConvert)
19
+ # ISO-only (not inheriting flavours, and -- unlike instance_of? --
20
+ # not tastes that reuse this class): gate on the document publisher.
21
+ # metanorma/metanorma-oiml#13.
22
+ @iso_class = Metanorma::Iso::PublisherIdentity
23
+ .iso_publisher?(docxml.at(ns("//bibdata")), ns: method(:ns))
20
24
  if amd?(docxml)
21
25
  @oldsuppressheadingnumbers = @suppressheadingnumbers
22
26
  @suppressheadingnumbers = true
@@ -181,8 +181,7 @@ module IsoDoc
181
181
  # do not use in IEC, BSI, where Word does not use list to generate
182
182
  # "Annex A"
183
183
  def annex_toc(annexid)
184
- instance_of?(IsoDoc::Iso::WordConvert) ||
185
- instance_of?(WordDISConvert) or return ""
184
+ @iso_publisher or return ""
186
185
  annexid += 1
187
186
  x = "#{@i18n.annex} #{('@'.ord + annexid).chr} "
188
187
  [x, annexid]
@@ -58,6 +58,17 @@ module IsoDoc
58
58
  end
59
59
  end
60
60
 
61
+ # word_cleanup (make_WordToC / annex_toc) runs on the generated Word
62
+ # HTML, which no longer carries <bibdata>; capture the document's
63
+ # ISO-publisher identity here, off the source presentation XML, and
64
+ # propagate it via @iso_publisher. ISO-only (not IEC/BSI, and --
65
+ # unlike instance_of? -- not tastes reusing this class). oiml#13.
66
+ def convert1(docxml, filename, dir)
67
+ @iso_publisher = Metanorma::Iso::PublisherIdentity
68
+ .iso_publisher?(docxml.at(ns("//bibdata")), ns: method(:ns))
69
+ super
70
+ end
71
+
61
72
  def make_body(xml, docxml)
62
73
  body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
63
74
  xml.body(**body_attr) do |body|
@@ -1902,15 +1902,40 @@ or as the string "auto"</a:documentation>
1902
1902
  <a:documentation>Mathematically formatted text</a:documentation>
1903
1903
  <element name="stem">
1904
1904
  <ref name="StemAttributes"/>
1905
- <oneOrMore>
1906
- <choice>
1905
+ <optional>
1906
+ <text>
1907
1907
  <a:documentation>The content of the mathematically formatted text</a:documentation>
1908
- <text/>
1909
- <ref name="AnyElement"/>
1910
- </choice>
1911
- </oneOrMore>
1908
+ </text>
1909
+ </optional>
1910
+ <optional>
1911
+ <ref name="mathml"/>
1912
+ </optional>
1913
+ <optional>
1914
+ <ref name="asciimath"/>
1915
+ </optional>
1916
+ <optional>
1917
+ <ref name="latexmath"/>
1918
+ </optional>
1912
1919
  </element>
1913
1920
  </define>
1921
+ <define name="latexmath">
1922
+ <a:documentation>Encoding of LatexMath</a:documentation>
1923
+ <element name="latexmath">
1924
+ <text/>
1925
+ </element>
1926
+ </define>
1927
+ <define name="asciimath">
1928
+ <a:documentation>Encoding of AsciiMath</a:documentation>
1929
+ <element name="asciimath">
1930
+ <text/>
1931
+ </element>
1932
+ </define>
1933
+ <define name="mathml">
1934
+ <a:documentation>Encoding of MathML: the official W3C MathML 3.0 grammar (namespace
1935
+ http://www.w3.org/1998/Math/MathML), via the metanorma wrapper in
1936
+ grammars/mathml/. See grammars/mathml/README.adoc and basicdoc-models#35.</a:documentation>
1937
+ <externalRef href="metanorma-mathml.rng"/>
1938
+ </define>
1914
1939
  <define name="StemAttributes">
1915
1940
  <attribute name="type">
1916
1941
  <a:documentation>The notation used to mathematically format the text</a:documentation>
@@ -90,8 +90,34 @@ module Metanorma
90
90
 
91
91
  def bibitem_cleanup(xmldoc)
92
92
  super
93
- unpublished_note(xmldoc)
94
- withdrawn_note(xmldoc)
93
+ cutoff = biblio_cutoff_date(xmldoc)
94
+ unpublished_note(xmldoc, cutoff)
95
+ withdrawn_note(xmldoc, cutoff)
96
+ end
97
+
98
+ # The citing document's publication date: reference status annotations
99
+ # (withdrawn/replaced, under-preparation) are rewound to this date, so a
100
+ # reference is not shown with a status change that only happened *after*
101
+ # the citing document was published. metanorma/metanorma-standoc#941.
102
+ def biblio_cutoff_date(xmldoc)
103
+ bd = xmldoc.at("//bibdata") or return nil
104
+ dates = bd.xpath("./date[@type = 'published' or @type = 'issued' or " \
105
+ "@type = 'circulated']/on").map { |d| iso_date(d.text) }
106
+ if (y = bd.at("./copyright/from")&.text)&.match?(/^\d{4}$/)
107
+ dates << Date.new(y.to_i, 12, 31)
108
+ end
109
+ dates.compact.max
110
+ end
111
+
112
+ # Complete a partial ISO date to the end of its period, so a status change
113
+ # anywhere within the citing document's publication year still counts as
114
+ # having occurred by publication.
115
+ def iso_date(str)
116
+ case str.to_s.strip
117
+ when /^(\d{4})$/ then Date.new($1.to_i, 12, 31)
118
+ when /^(\d{4})-(\d{2})/ then Date.new($1.to_i, $2.to_i, -1)
119
+ else Date.parse(str) rescue nil
120
+ end
95
121
  end
96
122
 
97
123
  def bibitem_note_types(bib)
@@ -100,21 +126,21 @@ module Metanorma
100
126
  end.flatten
101
127
  end
102
128
 
103
- def unpublished_note(xmldoc)
129
+ def unpublished_note(xmldoc, cutoff = nil)
104
130
  xmldoc.xpath("//bibitem[not(./ancestor::bibitem)]").each do |b|
105
131
  n = bibitem_note_types(b)
106
- n.include?("Unpublished-Status") or unpublished_note1(b)
132
+ n.include?("Unpublished-Status") or unpublished_note1(b, cutoff)
107
133
  end
108
134
  end
109
135
 
110
- def unpublished_note1(bibitem)
136
+ def unpublished_note1(bibitem, cutoff = nil)
111
137
  unpublished_ref?(bibitem) and return
112
138
  docid = bibitem.at("./docidentifier[@primary = 'true']") ||
113
139
  bibitem.at("./docidentifier[@type = 'ISO' or @type = 'IEC']") ||
114
140
  bibitem.at("./docidentifier")
115
141
  base_pubid, orig = parse_draft_docid(docid, bibitem)
116
142
  insert_unpub_note(bibitem, @i18n.under_preparation
117
- .sub("%", dated_draft_id(orig, base_pubid)))
143
+ .sub("%", dated_draft_id(orig, base_pubid, cutoff)))
118
144
  draft_biblio_docid(orig, base_pubid, docid)
119
145
  end
120
146
 
@@ -132,24 +158,24 @@ module Metanorma
132
158
  docid.children = new
133
159
  end
134
160
 
135
- def dated_draft_id(orig, base_pubid)
161
+ def dated_draft_id(orig, base_pubid, cutoff = nil)
136
162
  ret = orig.dup
137
- ret[:year] = Date.today.year
163
+ ret[:year] = cutoff&.year || Date.today.year
138
164
  base_pubid.create(**ret).to_s
139
165
  end
140
166
 
141
167
  def unpublished_ref?(bibitem)
142
- pub_class(bibitem) > 2 and return true
168
+ PublisherIdentity.iso_iec_publisher?(bibitem) or return true
143
169
  ((s = bibitem.at("./status/stage")) && s.text.match?(/\d/) &&
144
170
  (s.text.to_i < 60)) or return true
145
171
  false
146
172
  end
147
173
 
148
- def withdrawn_note(xmldoc)
174
+ def withdrawn_note(xmldoc, cutoff = nil)
149
175
  xmldoc.xpath("//bibitem").each do |b|
150
176
  n = bibitem_note_types(b)
151
177
  n.include?("Unpublished-Status") and next
152
- withdrawn_ref?(b) or next
178
+ withdrawn_ref?(b, cutoff) or next
153
179
  if id = replacement_standard(b)
154
180
  insert_unpub_note(b, @i18n.cancelled_and_replaced.sub("%", id))
155
181
  else insert_unpub_note(b, @i18n.withdrawn)
@@ -157,10 +183,23 @@ module Metanorma
157
183
  end
158
184
  end
159
185
 
160
- def withdrawn_ref?(bibitem)
161
- pub_class(bibitem) > 2 and return false
186
+ def withdrawn_ref?(bibitem, cutoff = nil)
187
+ PublisherIdentity.iso_iec_publisher?(bibitem) or return false
162
188
  (s = bibitem.at("./status/stage")) && (s.text.to_i == 95) &&
163
- (t = bibitem.at("./status/substage")) && (t.text.to_i == 99)
189
+ (t = bibitem.at("./status/substage")) && (t.text.to_i == 99) or
190
+ return false
191
+ # As-of-date: a withdrawal that only happened after the citing document
192
+ # was published did not apply then. metanorma/metanorma-standoc#941.
193
+ wd = withdrawal_date(bibitem)
194
+ !(cutoff && wd && wd > cutoff)
195
+ end
196
+
197
+ # Date the reference was superseded/withdrawn: the earliest published date
198
+ # of an obsoletedBy/updates successor.
199
+ def withdrawal_date(bibitem)
200
+ bibitem.xpath("./relation[@type = 'obsoletedBy' or @type = 'updates']" \
201
+ "/bibitem/date[@type = 'published' or @type = 'circulated']" \
202
+ "/on").map { |d| iso_date(d.text) }.compact.min
164
203
  end
165
204
 
166
205
  def replacement_standard(biblio)
@@ -852,7 +852,7 @@ titlecase, or lowercase</a:documentation>
852
852
  <a:documentation>Width of the figure block in rendering</a:documentation>
853
853
  </attribute>
854
854
  </optional>
855
- <ref name="BlockAttributes"/>
855
+ <ref name="BlockAttributesCore"/>
856
856
  </define>
857
857
  <define name="SourceAttributes" combine="interleave">
858
858
  <ref name="BlockAttributes"/>
@@ -1283,7 +1283,11 @@ That concept may be defined as a term within the current document, or it may be
1283
1283
  <a:documentation>Class of input form</a:documentation>
1284
1284
  </attribute>
1285
1285
  </optional>
1286
- <ref name="BlockAttributes"/>
1286
+ <ref name="BlockAttributesCore">
1287
+ <a:documentation>form declares its own class above, so it uses BlockAttributesCore to
1288
+ avoid duplicating the custom-class slot in BlockAttributes. Treated like
1289
+ figure. See metanorma/metanorma-standoc#1197</a:documentation>
1290
+ </ref>
1287
1291
  <zeroOrMore>
1288
1292
  <!-- Input form contents -->
1289
1293
  <choice>
@@ -2768,7 +2772,11 @@ links within an SVG file, so that the SVG file can hyperlink to anchors within t
2768
2772
  </oneOrMore>
2769
2773
  </element>
2770
2774
  </define>
2771
- <define name="BlockAttributes">
2775
+ <define name="BlockAttributesCore">
2776
+ <a:documentation>Block attributes excluding the custom CSS class. Blocks that already carry
2777
+ their own `class` attribute (e.g. figure, via basicdoc FigureAttributes)
2778
+ include this directly, to avoid a duplicate-attribute collision with the
2779
+ `class` added in BlockAttributes. See metanorma/metanorma-standoc#1197</a:documentation>
2772
2780
  <optional>
2773
2781
  <attribute name="keep-with-next">
2774
2782
  <a:documentation>Keep this block on the same page as the following block in paged media</a:documentation>
@@ -2800,6 +2808,17 @@ to span across both columns</a:documentation>
2800
2808
  </attribute>
2801
2809
  </optional>
2802
2810
  </define>
2811
+ <define name="BlockAttributes">
2812
+ <a:documentation>Universal block attributes, including a custom CSS class (space-separated,
2813
+ appended additively to the block's built-in HTML class, HTML output only).
2814
+ See metanorma/metanorma-standoc#1197</a:documentation>
2815
+ <ref name="BlockAttributesCore"/>
2816
+ <optional>
2817
+ <attribute name="class">
2818
+ <a:documentation>Custom CSS class(es) for the block in HTML output</a:documentation>
2819
+ </attribute>
2820
+ </optional>
2821
+ </define>
2803
2822
  <define name="DisplayDirective">
2804
2823
  <a:documentation>Directive on how to render a block in Presentation XML </a:documentation>
2805
2824
  <optional>
@@ -0,0 +1,257 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ This is the Mathematical Markup Language (MathML) 3.0, an XML
4
+ application for describing mathematical notation and capturing
5
+ both its structure and content.
6
+
7
+ Copyright 1998-2014 W3C (MIT, ERCIM, Keio, Beihang)
8
+
9
+ Use and distribution of this code are permitted under the terms
10
+ W3C Software Notice and License
11
+ http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
12
+ -->
13
+ <grammar ns="http://www.w3.org/1998/Math/MathML" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
14
+ <start>
15
+ <ref name="math"/>
16
+ </start>
17
+ <define name="math">
18
+ <element name="math">
19
+ <ref name="math.attributes"/>
20
+ <zeroOrMore>
21
+ <ref name="MathExpression"/>
22
+ </zeroOrMore>
23
+ </element>
24
+ </define>
25
+ <define name="MathExpression">
26
+ <ref name="semantics"/>
27
+ </define>
28
+ <define name="NonMathMLAtt">
29
+ <attribute>
30
+ <anyName>
31
+ <except>
32
+ <nsName ns=""/>
33
+ <nsName/>
34
+ </except>
35
+ </anyName>
36
+ <data type="string"/>
37
+ </attribute>
38
+ </define>
39
+ <define name="CommonDeprecatedAtt">
40
+ <optional>
41
+ <attribute name="other"/>
42
+ </optional>
43
+ </define>
44
+ <define name="CommonAtt">
45
+ <optional>
46
+ <attribute name="id">
47
+ <data type="ID"/>
48
+ </attribute>
49
+ </optional>
50
+ <optional>
51
+ <attribute name="xref"/>
52
+ </optional>
53
+ <optional>
54
+ <attribute name="class">
55
+ <data type="NMTOKENS"/>
56
+ </attribute>
57
+ </optional>
58
+ <optional>
59
+ <attribute name="style">
60
+ <data type="string"/>
61
+ </attribute>
62
+ </optional>
63
+ <optional>
64
+ <attribute name="href">
65
+ <data type="anyURI"/>
66
+ </attribute>
67
+ </optional>
68
+ <ref name="CommonDeprecatedAtt"/>
69
+ <zeroOrMore>
70
+ <ref name="NonMathMLAtt"/>
71
+ </zeroOrMore>
72
+ </define>
73
+ <define name="math.attributes">
74
+ <ref name="CommonAtt"/>
75
+ <optional>
76
+ <attribute name="display">
77
+ <choice>
78
+ <value>block</value>
79
+ <value>inline</value>
80
+ </choice>
81
+ </attribute>
82
+ </optional>
83
+ <optional>
84
+ <attribute name="maxwidth">
85
+ <ref name="length"/>
86
+ </attribute>
87
+ </optional>
88
+ <optional>
89
+ <attribute name="overflow">
90
+ <choice>
91
+ <value>linebreak</value>
92
+ <value>scroll</value>
93
+ <value>elide</value>
94
+ <value>truncate</value>
95
+ <value>scale</value>
96
+ </choice>
97
+ </attribute>
98
+ </optional>
99
+ <optional>
100
+ <attribute name="altimg">
101
+ <data type="anyURI"/>
102
+ </attribute>
103
+ </optional>
104
+ <optional>
105
+ <attribute name="altimg-width">
106
+ <ref name="length"/>
107
+ </attribute>
108
+ </optional>
109
+ <optional>
110
+ <attribute name="altimg-height">
111
+ <ref name="length"/>
112
+ </attribute>
113
+ </optional>
114
+ <optional>
115
+ <attribute name="altimg-valign">
116
+ <choice>
117
+ <ref name="length"/>
118
+ <value>top</value>
119
+ <value>middle</value>
120
+ <value>bottom</value>
121
+ </choice>
122
+ </attribute>
123
+ </optional>
124
+ <optional>
125
+ <attribute name="alttext"/>
126
+ </optional>
127
+ <optional>
128
+ <attribute name="cdgroup">
129
+ <data type="anyURI"/>
130
+ </attribute>
131
+ </optional>
132
+ <ref name="math.deprecatedattributes"/>
133
+ </define>
134
+ <!--
135
+ the mathml3-presentation schema adds additional attributes
136
+ to the math element, all those valid on mstyle
137
+ -->
138
+ <define name="math.deprecatedattributes">
139
+ <optional>
140
+ <attribute name="mode">
141
+ <data type="string"/>
142
+ </attribute>
143
+ </optional>
144
+ <optional>
145
+ <attribute name="macros">
146
+ <data type="string"/>
147
+ </attribute>
148
+ </optional>
149
+ </define>
150
+ <define name="name">
151
+ <attribute name="name">
152
+ <data type="NCName"/>
153
+ </attribute>
154
+ </define>
155
+ <define name="cd">
156
+ <attribute name="cd">
157
+ <data type="NCName"/>
158
+ </attribute>
159
+ </define>
160
+ <define name="src">
161
+ <optional>
162
+ <attribute name="src">
163
+ <data type="anyURI"/>
164
+ </attribute>
165
+ </optional>
166
+ </define>
167
+ <define name="annotation">
168
+ <element name="annotation">
169
+ <ref name="annotation.attributes"/>
170
+ <text/>
171
+ </element>
172
+ </define>
173
+ <define name="annotation-xml.model">
174
+ <zeroOrMore>
175
+ <choice>
176
+ <ref name="MathExpression"/>
177
+ <ref name="anyElement"/>
178
+ </choice>
179
+ </zeroOrMore>
180
+ </define>
181
+ <define name="anyElement">
182
+ <element>
183
+ <anyName>
184
+ <except>
185
+ <nsName/>
186
+ </except>
187
+ </anyName>
188
+ <zeroOrMore>
189
+ <choice>
190
+ <attribute>
191
+ <anyName/>
192
+ </attribute>
193
+ <text/>
194
+ <ref name="anyElement"/>
195
+ </choice>
196
+ </zeroOrMore>
197
+ </element>
198
+ </define>
199
+ <define name="annotation-xml">
200
+ <element name="annotation-xml">
201
+ <ref name="annotation.attributes"/>
202
+ <ref name="annotation-xml.model"/>
203
+ </element>
204
+ </define>
205
+ <define name="annotation.attributes">
206
+ <ref name="CommonAtt"/>
207
+ <optional>
208
+ <ref name="cd"/>
209
+ </optional>
210
+ <optional>
211
+ <ref name="name"/>
212
+ </optional>
213
+ <ref name="DefEncAtt"/>
214
+ <optional>
215
+ <ref name="src"/>
216
+ </optional>
217
+ </define>
218
+ <define name="DefEncAtt">
219
+ <optional>
220
+ <attribute name="encoding">
221
+ <data type="string"/>
222
+ </attribute>
223
+ </optional>
224
+ <optional>
225
+ <attribute name="definitionURL">
226
+ <data type="anyURI"/>
227
+ </attribute>
228
+ </optional>
229
+ </define>
230
+ <define name="semantics">
231
+ <element name="semantics">
232
+ <ref name="semantics.attributes"/>
233
+ <ref name="MathExpression"/>
234
+ <zeroOrMore>
235
+ <choice>
236
+ <ref name="annotation"/>
237
+ <ref name="annotation-xml"/>
238
+ </choice>
239
+ </zeroOrMore>
240
+ </element>
241
+ </define>
242
+ <define name="semantics.attributes">
243
+ <ref name="CommonAtt"/>
244
+ <ref name="DefEncAtt"/>
245
+ <optional>
246
+ <ref name="cd"/>
247
+ </optional>
248
+ <optional>
249
+ <ref name="name"/>
250
+ </optional>
251
+ </define>
252
+ <define name="length">
253
+ <data type="string">
254
+ <param name="pattern">\s*((-?[0-9]*([0-9]\.?|\.[0-9])[0-9]*(e[mx]|in|cm|mm|p[xtc]|%)?)|(negative)?((very){0,2}thi(n|ck)|medium)mathspace)\s*</param>
255
+ </data>
256
+ </define>
257
+ </grammar>