metanorma-iso 2.5.2 → 2.5.4

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.
@@ -0,0 +1,233 @@
1
+ module IsoDoc
2
+ module Iso
3
+ class WordDISConvert < WordConvert
4
+ STYLESMAP = {
5
+ AltTerms: "AdmittedTerm",
6
+ TableFootnote: "Tablefootnote",
7
+ formula: "Formula",
8
+ note: "Note",
9
+ example: "Example",
10
+ admonition: "Admonition",
11
+ admonitiontitle: "AdmonitionTitle",
12
+ sourcetitle: "SourceTitle",
13
+ TableTitle: "Tabletitle",
14
+ titlepagesbhead: "TablePageSubhead",
15
+ NormRef: "RefNorm",
16
+ Biblio: "BiblioEntry",
17
+ MsoNormal: "MsoBodyText",
18
+ FigureTitle: "Figuretitle",
19
+ zzwarning: "zzWarning",
20
+ zzwarninghdr: "zzWarningHdr",
21
+ quoteattribution: "QuoteAttribution",
22
+ Sourcecode: "Code",
23
+ zzSTDTitle1: "zzSTDTitle",
24
+ zzSTDTitle2: "zzSTDTitle",
25
+ zzCopyright1: "zzCopyright",
26
+ }.freeze
27
+
28
+ def new_styles(docxml)
29
+ STYLESMAP.each do |k, v|
30
+ docxml.xpath("//*[@class = '#{k}']").each { |s| s["class"] = v }
31
+ end
32
+ docxml.xpath("//h1[@class = 'ForewordTitle' or @class = 'IntroTitle']")
33
+ .each { |h| h.name = "p" }
34
+ dis_styles1(docxml)
35
+ docxml.xpath("//p[not(@class)]").each { |p| p["class"] = "MsoBodyText" }
36
+ stripbgcolor(docxml)
37
+ end
38
+
39
+ def sourcecode_style
40
+ "Code"
41
+ end
42
+
43
+ def dis_styles1(docxml)
44
+ amd_style(docxml)
45
+ middle_title_style(docxml)
46
+ code_style(docxml)
47
+ figure_style(docxml)
48
+ formula_style(docxml)
49
+ note_style(docxml)
50
+ example_style(docxml)
51
+ dis_style_interactions(docxml)
52
+ quote_style(docxml)
53
+ smaller_code_style(docxml)
54
+ end
55
+
56
+ def middle_title_style(docxml)
57
+ docxml.xpath("//p[@class = 'zzSTDTitle2']").each do |p|
58
+ p1 = p.previous_element && p1.name == p &&
59
+ p1["class"] = "zzSTDTitle2" or next
60
+ p1 << " #{p.remove.children.to_xml}"
61
+ end
62
+ end
63
+
64
+ def dis_style_interactions(docxml)
65
+ docxml.xpath("//p[@class = 'Code' or @class = 'Code-' or " \
66
+ "@class = 'Code--']" \
67
+ "[following::p[@class = 'Examplecontinued']]").each do |p|
68
+ p["style"] ||= ""
69
+ p["style"] = "margin-bottom:12pt;#{p['style']}"
70
+ end
71
+ end
72
+
73
+ def amd_style(docxml)
74
+ @meta.get[:doctype] == "Amendment" or return
75
+ docxml.xpath("//div[@class = 'WordSection3']//h1").each do |h|
76
+ h.name = "p"
77
+ h["style"] = "font-style:italic;page-break-after:avoid;"
78
+ end
79
+ end
80
+
81
+ def para_style_change(div, class1, class2)
82
+ s = class1 ? "@class = '#{class1}'" : "not(@class)"
83
+ div.xpath(".//p[#{s}]").each do |p|
84
+ p["class"] = class2
85
+ end
86
+ end
87
+
88
+ def quote_style1(div)
89
+ para_style_change(div, nil, "BodyTextindent1")
90
+ para_style_change(div, "Code-", "Code--")
91
+ para_style_change(div, "Code", "Code-")
92
+ if div["class"] != "Example"
93
+ para_style_change(div, "Example", "Exampleindent")
94
+ para_style_change(div, "Examplecontinued", "Exampleindentcontinued")
95
+ end
96
+ if div["class"] != "Note"
97
+ para_style_change(div, "Note", "Noteindent")
98
+ para_style_change(div, "Notecontinued", "Noteindentcontinued")
99
+ end
100
+ div.xpath(".//table[@class = 'dl']").each do |t|
101
+ t["style"] = "margin-left: 1cm;"
102
+ end
103
+ end
104
+
105
+ def note_style(docxml)
106
+ remove_note_label(docxml)
107
+ note_continued_style(docxml)
108
+ end
109
+
110
+ def example_style(docxml)
111
+ example_continued_style(docxml)
112
+ end
113
+
114
+ def example_continued_style(docxml)
115
+ docxml.xpath("//div[@class = 'Example']").each do |d|
116
+ d.xpath("./p").each_with_index do |p, i|
117
+ p["class"] && p["class"] != "Example" and next
118
+ p["class"] = (i.zero? ? "Example" : "Examplecontinued")
119
+ end
120
+ end
121
+ end
122
+
123
+ def note_continued_style(docxml)
124
+ docxml.xpath("//div[@class = 'Note']").each do |d|
125
+ d.xpath("./p").each_with_index do |p, i|
126
+ p["class"] && p["class"] != "Note" and next
127
+ p["class"] = (i.zero? ? "Note" : "Notecontinued")
128
+ end
129
+ end
130
+ end
131
+
132
+ FIGURE_NESTED_STYLES =
133
+ { Note: "Figurenote", example: "Figureexample" }.freeze
134
+
135
+ def figure_style(docxml)
136
+ docxml.xpath("//div[@class = 'figure']").each do |f|
137
+ FIGURE_NESTED_STYLES.each do |k, v|
138
+ f.xpath(".//*[@class = '#{k}']").each { |n| n["class"] = v }
139
+ end
140
+ f.xpath("./img").each do |i|
141
+ i.replace("<p class='FigureGraphic'>#{i.to_xml}</p>")
142
+ end
143
+ end
144
+ end
145
+
146
+ def formula_style(docxml)
147
+ docxml.xpath("//div[@class = 'Formula']").each do |f|
148
+ f.xpath(".//p[not(@class)]").each do |p|
149
+ p["class"] = "Formula"
150
+ end
151
+ end
152
+ end
153
+
154
+ def code_style(doc)
155
+ span_style((doc.xpath("//tt//b") - doc.xpath("//tt//i//b")),
156
+ "ISOCodebold")
157
+ span_style((doc.xpath("//tt//i") - doc.xpath("//tt//b//i")),
158
+ "ISOCodeitalic")
159
+ span_style((doc.xpath("//b//tt") - doc.xpath("//b//i//tt")),
160
+ "ISOCodebold")
161
+ span_style((doc.xpath("//i//tt") - doc.xpath("//i//b//tt")),
162
+ "ISOCodeitalic")
163
+ span_style(doc.xpath("//tt"), "ISOCode")
164
+ end
165
+
166
+ def span_style(xpath, style)
167
+ xpath.each do |elem|
168
+ elem.name = "span"
169
+ elem["class"] = style
170
+ end
171
+ end
172
+
173
+ def smaller_code_style(doc)
174
+ smaller_code_style_names(doc)
175
+ smaller_code_style_names2spans(doc)
176
+ end
177
+
178
+ # TODO read $smallerfonsize from CSS definitions
179
+ SMALL_FONT_CLASSES =
180
+ %w(pseudocode Note tablefootnote figdl MsoISOTable MsoTableGrid
181
+ TableISO Example Notecontinued Noteindent Noteindentcontinued
182
+ ListNumber5- ListContinue5- BodyTextIndent22 BodyTextIndent32
183
+ Exampleindent2 Exampleindent2continued Noteindent2continued
184
+ Noteindent2 example_label note_label Tablebody MsoNormalTable).freeze
185
+
186
+ INLINE_CODE_CLASSES = %w(ISOCodebold ISOCodeitalic ISOCode).freeze
187
+
188
+ def smaller_code_style_names(doc)
189
+ klass = SMALL_FONT_CLASSES.map { |x| "@class = '#{x}'" }.join(" or ")
190
+ doc.xpath("//*[#{klass}]") - doc.xpath("//*[#{klass}]//*[#{klass}]")
191
+ .each do |d|
192
+ INLINE_CODE_CLASSES.each do |n|
193
+ d.xpath(".//span[@class = '#{n}']").each do |s|
194
+ s["class"] += "-"
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ def smaller_code_style_names2spans(doc)
201
+ INLINE_CODE_CLASSES.each do |n|
202
+ doc.xpath("//span[@class = '#{n}-']").each do |s|
203
+ s["class"] = n
204
+ s.children =
205
+ "<span style='font-size: 9pt;'>#{s.children.to_xml}</span>"
206
+ end
207
+ end
208
+ end
209
+
210
+ def word_annex_cleanup1(docxml, lvl)
211
+ docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
212
+ h2.name = "p"
213
+ h2["class"] = "a#{lvl}"
214
+ end
215
+ end
216
+
217
+ def word_table_cell_para_style(cell)
218
+ ret = cell["header"] == "true" ? "Tableheader" : "Tablebody"
219
+ cell["class"] == "rouge-code" and ret = "Code"
220
+ ret
221
+ end
222
+
223
+ def table_toc_class
224
+ ["Table title", "Tabletitle", "Annex Table Title", "AnnexTableTitle"] +
225
+ super
226
+ end
227
+
228
+ def figure_toc_class
229
+ ["Figure Title", "Annex Figure Title", "AnnexFigureTitle"] + super
230
+ end
231
+ end
232
+ end
233
+ end
@@ -7,10 +7,9 @@ module IsoDoc
7
7
  clause.at(ns("./clause")) and
8
8
  @anchors[clause["id"]] = { label: nil, level: 1, type: "clause",
9
9
  xref: clause.at(ns("./title"))&.text }
10
- i = Counter.new
10
+ i = Counter.new(0, prefix: "0.")
11
11
  clause.xpath(ns("./clause")).each do |c|
12
- i.increment(c)
13
- section_names1(c, "0.#{i.print}", 2)
12
+ section_names1(c, i.increment(c).print, 2)
14
13
  end
15
14
  end
16
15
 
@@ -27,10 +26,9 @@ module IsoDoc
27
26
  anchor_struct(i.print, nil, @labels["appendix"],
28
27
  "clause").merge(level: 2, subtype: "annex",
29
28
  container: clause["id"])
30
- j = Counter.new
29
+ j = Counter.new(0, prefix: "#{i.print}.")
31
30
  c.xpath(ns("./clause | ./references")).each do |c1|
32
- j.increment(c1)
33
- lbl = "#{@labels['appendix']} #{i.print}.#{j.print}"
31
+ lbl = "#{@labels['appendix']} #{j.increment(c1).print}"
34
32
  appendix_names1(c1, l10n(lbl), 3, clause["id"])
35
33
  end
36
34
  end
@@ -41,32 +39,29 @@ module IsoDoc
41
39
  def section_names1(clause, num, level)
42
40
  @anchors[clause["id"]] =
43
41
  { label: num, level: level, xref: num, subtype: "clause" }
44
- i = Counter.new
42
+ i = Counter.new(0, prefix: "#{num}.")
45
43
  clause.xpath(ns("./clause | ./terms | ./term | ./definitions | " \
46
44
  "./references"))
47
45
  .each do |c|
48
- i.increment(c)
49
- section_names1(c, "#{num}.#{i.print}", level + 1)
46
+ section_names1(c, i.increment(c).print, level + 1)
50
47
  end
51
48
  end
52
49
 
53
50
  def annex_names1(clause, num, level)
54
51
  @anchors[clause["id"]] = { label: num, xref: num, level: level,
55
52
  subtype: "annex" }
56
- i = Counter.new
53
+ i = Counter.new(0, prefix: "#{num}.")
57
54
  clause.xpath(ns("./clause | ./references")).each do |c|
58
- i.increment(c)
59
- annex_names1(c, "#{num}.#{i.print}", level + 1)
55
+ annex_names1(c, i.increment(c).print, level + 1)
60
56
  end
61
57
  end
62
58
 
63
59
  def appendix_names1(clause, num, level, container)
64
60
  @anchors[clause["id"]] = { label: num, xref: num, level: level,
65
61
  container: container }
66
- i = Counter.new
62
+ i = Counter.new(0, prefix: "#{num}.")
67
63
  clause.xpath(ns("./clause | ./references")).each do |c|
68
- i.increment(c)
69
- appendix_names1(c, "#{num}.#{i.print}", level + 1, container)
64
+ appendix_names1(c, i.increment(c).print, level + 1, container)
70
65
  end
71
66
  end
72
67
 
@@ -5,6 +5,7 @@ require "pathname"
5
5
  require "open-uri"
6
6
  require "isodoc"
7
7
  require "fileutils"
8
+ require_relative "processor"
8
9
 
9
10
  module Metanorma
10
11
  module ISO
@@ -47,7 +48,9 @@ module Metanorma
47
48
  end
48
49
 
49
50
  def presentation_xml_converter(node)
50
- IsoDoc::Iso::PresentationXMLConvert.new(html_extract_attributes(node))
51
+ IsoDoc::Iso::PresentationXMLConvert
52
+ .new(html_extract_attributes(node)
53
+ .merge(output_formats: ::Metanorma::Iso::Processor.new.output_formats))
51
54
  end
52
55
 
53
56
  def init(node)
@@ -346,6 +346,8 @@
346
346
  <ref name="keyword"/>
347
347
  <ref name="xref"/>
348
348
  <ref name="hyperlink"/>
349
+ <ref name="index"/>
350
+ <ref name="index-xref"/>
349
351
  </choice>
350
352
  </oneOrMore>
351
353
  </element>
@@ -623,6 +625,8 @@
623
625
  <ref name="eref"/>
624
626
  <ref name="xref"/>
625
627
  <ref name="hyperlink"/>
628
+ <ref name="index"/>
629
+ <ref name="index-xref"/>
626
630
  </choice>
627
631
  </zeroOrMore>
628
632
  </element>
@@ -636,6 +640,8 @@
636
640
  <ref name="eref"/>
637
641
  <ref name="xref"/>
638
642
  <ref name="hyperlink"/>
643
+ <ref name="index"/>
644
+ <ref name="index-xref"/>
639
645
  </choice>
640
646
  </zeroOrMore>
641
647
  </element>
@@ -648,6 +654,8 @@
648
654
  <ref name="eref"/>
649
655
  <ref name="xref"/>
650
656
  <ref name="hyperlink"/>
657
+ <ref name="index"/>
658
+ <ref name="index-xref"/>
651
659
  </choice>
652
660
  </zeroOrMore>
653
661
  </element>
@@ -655,7 +663,11 @@
655
663
  <define name="keyword">
656
664
  <element name="keyword">
657
665
  <zeroOrMore>
658
- <ref name="PureTextElement"/>
666
+ <choice>
667
+ <ref name="PureTextElement"/>
668
+ <ref name="index"/>
669
+ <ref name="index-xref"/>
670
+ </choice>
659
671
  </zeroOrMore>
660
672
  </element>
661
673
  </define>
@@ -676,7 +688,11 @@
676
688
  <define name="strike">
677
689
  <element name="strike">
678
690
  <zeroOrMore>
679
- <ref name="PureTextElement"/>
691
+ <choice>
692
+ <ref name="PureTextElement"/>
693
+ <ref name="index"/>
694
+ <ref name="index-xref"/>
695
+ </choice>
680
696
  </zeroOrMore>
681
697
  </element>
682
698
  </define>
@@ -898,44 +914,47 @@
898
914
  -->
899
915
  <define name="image">
900
916
  <element name="image">
901
- <attribute name="id">
902
- <data type="ID"/>
917
+ <ref name="Image"/>
918
+ </element>
919
+ </define>
920
+ <define name="Image">
921
+ <attribute name="id">
922
+ <data type="ID"/>
923
+ </attribute>
924
+ <attribute name="src">
925
+ <data type="anyURI"/>
926
+ </attribute>
927
+ <attribute name="mimetype"/>
928
+ <optional>
929
+ <attribute name="filename"/>
930
+ </optional>
931
+ <optional>
932
+ <attribute name="width">
933
+ <choice>
934
+ <data type="int"/>
935
+ <value>auto</value>
936
+ </choice>
903
937
  </attribute>
904
- <attribute name="src">
938
+ </optional>
939
+ <optional>
940
+ <attribute name="height">
941
+ <choice>
942
+ <data type="int"/>
943
+ <value>auto</value>
944
+ </choice>
945
+ </attribute>
946
+ </optional>
947
+ <optional>
948
+ <attribute name="alt"/>
949
+ </optional>
950
+ <optional>
951
+ <attribute name="title"/>
952
+ </optional>
953
+ <optional>
954
+ <attribute name="longdesc">
905
955
  <data type="anyURI"/>
906
956
  </attribute>
907
- <attribute name="mimetype"/>
908
- <optional>
909
- <attribute name="filename"/>
910
- </optional>
911
- <optional>
912
- <attribute name="width">
913
- <choice>
914
- <data type="int"/>
915
- <value>auto</value>
916
- </choice>
917
- </attribute>
918
- </optional>
919
- <optional>
920
- <attribute name="height">
921
- <choice>
922
- <data type="int"/>
923
- <value>auto</value>
924
- </choice>
925
- </attribute>
926
- </optional>
927
- <optional>
928
- <attribute name="alt"/>
929
- </optional>
930
- <optional>
931
- <attribute name="title"/>
932
- </optional>
933
- <optional>
934
- <attribute name="longdesc">
935
- <data type="anyURI"/>
936
- </attribute>
937
- </optional>
938
- </element>
957
+ </optional>
939
958
  </define>
940
959
  <define name="video">
941
960
  <element name="video">
@@ -348,6 +348,9 @@
348
348
  <zeroOrMore>
349
349
  <ref name="contact"/>
350
350
  </zeroOrMore>
351
+ <optional>
352
+ <ref name="logo"/>
353
+ </optional>
351
354
  </element>
352
355
  </define>
353
356
  <define name="orgname">
@@ -366,6 +369,11 @@
366
369
  </choice>
367
370
  </element>
368
371
  </define>
372
+ <define name="logo">
373
+ <element name="logo">
374
+ <ref name="image"/>
375
+ </element>
376
+ </define>
369
377
  <define name="NameWithVariants">
370
378
  <element name="primary">
371
379
  <ref name="LocalizedString"/>
@@ -942,6 +950,7 @@
942
950
  <value>obsoleted</value>
943
951
  <value>confirmed</value>
944
952
  <value>updated</value>
953
+ <value>corrected</value>
945
954
  <value>issued</value>
946
955
  <value>transmitted</value>
947
956
  <value>copied</value>
@@ -1283,7 +1292,7 @@
1283
1292
  <value>mergedInto</value>
1284
1293
  <value>splits</value>
1285
1294
  <value>splitInto</value>
1286
- <value>instance</value>
1295
+ <value>instanceOf</value>
1287
1296
  <value>hasInstance</value>
1288
1297
  <value>exemplarOf</value>
1289
1298
  <value>hasExemplar</value>
@@ -1,6 +1,3 @@
1
- require "date"
2
- require "htmlentities"
3
-
4
1
  module Metanorma
5
2
  module ISO
6
3
  class Converter < Standoc::Converter
@@ -37,7 +34,6 @@ module Metanorma
37
34
  xmldoc.xpath("//bibdata/contributor[role/@type = 'publisher']" \
38
35
  "/organization").each_with_object([]) do |x, prefix|
39
36
  x1 = x.at("abbreviation")&.text || x.at("name")&.text
40
- # (x1 == "ISO" and prefix.unshift("ISO")) or prefix << x1
41
37
  prefix << x1
42
38
  end
43
39
  end
@@ -76,9 +72,7 @@ module Metanorma
76
72
  end
77
73
 
78
74
  def sort_biblio(bib)
79
- bib.sort do |a, b|
80
- sort_biblio_key(a) <=> sort_biblio_key(b)
81
- end
75
+ bib.sort { |a, b| sort_biblio_key(a) <=> sort_biblio_key(b) }
82
76
  end
83
77
 
84
78
  # sort by: doc class (ISO, IEC, other standard (not DOI &c), other
@@ -90,15 +84,15 @@ module Metanorma
90
84
  # then title
91
85
  def sort_biblio_key(bib)
92
86
  pubclass = pub_class(bib)
93
- num = bib&.at("./docnumber")&.text
94
- id = bib&.at("./docidentifier[@primary]") ||
95
- bib&.at("./docidentifier[not(#{skip_docid} or @type = 'metanorma')]")
96
- metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text
87
+ num = bib.at("./docnumber")&.text
88
+ id = bib.at("./docidentifier[@primary]") ||
89
+ bib.at("./docidentifier[not(#{skip_docid} or @type = 'metanorma')]")
90
+ metaid = bib.at("./docidentifier[@type = 'metanorma']")&.text
97
91
  abbrid = metaid unless /^\[\d+\]$/.match?(metaid)
98
92
  /\d-(?<partid>\d+)/ =~ id&.text
99
93
  type = id["type"] if id
100
- title = bib&.at("./title[@type = 'main']")&.text ||
101
- bib&.at("./title")&.text || bib&.at("./formattedref")&.text
94
+ title = bib.at("./title[@type = 'main']")&.text ||
95
+ bib.at("./title")&.text || bib&.at("./formattedref")&.text
102
96
  "#{pubclass} :: #{type} :: " \
103
97
  "#{num.nil? ? abbrid : sprintf('%09d', num.to_i)} :: " \
104
98
  "#{sprintf('%09d', partid.to_i)} :: #{id&.text} :: #{title}"
@@ -241,6 +235,14 @@ module Metanorma
241
235
  end
242
236
  end
243
237
  end
238
+
239
+ def termdef_boilerplate_insert_location(xmldoc)
240
+ f = xmldoc.at(self.class::TERM_CLAUSE)
241
+ root = xmldoc.at("//sections/terms | //sections/clause[.//terms]")
242
+ !f || !root and return f || root
243
+ f.at("./preceding-sibling::clause") and return root
244
+ f
245
+ end
244
246
  end
245
247
  end
246
248
  end
@@ -84,7 +84,8 @@ module Metanorma
84
84
  end
85
85
 
86
86
  def iso_id_year(node)
87
- node.attr("copyright-year") || node.attr("updated-date")
87
+ (node.attr("copyright-year") || node.attr("updated-date") ||
88
+ node.attr("published-date"))
88
89
  &.sub(/-.*$/, "") || Date.today.year
89
90
  end
90
91