metanorma-itu 2.4.3 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -9284,16 +9284,44 @@
9284
9284
  </xsl:choose>
9285
9285
 
9286
9286
  <xsl:attribute name="content-width">scale-down-to-fit</xsl:attribute>
9287
- <xsl:variable name="svg_width" select="xalan:nodeset($svg_content)/*/@width"/>
9288
- <xsl:variable name="svg_height" select="xalan:nodeset($svg_content)/*/@height"/>
9287
+ <xsl:variable name="svg_width_" select="xalan:nodeset($svg_content)/*/@width"/>
9288
+ <xsl:variable name="svg_width" select="number(translate($svg_width_, 'px', ''))"/>
9289
+ <xsl:variable name="svg_height_" select="xalan:nodeset($svg_content)/*/@height"/>
9290
+ <xsl:variable name="svg_height" select="number(translate($svg_height_, 'px', ''))"/>
9291
+
9292
+ <!-- Example: -->
9289
9293
  <!-- effective height 297 - 27.4 - 13 = 256.6 -->
9290
9294
  <!-- effective width 210 - 12.5 - 25 = 172.5 -->
9291
9295
  <!-- effective height / width = 1.48, 1.4 - with title -->
9292
- <xsl:if test="$svg_height &gt; ($svg_width * 1.4)"> <!-- for images with big height -->
9296
+
9297
+ <xsl:variable name="scale_x">
9298
+ <xsl:choose>
9299
+ <xsl:when test="$svg_width &gt; $width_effective_px">
9300
+ <xsl:value-of select="$width_effective_px div $svg_width"/>
9301
+ </xsl:when>
9302
+ <xsl:otherwise>1</xsl:otherwise>
9303
+ </xsl:choose>
9304
+ </xsl:variable>
9305
+ <xsl:variable name="scale_y">
9306
+ <xsl:choose>
9307
+ <xsl:when test="$svg_height * $scale_x &gt; $height_effective_px">
9308
+ <xsl:value-of select="$height_effective_px div ($svg_height * $scale_x)"/>
9309
+ </xsl:when>
9310
+ <xsl:otherwise>1</xsl:otherwise>
9311
+ </xsl:choose>
9312
+ </xsl:variable>
9313
+
9314
+ <!-- for images with big height -->
9315
+ <!-- <xsl:if test="$svg_height &gt; ($svg_width * 1.4)">
9293
9316
  <xsl:variable name="width" select="(($svg_width * 1.4) div $svg_height) * 100"/>
9294
9317
  <xsl:attribute name="width"><xsl:value-of select="$width"/>%</xsl:attribute>
9295
- </xsl:if>
9318
+ </xsl:if> -->
9296
9319
  <xsl:attribute name="scaling">uniform</xsl:attribute>
9320
+
9321
+ <xsl:if test="$scale_y != 1">
9322
+ <xsl:attribute name="content-height"><xsl:value-of select="round($scale_x * $scale_y * 100)"/>%</xsl:attribute>
9323
+ </xsl:if>
9324
+
9297
9325
  <xsl:copy-of select="$svg_content"/>
9298
9326
  </fo:instream-foreign-object>
9299
9327
  <!-- </fo:block> -->
@@ -11452,7 +11480,9 @@
11452
11480
  </xsl:template> <!-- sections_element_style -->
11453
11481
 
11454
11482
  <xsl:template match="//*[contains(local-name(), '-standard')]/*[local-name() = 'preface']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
11455
- <fo:block break-after="page"/>
11483
+
11484
+ <fo:block break-after="page"/>
11485
+
11456
11486
  <fo:block>
11457
11487
  <xsl:call-template name="setId"/>
11458
11488
  <xsl:apply-templates/>
@@ -11523,7 +11553,7 @@
11523
11553
  <xsl:when test="ancestor::*[contains(local-name(), '-standard')] and not(ancestor::*[contains(local-name(), '-standard')]//*[@id = $id_from])">
11524
11554
  <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
11525
11555
  </xsl:when>
11526
- <xsl:when test="not(//*[@id = $id_from]) and not(preceding-sibling::*[@id = $id_from])">
11556
+ <xsl:when test="not(/*[@id = $id_from]) and not(/*//*[@id = $id_from]) and not(preceding-sibling::*[@id = $id_from])">
11527
11557
  <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
11528
11558
  </xsl:when>
11529
11559
  </xsl:choose>
@@ -9284,16 +9284,44 @@
9284
9284
  </xsl:choose>
9285
9285
 
9286
9286
  <xsl:attribute name="content-width">scale-down-to-fit</xsl:attribute>
9287
- <xsl:variable name="svg_width" select="xalan:nodeset($svg_content)/*/@width"/>
9288
- <xsl:variable name="svg_height" select="xalan:nodeset($svg_content)/*/@height"/>
9287
+ <xsl:variable name="svg_width_" select="xalan:nodeset($svg_content)/*/@width"/>
9288
+ <xsl:variable name="svg_width" select="number(translate($svg_width_, 'px', ''))"/>
9289
+ <xsl:variable name="svg_height_" select="xalan:nodeset($svg_content)/*/@height"/>
9290
+ <xsl:variable name="svg_height" select="number(translate($svg_height_, 'px', ''))"/>
9291
+
9292
+ <!-- Example: -->
9289
9293
  <!-- effective height 297 - 27.4 - 13 = 256.6 -->
9290
9294
  <!-- effective width 210 - 12.5 - 25 = 172.5 -->
9291
9295
  <!-- effective height / width = 1.48, 1.4 - with title -->
9292
- <xsl:if test="$svg_height &gt; ($svg_width * 1.4)"> <!-- for images with big height -->
9296
+
9297
+ <xsl:variable name="scale_x">
9298
+ <xsl:choose>
9299
+ <xsl:when test="$svg_width &gt; $width_effective_px">
9300
+ <xsl:value-of select="$width_effective_px div $svg_width"/>
9301
+ </xsl:when>
9302
+ <xsl:otherwise>1</xsl:otherwise>
9303
+ </xsl:choose>
9304
+ </xsl:variable>
9305
+ <xsl:variable name="scale_y">
9306
+ <xsl:choose>
9307
+ <xsl:when test="$svg_height * $scale_x &gt; $height_effective_px">
9308
+ <xsl:value-of select="$height_effective_px div ($svg_height * $scale_x)"/>
9309
+ </xsl:when>
9310
+ <xsl:otherwise>1</xsl:otherwise>
9311
+ </xsl:choose>
9312
+ </xsl:variable>
9313
+
9314
+ <!-- for images with big height -->
9315
+ <!-- <xsl:if test="$svg_height &gt; ($svg_width * 1.4)">
9293
9316
  <xsl:variable name="width" select="(($svg_width * 1.4) div $svg_height) * 100"/>
9294
9317
  <xsl:attribute name="width"><xsl:value-of select="$width"/>%</xsl:attribute>
9295
- </xsl:if>
9318
+ </xsl:if> -->
9296
9319
  <xsl:attribute name="scaling">uniform</xsl:attribute>
9320
+
9321
+ <xsl:if test="$scale_y != 1">
9322
+ <xsl:attribute name="content-height"><xsl:value-of select="round($scale_x * $scale_y * 100)"/>%</xsl:attribute>
9323
+ </xsl:if>
9324
+
9297
9325
  <xsl:copy-of select="$svg_content"/>
9298
9326
  </fo:instream-foreign-object>
9299
9327
  <!-- </fo:block> -->
@@ -11452,7 +11480,9 @@
11452
11480
  </xsl:template> <!-- sections_element_style -->
11453
11481
 
11454
11482
  <xsl:template match="//*[contains(local-name(), '-standard')]/*[local-name() = 'preface']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
11455
- <fo:block break-after="page"/>
11483
+
11484
+ <fo:block break-after="page"/>
11485
+
11456
11486
  <fo:block>
11457
11487
  <xsl:call-template name="setId"/>
11458
11488
  <xsl:apply-templates/>
@@ -11523,7 +11553,7 @@
11523
11553
  <xsl:when test="ancestor::*[contains(local-name(), '-standard')] and not(ancestor::*[contains(local-name(), '-standard')]//*[@id = $id_from])">
11524
11554
  <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
11525
11555
  </xsl:when>
11526
- <xsl:when test="not(//*[@id = $id_from]) and not(preceding-sibling::*[@id = $id_from])">
11556
+ <xsl:when test="not(/*[@id = $id_from]) and not(/*//*[@id = $id_from]) and not(preceding-sibling::*[@id = $id_from])">
11527
11557
  <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
11528
11558
  </xsl:when>
11529
11559
  </xsl:choose>
@@ -31,6 +31,8 @@ module IsoDoc
31
31
  series1: "//bibdata/series[@type='secondary']/title",
32
32
  series2: "//bibdata/series[@type='tertiary']/title",
33
33
  annextitle: "//bibdata/title[@type='annex']",
34
+ collectiontitle: "//bibdata/title[@type='collection']",
35
+ slogantitle: "//bibdata/title[@type='slogan']",
34
36
  positiontitle: "//bibdata/title[@type='position-sp']" }.each do |k, v|
35
37
  titleset(isoxml, k, v)
36
38
  end
@@ -51,6 +53,8 @@ module IsoDoc
51
53
  end
52
54
 
53
55
  def author(xml, _out)
56
+ sector = xml.at(ns("//bibdata/ext/editorialgroup/sector"))
57
+ set(:sector, sector.text) if sector
54
58
  bureau = xml.at(ns("//bibdata/ext/editorialgroup/bureau"))
55
59
  set(:bureau, bureau.text) if bureau
56
60
  tc = xml.at(ns("//bibdata/ext/editorialgroup/committee"))
@@ -24,29 +24,34 @@ module IsoDoc
24
24
  end
25
25
 
26
26
  def multi_bibitem_ref_code(bib)
27
- skip = IsoDoc::Function::References::SKIP_DOCID
28
- skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'"
29
- prim = "[@primary = 'true']"
30
- id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]"))
31
- id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]"))
32
- id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]"))
33
- id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]"))
34
- id.empty? and return id
35
- id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
27
+ id = pref_ref_code_parse(bib)
28
+ id.nil? and return []
29
+ id.sort_by { |i| /^ITU/.match?(i) ? 0 : 1 }
36
30
  end
37
31
 
38
- def render_multi_identifiers(ids)
32
+ def render_multi_identifiers(ids, bib)
39
33
  ids.map do |id|
40
- if id["type"] == "ITU" then doctype_title(id)
34
+ if /^ITU/.match?(id) then doctype_title(id, bib)
41
35
  else
42
- docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
36
+ id.sub(/^\[/, "").sub(/\]$/, "")
43
37
  end
44
38
  end.join("&#xA0;| ")
45
39
  end
46
40
 
41
+ def doctype_title(id, bib)
42
+ type = bib.at(ns("./ext/doctype"))&.text || "recommendation"
43
+ if type == "recommendation" &&
44
+ /^(?<prefix>ITU-[A-Z][  ][A-Z])[  .-]Sup[a-z]*\.[  ]?(?<num>\d+)$/ =~ id
45
+ "#{prefix}-series Recommendations – Supplement #{num}"
46
+ else
47
+ d = id.sub(/^\[/, "").sub(/\]$/, "")
48
+ "#{titlecase(type)} #{d}"
49
+ end
50
+ end
51
+
47
52
  def reference_format_start(bib)
48
53
  id = multi_bibitem_ref_code(bib)
49
- id1 = render_multi_identifiers(id)
54
+ id1 = render_multi_identifiers(id, bib)
50
55
  out = id1
51
56
  date = bib.at(ns("./date[@type = 'published']/on | " \
52
57
  "./date[@type = 'published']/from")) and
@@ -87,17 +87,6 @@ module IsoDoc
87
87
  str.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
88
88
  end
89
89
 
90
- def doctype_title(id)
91
- type = id.parent&.at(ns("./ext/doctype"))&.text || "recommendation"
92
- if type == "recommendation" &&
93
- /^(?<prefix>ITU-[A-Z][  ][A-Z])[  .-]Sup[a-z]*\.[  ]?(?<num>\d+)$/ =~ id.text
94
- "#{prefix}-series Recommendations – Supplement #{num}"
95
- else
96
- d = docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
97
- "#{titlecase(type)} #{d}"
98
- end
99
- end
100
-
101
90
  def twitter_cldr_localiser_symbols
102
91
  { group: "'" }
103
92
  end
@@ -1,21 +1,8 @@
1
+ require_relative "cleanup_section"
2
+
1
3
  module Metanorma
2
4
  module ITU
3
5
  class Converter < Standoc::Converter
4
- def sections_cleanup(xml)
5
- super
6
- insert_missing_sections(xml) unless @no_insert_missing_sections
7
- insert_empty_clauses(xml)
8
- resolution_inline_header(xml)
9
- end
10
-
11
- def resolution_inline_header(xml)
12
- @doctype == "resolution" or return
13
- xml.xpath("//clause//clause").each do |c|
14
- (title = c.at("./title")) && !title.text&.empty? and next
15
- c["inline-header"] = true
16
- end
17
- end
18
-
19
6
  def table_cleanup(xmldoc)
20
7
  super
21
8
  xmldoc.xpath("//thead/tr[1]/th | //thead/tr[1]/td").each do |t|
@@ -31,84 +18,6 @@ module Metanorma
31
18
  end
32
19
  end
33
20
 
34
- def insert_missing_sections(xml)
35
- xml.at("//metanorma-extension/semantic-metadata/" \
36
- "headless[text() = 'true']") and return nil
37
- insert_scope(xml)
38
- insert_norm_ref(xml)
39
- insert_terms(xml)
40
- insert_symbols(xml)
41
- insert_conventions(xml)
42
- end
43
-
44
- def add_id
45
- %(id="_#{UUIDTools::UUID.random_create}")
46
- end
47
-
48
- def insert_scope(xml)
49
- xml.at("./*/sections") or
50
- xml.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
51
- "<sections><sentinel/></sections>"
52
- xml.at("./*/sections/*") or xml.at("./*/sections") << "<sentinel/>"
53
- ins = xml.at("//sections").elements.first
54
- xml.at("//sections/clause[@type = 'scope']") or
55
- ins.previous =
56
- "<clause type='scope' #{add_id}><title>#{@i18n.scope}</title><p>" \
57
- "#{@i18n.clause_empty}</p></clause>"
58
- xml.at("//sentinel")&.remove
59
- end
60
-
61
- def insert_norm_ref(xml)
62
- xml.at("//bibliography") or
63
- xml.at("./*/annex[last()] | ./*/sections").next =
64
- "<bibliography><sentinel/></bibliography>"
65
- ins = xml.at("//bibliography").elements.first
66
- xml.at("//bibliography/references[@normative = 'true']") or
67
- ins.previous = "<references #{add_id} normative='true'>" \
68
- "<title>#{@i18n.normref}</title></references>"
69
- xml.at("//sentinel")&.remove
70
- end
71
-
72
- def insert_terms(xml)
73
- ins = xml.at("//sections/clause[@type = 'scope']")
74
- xml.at("//sections//terms") or
75
- ins.next = "<terms #{add_id}><title>#{@i18n.termsdef}</title></terms>"
76
- end
77
-
78
- def insert_symbols(xml)
79
- ins = xml.at("//sections/terms") ||
80
- xml.at("//sections/clause[descendant::terms]")
81
- unless xml.at("//sections//definitions")
82
- ins.next = "<definitions #{add_id}>" \
83
- "<title>#{@i18n.symbolsabbrev}</title></definitions>"
84
- end
85
- end
86
-
87
- def insert_conventions(xml)
88
- ins = xml.at("//sections//definitions") ||
89
- xml.at("//sections/clause[descendant::definitions]")
90
- unless xml.at("//sections/clause[@type = 'conventions']")
91
- ins.next = "<clause #{add_id} type='conventions'>" \
92
- "<title>#{@i18n.conventions}</title><p>" \
93
- "#{@i18n.clause_empty}</p></clause>"
94
- end
95
- end
96
-
97
- def insert_empty_clauses(xml)
98
- xml.xpath("//terms[not(./term)][not(.//terms)]").each do |c|
99
- insert_empty_clauses1(c, @i18n.clause_empty)
100
- end
101
- xml.xpath("//definitions[not(./dl)]").each do |c|
102
- insert_empty_clauses1(c, @i18n.clause_empty)
103
- end
104
- end
105
-
106
- def insert_empty_clauses1(clause, text)
107
- clause.at("./p") and return
108
- ins = clause.at("./title") or return
109
- ins.next = "<p>#{text}</p>"
110
- end
111
-
112
21
  def cleanup(xmldoc)
113
22
  symbols_cleanup(xmldoc)
114
23
  super
@@ -117,11 +26,9 @@ module Metanorma
117
26
  end
118
27
 
119
28
  def smartquotes_cleanup(xmldoc)
120
- return super if @smartquotes
121
-
29
+ @smartquotes and return super
122
30
  xmldoc.traverse do |n|
123
- next unless n.text?
124
-
31
+ n.text? or next
125
32
  n.replace(HTMLEntities.new.encode(
126
33
  n.text.gsub(/\u2019|\u2018|\u201a|\u201b/, "'")
127
34
  .gsub(/\u201c|\u201d|\u201e|\u201f/, '"'), :basic
@@ -130,51 +37,6 @@ module Metanorma
130
37
  xmldoc
131
38
  end
132
39
 
133
- def termdef_boilerplate_cleanup(xmldoc); end
134
-
135
- def terms_extract(div)
136
- internal = div.at("./terms[@type = 'internal']/title")
137
- external = div.at("./terms[@type = 'external']/title")
138
- [internal, external]
139
- end
140
-
141
- def term_defs_boilerplate(div, _source, _term, _preface, _isodoc)
142
- internal, external = terms_extract(div.parent)
143
- internal&.next_element&.name == "term" and
144
- internal.next = "<p>#{@i18n.internal_terms_boilerplate}</p>"
145
- internal and internal&.next_element == nil and
146
- internal.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
147
- external&.next_element&.name == "term" and
148
- external.next = "<p>#{@i18n.external_terms_boilerplate}</p>"
149
- external and external&.next_element == nil and
150
- external.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
151
- !internal and !external and
152
- %w(term terms).include? div&.next_element&.name and
153
- div.next = "<p>#{@i18n.term_def_boilerplate}</p>"
154
- end
155
-
156
- def section_names_terms_cleanup(xml)
157
- super
158
- replace_title(
159
- xml, "//terms[@type = 'internal'] | " \
160
- "//clause[./terms[@type = 'internal']]" \
161
- "[not(./terms[@type = 'external'])]",
162
- @i18n&.internal_termsdef
163
- )
164
- replace_title(
165
- xml, "//terms[@type = 'external'] | " \
166
- "//clause[./terms[@type = 'external']]" \
167
- "[not(./terms[@type = 'internal'])]",
168
- @i18n&.external_termsdef
169
- )
170
- end
171
-
172
- def symbols_cleanup(xmldoc)
173
- sym = xmldoc.at("//definitions/title")
174
- sym and sym&.next_element&.name == "dl" and
175
- sym.next = "<p>#{@i18n.symbols_boilerplate}</p>"
176
- end
177
-
178
40
  PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze
179
41
 
180
42
  def pub_class(bib)
@@ -221,11 +83,20 @@ module Metanorma
221
83
  end
222
84
  end
223
85
 
224
- def sections_names_cleanup(xml)
86
+ def bibdata_cleanup(xmldoc)
225
87
  super
226
- t = xml.at("//preface//abstract") or return
227
- t["id"] == "_summary" and
228
- replace_title(xml, "//preface//abstract", @i18n&.summary)
88
+ coverpage_images(xmldoc)
89
+ end
90
+
91
+ def coverpage_images(xmldoc)
92
+ %w(coverpage-image).each do |n|
93
+ xmldoc.xpath("//bibdata/ext/#{n}").each do |x|
94
+ ins = add_misc_container(xmldoc)
95
+ ins << "<presentation-metadata><name>#{n}</name>" \
96
+ "<value>#{x.remove.children.to_xml}</value>" \
97
+ "</presentation-metadata>"
98
+ end
99
+ end
229
100
  end
230
101
  end
231
102
  end
@@ -0,0 +1,150 @@
1
+ module Metanorma
2
+ module ITU
3
+ class Converter < Standoc::Converter
4
+ def sections_cleanup(xml)
5
+ super
6
+ insert_missing_sections(xml) unless @no_insert_missing_sections
7
+ insert_empty_clauses(xml)
8
+ resolution_inline_header(xml)
9
+ end
10
+
11
+ def resolution_inline_header(xml)
12
+ @doctype == "resolution" or return
13
+ xml.xpath("//clause//clause").each do |c|
14
+ (title = c.at("./title")) && !title.text&.empty? and next
15
+ c["inline-header"] = true
16
+ end
17
+ end
18
+
19
+ def insert_missing_sections(xml)
20
+ xml.at("//metanorma-extension/semantic-metadata/" \
21
+ "headless[text() = 'true']") and return nil
22
+ insert_scope(xml)
23
+ insert_norm_ref(xml)
24
+ insert_terms(xml)
25
+ insert_symbols(xml)
26
+ insert_conventions(xml)
27
+ end
28
+
29
+ def add_id
30
+ %(id="_#{UUIDTools::UUID.random_create}")
31
+ end
32
+
33
+ def insert_scope(xml)
34
+ xml.at("./*/sections") or
35
+ xml.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
36
+ "<sections><sentinel/></sections>"
37
+ xml.at("./*/sections/*") or xml.at("./*/sections") << "<sentinel/>"
38
+ ins = xml.at("//sections").elements.first
39
+ xml.at("//sections/clause[@type = 'scope']") or
40
+ ins.previous =
41
+ "<clause type='scope' #{add_id}><title>#{@i18n.scope}</title><p>" \
42
+ "#{@i18n.clause_empty}</p></clause>"
43
+ xml.at("//sentinel")&.remove
44
+ end
45
+
46
+ def insert_norm_ref(xml)
47
+ xml.at("//bibliography") or
48
+ xml.at("./*/annex[last()] | ./*/sections").next =
49
+ "<bibliography><sentinel/></bibliography>"
50
+ ins = xml.at("//bibliography").elements.first
51
+ xml.at("//bibliography/references[@normative = 'true']") or
52
+ ins.previous = "<references #{add_id} normative='true'>" \
53
+ "<title>#{@i18n.normref}</title></references>"
54
+ xml.at("//sentinel")&.remove
55
+ end
56
+
57
+ def insert_terms(xml)
58
+ ins = xml.at("//sections/clause[@type = 'scope']")
59
+ xml.at("//sections//terms") or
60
+ ins.next = "<terms #{add_id}><title>#{@i18n.termsdef}</title></terms>"
61
+ end
62
+
63
+ def insert_symbols(xml)
64
+ ins = xml.at("//sections/terms") ||
65
+ xml.at("//sections/clause[descendant::terms]")
66
+ unless xml.at("//sections//definitions")
67
+ ins.next = "<definitions #{add_id}>" \
68
+ "<title>#{@i18n.symbolsabbrev}</title></definitions>"
69
+ end
70
+ end
71
+
72
+ def insert_conventions(xml)
73
+ ins = xml.at("//sections//definitions") ||
74
+ xml.at("//sections/clause[descendant::definitions]")
75
+ unless xml.at("//sections/clause[@type = 'conventions']")
76
+ ins.next = "<clause #{add_id} type='conventions'>" \
77
+ "<title>#{@i18n.conventions}</title><p>" \
78
+ "#{@i18n.clause_empty}</p></clause>"
79
+ end
80
+ end
81
+
82
+ def insert_empty_clauses(xml)
83
+ xml.xpath("//terms[not(./term)][not(.//terms)]").each do |c|
84
+ insert_empty_clauses1(c, @i18n.clause_empty)
85
+ end
86
+ xml.xpath("//definitions[not(./dl)]").each do |c|
87
+ insert_empty_clauses1(c, @i18n.clause_empty)
88
+ end
89
+ end
90
+
91
+ def insert_empty_clauses1(clause, text)
92
+ clause.at("./p") and return
93
+ ins = clause.at("./title") or return
94
+ ins.next = "<p>#{text}</p>"
95
+ end
96
+
97
+ def termdef_boilerplate_cleanup(xmldoc); end
98
+
99
+ def terms_extract(div)
100
+ internal = div.at("./terms[@type = 'internal']/title")
101
+ external = div.at("./terms[@type = 'external']/title")
102
+ [internal, external]
103
+ end
104
+
105
+ def term_defs_boilerplate(div, _source, _term, _preface, _isodoc)
106
+ internal, external = terms_extract(div.parent)
107
+ internal&.next_element&.name == "term" and
108
+ internal.next = "<p>#{@i18n.internal_terms_boilerplate}</p>"
109
+ internal and internal&.next_element == nil and
110
+ internal.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
111
+ external&.next_element&.name == "term" and
112
+ external.next = "<p>#{@i18n.external_terms_boilerplate}</p>"
113
+ external and external&.next_element == nil and
114
+ external.next = "<p>#{@i18n.no_terms_boilerplate}</p>"
115
+ !internal and !external and
116
+ %w(term terms).include? div&.next_element&.name and
117
+ div.next = "<p>#{@i18n.term_def_boilerplate}</p>"
118
+ end
119
+
120
+ def section_names_terms_cleanup(xml)
121
+ super
122
+ replace_title(
123
+ xml, "//terms[@type = 'internal'] | " \
124
+ "//clause[./terms[@type = 'internal']]" \
125
+ "[not(./terms[@type = 'external'])]",
126
+ @i18n&.internal_termsdef
127
+ )
128
+ replace_title(
129
+ xml, "//terms[@type = 'external'] | " \
130
+ "//clause[./terms[@type = 'external']]" \
131
+ "[not(./terms[@type = 'internal'])]",
132
+ @i18n&.external_termsdef
133
+ )
134
+ end
135
+
136
+ def symbols_cleanup(xmldoc)
137
+ sym = xmldoc.at("//definitions/title")
138
+ sym and sym&.next_element&.name == "dl" and
139
+ sym.next = "<p>#{@i18n.symbols_boilerplate}</p>"
140
+ end
141
+
142
+ def sections_names_cleanup(xml)
143
+ super
144
+ t = xml.at("//preface//abstract") or return
145
+ t["id"] == "_summary" and
146
+ replace_title(xml, "//preface//abstract", @i18n&.summary)
147
+ end
148
+ end
149
+ end
150
+ end
@@ -127,6 +127,10 @@ module Metanorma
127
127
  super
128
128
  end
129
129
 
130
+ def document_scheme(node)
131
+ super || "current"
132
+ end
133
+
130
134
  def html_extract_attributes(node)
131
135
  super.merge(hierarchicalassets:
132
136
  node.attr("hierarchical-object-numbering"))