metanorma-iso 2.0.8.1 → 2.1.2
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.
- checksums.yaml +4 -4
- data/lib/html2doc/lists.rb +169 -0
- data/lib/isodoc/iso/base_convert.rb +11 -1
- data/lib/isodoc/iso/html/html_iso_titlepage.html +7 -0
- data/lib/isodoc/iso/html/isodoc-dis.css +407 -427
- data/lib/isodoc/iso/html/isodoc-dis.scss +482 -438
- data/lib/isodoc/iso/html/isodoc.css +38 -13
- data/lib/isodoc/iso/html/isodoc.scss +38 -12
- data/lib/isodoc/iso/html/style-human.css +14 -1
- data/lib/isodoc/iso/html/style-human.scss +10 -1
- data/lib/isodoc/iso/html/style-iso.css +35 -23
- data/lib/isodoc/iso/html/style-iso.scss +31 -23
- data/lib/isodoc/iso/html/word_iso_intro-dis.html +3 -1
- data/lib/isodoc/iso/html/word_iso_titlepage-dis.html +26 -13
- data/lib/isodoc/iso/html/word_iso_titlepage-prf.html +58 -0
- data/lib/isodoc/iso/html/word_iso_titlepage.html +16 -6
- data/lib/isodoc/iso/html/wordstyle-dis.css +168 -48
- data/lib/isodoc/iso/html/wordstyle-dis.scss +158 -43
- data/lib/isodoc/iso/html_convert.rb +7 -2
- data/lib/isodoc/iso/i18n-en.yaml +33 -4
- data/lib/isodoc/iso/i18n-fr.yaml +30 -3
- data/lib/isodoc/iso/i18n-ru.yaml +33 -4
- data/lib/isodoc/iso/i18n-zh-Hans.yaml +33 -3
- data/lib/isodoc/iso/i18n.rb +1 -1
- data/lib/isodoc/iso/init.rb +17 -1
- data/lib/isodoc/iso/iso.amendment.xsl +1711 -367
- data/lib/isodoc/iso/iso.international-standard.xsl +1711 -367
- data/lib/isodoc/iso/metadata.rb +72 -78
- data/lib/isodoc/iso/presentation_bibdata.rb +74 -0
- data/lib/isodoc/iso/presentation_xml_convert.rb +52 -100
- data/lib/isodoc/iso/presentation_xref.rb +132 -0
- data/lib/isodoc/iso/sections.rb +3 -3
- data/lib/isodoc/iso/word_cleanup.rb +17 -0
- data/lib/isodoc/iso/word_convert.rb +32 -12
- data/lib/isodoc/iso/word_dis_cleanup.rb +235 -0
- data/lib/isodoc/iso/word_dis_convert.rb +122 -0
- data/lib/isodoc/iso/xref.rb +78 -29
- data/lib/metanorma/iso/base.rb +20 -1
- data/lib/metanorma/iso/biblio.rng +69 -42
- data/lib/metanorma/iso/boilerplate-fr.xml +4 -1
- data/lib/metanorma/iso/boilerplate-ru.xml +4 -3
- data/lib/metanorma/iso/boilerplate.xml +4 -3
- data/lib/metanorma/iso/cleanup.rb +29 -1
- data/lib/metanorma/iso/front.rb +31 -6
- data/lib/metanorma/iso/front_id.rb +2 -0
- data/lib/metanorma/iso/isodoc.rng +65 -0
- data/lib/metanorma/iso/isostandard.rng +30 -12
- data/lib/metanorma/iso/macros.rb +29 -0
- data/lib/metanorma/iso/version.rb +1 -1
- data/lib/metanorma-iso.rb +1 -0
- data/lib/relaton/render/config.yml +4 -0
- data/lib/relaton/render/general.rb +13 -0
- data/metanorma-iso.gemspec +1 -1
- data/spec/isodoc/amd_spec.rb +35 -60
- data/spec/isodoc/blocks_spec.rb +783 -179
- data/spec/isodoc/i18n_spec.rb +331 -100
- data/spec/isodoc/inline_spec.rb +35 -42
- data/spec/isodoc/iso_spec.rb +51 -170
- data/spec/isodoc/metadata_spec.rb +240 -99
- data/spec/isodoc/postproc_spec.rb +68 -7
- data/spec/isodoc/ref_spec.rb +66 -69
- data/spec/isodoc/section_spec.rb +88 -80
- data/spec/isodoc/table_spec.rb +2 -2
- data/spec/isodoc/terms_spec.rb +2 -2
- data/spec/isodoc/word_dis_spec.rb +1886 -0
- data/spec/isodoc/xref_spec.rb +138 -64
- data/spec/metanorma/amd_spec.rb +53 -1
- data/spec/metanorma/base_spec.rb +195 -20
- data/spec/metanorma/blocks_spec.rb +54 -0
- data/spec/metanorma/lists_spec.rb +2 -2
- data/spec/metanorma/section_spec.rb +2 -2
- data/spec/spec_helper.rb +23 -4
- data/spec/vcr_cassettes/withdrawn_iso.yml +25 -25
- metadata +15 -10
- data/docs/asciiiso-syntax.adoc +0 -307
- data/docs/guidance.adoc +0 -487
- data/docs/navigation.adoc +0 -23
- data/docs/quickstart.adoc +0 -179
- data/spec/vcr_cassettes/docrels.yml +0 -385
data/lib/isodoc/iso/metadata.rb
CHANGED
@@ -5,11 +5,8 @@ module IsoDoc
|
|
5
5
|
class Metadata < IsoDoc::Metadata
|
6
6
|
def initialize(lang, script, i18n)
|
7
7
|
super
|
8
|
-
|
9
|
-
set(:sc, "XXXX")
|
10
|
-
set(:wg, "XXXX")
|
8
|
+
DATETYPES.each { |w| @metadata["#{w.gsub(/-/, '_')}date".to_sym] = nil }
|
11
9
|
set(:editorialgroup, [])
|
12
|
-
set(:secretariat, "XXX")
|
13
10
|
set(:obsoletes, nil)
|
14
11
|
set(:obsoletes_part, nil)
|
15
12
|
end
|
@@ -21,8 +18,7 @@ module IsoDoc
|
|
21
18
|
stage = "DTS" if stage == "DIS"
|
22
19
|
stage = "FDTS" if stage == "FDIS"
|
23
20
|
end
|
24
|
-
%w(PWI NWIP WD CD).include?(stage) && iter and
|
25
|
-
stage += iter
|
21
|
+
%w(PWI NWIP WD CD).include?(stage) && iter and stage += iter
|
26
22
|
stage = "Pre#{stage}" if /^0\./.match?(draft)
|
27
23
|
stage
|
28
24
|
end
|
@@ -32,21 +28,20 @@ module IsoDoc
|
|
32
28
|
set(:unpublished, false)
|
33
29
|
revdate = isoxml.at(ns("//bibdata/version/revision-date"))
|
34
30
|
set(:revdate, revdate&.text)
|
35
|
-
|
36
|
-
docstatus1(isoxml, docstatus)
|
37
|
-
end
|
31
|
+
docstatus and docstatus1(isoxml, docstatus)
|
38
32
|
end
|
39
33
|
|
40
34
|
def docstatus1(isoxml, docstatus)
|
41
35
|
set(:stage, docstatus.text)
|
42
36
|
set(:stage_int, docstatus.text.to_i)
|
37
|
+
set(:substage_int, isoxml.at(ns("//bibdata/status/substage"))&.text)
|
43
38
|
set(:unpublished, unpublished(docstatus.text))
|
44
39
|
set(:statusabbr,
|
45
40
|
status_abbrev(docstatus["abbreviation"] || "??",
|
46
|
-
isoxml
|
47
|
-
isoxml
|
48
|
-
isoxml
|
49
|
-
isoxml
|
41
|
+
isoxml.at(ns("//bibdata/status/substage"))&.text,
|
42
|
+
isoxml.at(ns("//bibdata/status/iteration"))&.text,
|
43
|
+
isoxml.at(ns("//bibdata/version/draft"))&.text,
|
44
|
+
isoxml.at(ns("//bibdata/ext/doctype"))&.text))
|
50
45
|
unpublished(docstatus.text) and
|
51
46
|
set(:stageabbr, docstatus["abbreviation"])
|
52
47
|
end
|
@@ -68,28 +63,11 @@ module IsoDoc
|
|
68
63
|
|
69
64
|
# we don't leave this to i18n.rb, because we have both English and
|
70
65
|
# French titles in the same document
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def amd_label(lang)
|
80
|
-
case lang
|
81
|
-
when "en", "fr" then "AMENDMENT"
|
82
|
-
when "ru" then "ПОПРАВКА"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def corr_label(lang)
|
87
|
-
case lang
|
88
|
-
when "en" then "TECHNICAL CORRIGENDUM"
|
89
|
-
when "fr" then "RECTIFICATIF TECHNIQUE"
|
90
|
-
when "ru" then "ТЕХНИЧЕСКОЕ ИСПРАВЛЕНИЕ"
|
91
|
-
end
|
92
|
-
end
|
66
|
+
PART_LABEL = { en: "Part", fr: "Partie", ru: "Часть" }.freeze
|
67
|
+
AMD_LABEL = { en: "AMENDMENT", fr: "AMENDMENT", ru: "ПОПРАВКА" }.freeze
|
68
|
+
CORR_LABEL = { en: "TECHNICAL CORRIGENDUM",
|
69
|
+
fr: "RECTIFICATIF TECHNIQUE",
|
70
|
+
ru: "ТЕХНИЧЕСКОЕ ИСПРАВЛЕНИЕ" }.freeze
|
93
71
|
|
94
72
|
def part_title(part, titlenums, lang)
|
95
73
|
return "" unless part
|
@@ -97,25 +75,25 @@ module IsoDoc
|
|
97
75
|
suffix = @c.encode(part.text, :hexadecimal)
|
98
76
|
p = titlenums[:part]
|
99
77
|
titlenums[:part] && titlenums[:subpart] and
|
100
|
-
p = "#{titlenums[:part]}
|
78
|
+
p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
|
101
79
|
titlenums[:part] and
|
102
|
-
suffix = "#{
|
80
|
+
suffix = "#{PART_LABEL[lang.to_sym]} #{p}: " + suffix
|
103
81
|
suffix
|
104
82
|
end
|
105
83
|
|
106
84
|
def part_prefix(titlenums, lang)
|
107
85
|
p = titlenums[:part]
|
108
86
|
titlenums[:part] && titlenums[:subpart] and
|
109
|
-
p = "#{titlenums[:part]}
|
110
|
-
"#{
|
87
|
+
p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
|
88
|
+
"#{PART_LABEL[lang.to_sym]} #{p}"
|
111
89
|
end
|
112
90
|
|
113
91
|
def amd_prefix(titlenums, lang)
|
114
|
-
"#{
|
92
|
+
"#{AMD_LABEL[lang.to_sym]} #{titlenums[:amd]}"
|
115
93
|
end
|
116
94
|
|
117
95
|
def corr_prefix(titlenums, lang)
|
118
|
-
"#{
|
96
|
+
"#{CORR_LABEL[lang.to_sym]} #{titlenums[:corr]}"
|
119
97
|
end
|
120
98
|
|
121
99
|
def compose_title(tparts, tnums, lang)
|
@@ -124,29 +102,30 @@ module IsoDoc
|
|
124
102
|
main = @c.encode(tparts[:main].text, :hexadecimal)
|
125
103
|
tparts[:intro] &&
|
126
104
|
main = "#{@c.encode(tparts[:intro].text,
|
127
|
-
:hexadecimal)}
|
105
|
+
:hexadecimal)} — #{main}"
|
128
106
|
if tparts[:part]
|
129
107
|
suffix = part_title(tparts[:part], tnums, lang)
|
130
|
-
main = "#{main}
|
108
|
+
main = "#{main} — #{suffix}"
|
131
109
|
end
|
132
110
|
main
|
133
111
|
end
|
134
112
|
|
135
113
|
def title_nums(isoxml)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
114
|
+
prefix = "//bibdata/ext/structuredidentifier/project-number"
|
115
|
+
{ part: isoxml.at(ns("#{prefix}/@part")),
|
116
|
+
subpart: isoxml.at(ns("#{prefix}/@subpart")),
|
117
|
+
amd: isoxml.at(ns("#{prefix}/@amendment")),
|
118
|
+
corr: isoxml.at(ns("#{prefix}/@corrigendum")) }
|
140
119
|
end
|
141
120
|
|
142
121
|
def title_parts(isoxml, lang)
|
143
|
-
{ intro: isoxml.at(ns("//bibdata
|
122
|
+
{ intro: isoxml.at(ns("//bibdata/title[@type='title-intro' and "\
|
144
123
|
"@language='#{lang}']")),
|
145
|
-
main: isoxml.at(ns("//bibdata
|
124
|
+
main: isoxml.at(ns("//bibdata/title[@type='title-main' and "\
|
146
125
|
"@language='#{lang}']")),
|
147
|
-
part: isoxml.at(ns("//bibdata
|
126
|
+
part: isoxml.at(ns("//bibdata/title[@type='title-part' and "\
|
148
127
|
"@language='#{lang}']")),
|
149
|
-
amd: isoxml.at(ns("//bibdata
|
128
|
+
amd: isoxml.at(ns("//bibdata/title[@type='title-amd' and "\
|
150
129
|
"@language='#{lang}']")) }
|
151
130
|
end
|
152
131
|
|
@@ -164,10 +143,9 @@ module IsoDoc
|
|
164
143
|
@c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
|
165
144
|
main = compose_title(tp, tn, lang)
|
166
145
|
set(:doctitle, main)
|
167
|
-
|
146
|
+
tp[:intro] and
|
168
147
|
set(:doctitleintro,
|
169
148
|
@c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
|
170
|
-
end
|
171
149
|
set(:doctitlepartlabel, part_prefix(tn, lang))
|
172
150
|
set(:doctitlepart, @c.encode(tp[:part].text, :hexadecimal)) if tp[:part]
|
173
151
|
set(:doctitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
|
@@ -184,15 +162,13 @@ module IsoDoc
|
|
184
162
|
@c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
|
185
163
|
main = compose_title(tp, tn, lang)
|
186
164
|
set(:docsubtitle, main)
|
187
|
-
|
165
|
+
tp[:intro] and
|
188
166
|
set(:docsubtitleintro,
|
189
167
|
@c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
|
190
|
-
end
|
191
168
|
set(:docsubtitlepartlabel, part_prefix(tn, lang))
|
192
|
-
|
169
|
+
tp[:part] and
|
193
170
|
set(:docsubtitlepart,
|
194
171
|
@c.encode(tp[:part].text, :hexadecimal))
|
195
|
-
end
|
196
172
|
set(:docsubtitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
|
197
173
|
set(:docsubtitleamd, @c.encode(tp[:amd].text, :hexadecimal)) if tp[:amd]
|
198
174
|
set(:docsubtitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
|
@@ -203,40 +179,58 @@ module IsoDoc
|
|
203
179
|
tc(xml)
|
204
180
|
sc(xml)
|
205
181
|
wg(xml)
|
182
|
+
approvalgroup(xml)
|
206
183
|
secretariat(xml)
|
207
184
|
end
|
208
185
|
|
209
186
|
def tc(xml)
|
210
|
-
|
187
|
+
tcid = tc_base(xml, "editorialgroup") or return
|
188
|
+
set(:tc, tcid)
|
189
|
+
set(:editorialgroup, get[:editorialgroup] << tcid)
|
190
|
+
end
|
191
|
+
|
192
|
+
def tc_base(xml, grouptype)
|
193
|
+
tc_num = xml.at(ns("//bibdata/ext/#{grouptype}/"\
|
194
|
+
"technical-committee/@number")) or return nil
|
195
|
+
tc_type = xml.at(ns("//bibdata/ext/#{grouptype}/technical-committee/"\
|
211
196
|
"@type"))&.text || "TC"
|
212
|
-
|
213
|
-
"technical-committee/@number"))
|
214
|
-
tcid = "#{tc_type} #{tc_num.text}"
|
215
|
-
set(:tc, tcid)
|
216
|
-
set(:editorialgroup, get[:editorialgroup] << tcid)
|
217
|
-
end
|
197
|
+
"#{tc_type} #{tc_num.text}"
|
218
198
|
end
|
219
199
|
|
220
200
|
def sc(xml)
|
221
|
-
|
222
|
-
|
201
|
+
scid = sc_base(xml, "editorialgroup") or return
|
202
|
+
set(:sc, scid)
|
203
|
+
set(:editorialgroup, get[:editorialgroup] << scid)
|
204
|
+
end
|
205
|
+
|
206
|
+
def sc_base(xml, grouptype)
|
207
|
+
sc_num = xml.at(ns("//bibdata/ext/#{grouptype}/subcommittee/"\
|
208
|
+
"@number")) or return nil
|
209
|
+
sc_type = xml.at(ns("//bibdata/ext/#{grouptype}/subcommittee/"\
|
223
210
|
"@type"))&.text || "SC"
|
224
|
-
|
225
|
-
scid = "#{sc_type} #{sc_num.text}"
|
226
|
-
set(:sc, scid)
|
227
|
-
set(:editorialgroup, get[:editorialgroup] << scid)
|
228
|
-
end
|
211
|
+
"#{sc_type} #{sc_num.text}"
|
229
212
|
end
|
230
213
|
|
231
214
|
def wg(xml)
|
232
|
-
|
233
|
-
|
215
|
+
wgid = wg_base(xml, "editorialgroup") or return
|
216
|
+
set(:wg, wgid)
|
217
|
+
set(:editorialgroup, get[:editorialgroup] << wgid)
|
218
|
+
end
|
219
|
+
|
220
|
+
def wg_base(xml, grouptype)
|
221
|
+
wg_num = xml.at(ns("//bibdata/ext/#{grouptype}/workgroup/"\
|
222
|
+
"@number")) or return
|
223
|
+
wg_type = xml.at(ns("//bibdata/ext/#{grouptype}/workgroup/"\
|
234
224
|
"@type"))&.text || "WG"
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
225
|
+
"#{wg_type} #{wg_num.text}"
|
226
|
+
end
|
227
|
+
|
228
|
+
def approvalgroup(xml)
|
229
|
+
ag = tc_base(xml, "approvalgroup") or return
|
230
|
+
ret = [ag]
|
231
|
+
ret << sc_base(xml, "approvalgroup")
|
232
|
+
ret << wg_base(xml, "approvalgroup")
|
233
|
+
set(:approvalgroup, ret)
|
240
234
|
end
|
241
235
|
|
242
236
|
def secretariat(xml)
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
module Iso
|
3
|
+
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
|
4
|
+
def bibdata(docxml)
|
5
|
+
super
|
6
|
+
editorialgroup_identifier(docxml)
|
7
|
+
warning_for_missing_metadata(docxml)
|
8
|
+
end
|
9
|
+
|
10
|
+
def warning_for_missing_metadata(docxml)
|
11
|
+
return unless @meta.get[:unpublished]
|
12
|
+
|
13
|
+
ret = ""
|
14
|
+
docxml.at(ns("//bibdata/ext//secretariat")) or
|
15
|
+
ret += "<p>Secretariat is missing.</p>"
|
16
|
+
docxml.at(ns("//bibdata/ext//editorialgroup")) or
|
17
|
+
ret += "<p>Editorial groups are missing.</p>"
|
18
|
+
docxml.at(ns("//bibdata/date[@type = 'published' or @type = 'issued' "\
|
19
|
+
"or @type = 'created']")) ||
|
20
|
+
docxml.at(ns("//bibdata/version/revision-date")) or
|
21
|
+
ret += "<p>Document date is missing.</p>"
|
22
|
+
return if ret.empty?
|
23
|
+
|
24
|
+
warning_for_missing_metadata1(docxml, ret)
|
25
|
+
end
|
26
|
+
|
27
|
+
def warning_for_missing_metadata1(docxml, ret)
|
28
|
+
id = UUIDTools::UUID.random_create
|
29
|
+
ret = "<review date='#{Date.today}' reviewer='Metanorma' id='_#{id}'>"\
|
30
|
+
"<p><strong>Metadata warnings:<strong></p> #{ret}</review>"
|
31
|
+
ins = docxml.at(ns("//sections//title")) or return
|
32
|
+
ins.children.first.previous = ret
|
33
|
+
end
|
34
|
+
|
35
|
+
def editorialgroup_identifier(docxml)
|
36
|
+
%w(editorialgroup approvalgroup).each do |v|
|
37
|
+
docxml.xpath(ns("//bibdata/ext/#{v}")).each do |a|
|
38
|
+
editorialgroup_identifier1(a)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def editorialgroup_identifier1(group)
|
44
|
+
agency = group.xpath(ns("./agency"))&.map(&:text)
|
45
|
+
ret = %w(technical-committee subcommittee workgroup)
|
46
|
+
.each_with_object([]) do |v, m|
|
47
|
+
a = group.at(ns("./#{v}")) or next
|
48
|
+
m << "#{a['type']} #{a['number']}"
|
49
|
+
end
|
50
|
+
group["identifier"] = (agency + ret).join("/")
|
51
|
+
end
|
52
|
+
|
53
|
+
def bibdata_i18n(bib)
|
54
|
+
hash_translate(bib, @i18n.get["doctype_dict"], "./ext/doctype")
|
55
|
+
bibdata_i18n_stage(bib, bib.at(ns("./status/stage")),
|
56
|
+
bib.at(ns("./ext/doctype")))
|
57
|
+
hash_translate(bib, @i18n.get["substage_dict"],
|
58
|
+
"./status/substage")
|
59
|
+
edition_translate(bib)
|
60
|
+
end
|
61
|
+
|
62
|
+
def bibdata_i18n_stage(bib, stage, type, lang: @lang, i18n: @i18n)
|
63
|
+
return unless stage
|
64
|
+
|
65
|
+
i18n.get["stage_dict"][stage.text].is_a?(Hash) or
|
66
|
+
return hash_translate(bib, i18n.get["stage_dict"],
|
67
|
+
"./status/stage", lang)
|
68
|
+
i18n.get["stage_dict"][stage.text][type&.text] and
|
69
|
+
tag_translate(stage, lang,
|
70
|
+
i18n.get["stage_dict"][stage.text][type&.text])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
require_relative "init"
|
2
2
|
require "isodoc"
|
3
3
|
require_relative "index"
|
4
|
+
require_relative "presentation_xref"
|
5
|
+
require_relative "presentation_bibdata"
|
6
|
+
require_relative "../../relaton/render/general"
|
4
7
|
|
5
8
|
module IsoDoc
|
6
9
|
module Iso
|
7
10
|
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
|
8
11
|
def convert1(docxml, filename, dir)
|
12
|
+
@iso_class = instance_of?(IsoDoc::Iso::PresentationXMLConvert)
|
9
13
|
if amd(docxml)
|
10
14
|
@oldsuppressheadingnumbers = @suppressheadingnumbers
|
11
15
|
@suppressheadingnumbers = true
|
@@ -22,104 +26,19 @@ module IsoDoc
|
|
22
26
|
amd(isoxml) and @suppressheadingnumbers = true
|
23
27
|
end
|
24
28
|
|
25
|
-
def xref_init(lang, script, klass, labels, options)
|
26
|
-
@xrefs = Xref.new(lang, script, klass, labels, options)
|
27
|
-
end
|
28
|
-
|
29
29
|
def figure1(node)
|
30
30
|
lbl = @xrefs.anchor(node["id"], :label, false) or return
|
31
31
|
figname = node.parent.name == "figure" ? "" : "#{@i18n.figure} "
|
32
|
-
connective = node.parent.name == "figure" ? "
|
32
|
+
connective = node.parent.name == "figure" ? "  " : " — "
|
33
33
|
prefix_name(node, connective, l10n("#{figname}#{lbl}"), "name")
|
34
34
|
end
|
35
35
|
|
36
36
|
def example1(node)
|
37
37
|
n = @xrefs.get[node["id"]]
|
38
|
-
lbl = if n.nil? || n[:label]
|
39
|
-
|
40
|
-
else
|
41
|
-
l10n("#{@i18n.example} #{n[:label]}")
|
42
|
-
end
|
43
|
-
prefix_name(node, " — ", lbl, "name")
|
44
|
-
end
|
45
|
-
|
46
|
-
def eref_delim(delim, type)
|
47
|
-
if delim == ";" then ";"
|
48
|
-
else type == "list" ? " " : delim
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def can_conflate_eref_rendering?(refs)
|
53
|
-
super or return false
|
54
|
-
|
55
|
-
first = subclause?(nil, refs.first.at(ns("./locality/@type"))&.text,
|
56
|
-
refs.first.at(ns("./locality/referenceFrom"))&.text)
|
57
|
-
refs.all? do |r|
|
58
|
-
subclause?(nil, r.at(ns("./locality/@type"))&.text,
|
59
|
-
r.at(ns("./locality/referenceFrom"))&.text) == first
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def locality_delimiter(loc)
|
64
|
-
loc&.next_element&.attribute("type")&.text == "list" and return " "
|
65
|
-
super
|
66
|
-
end
|
67
|
-
|
68
|
-
def eref_localities_conflated(refs, target, node)
|
69
|
-
droploc = node["droploc"]
|
70
|
-
node["droploc"] = true
|
71
|
-
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
|
72
|
-
node))
|
73
|
-
node["droploc"] = droploc
|
74
|
-
eref_localities1(target,
|
75
|
-
prefix_clause(target, refs.first.at(ns("./locality"))),
|
76
|
-
l10n(ret[1..-1].join), nil, node, @lang)
|
77
|
-
end
|
78
|
-
|
79
|
-
def prefix_clause(target, loc)
|
80
|
-
loc["type"] == "clause" or return loc["type"]
|
81
|
-
|
82
|
-
if subclause?(target, loc["type"], loc&.at(ns("./referenceFrom"))&.text)
|
83
|
-
""
|
84
|
-
else
|
85
|
-
"clause"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def subclause?(target, type, from)
|
90
|
-
(from&.match?(/\./) && type == "clause") ||
|
91
|
-
type == "list" || target&.match(/^IEV$|^IEC 60050-/)
|
92
|
-
end
|
93
|
-
|
94
|
-
def eref_localities1_zh(target, type, from, upto, node)
|
95
|
-
ret = " 第#{from}" if from
|
96
|
-
ret += "–#{upto}" if upto
|
97
|
-
if node["droploc"] != "true" && !subclause?(target, type, from)
|
98
|
-
ret += eref_locality_populate(type, node)
|
99
|
-
end
|
100
|
-
ret += ")" if type == "list"
|
101
|
-
ret
|
102
|
-
end
|
103
|
-
|
104
|
-
def eref_localities1(target, type, from, upto, node, lang = "en")
|
105
|
-
return nil if type == "anchor"
|
106
|
-
|
107
|
-
type = type.downcase
|
108
|
-
lang == "zh" and
|
109
|
-
return l10n(eref_localities1_zh(target, type, from, upto, node))
|
110
|
-
ret = if node["droploc"] != "true" && !subclause?(target, type, from)
|
111
|
-
eref_locality_populate(type, node)
|
112
|
-
else ""
|
38
|
+
lbl = if n.nil? || blank?(n[:label]) then @i18n.example
|
39
|
+
else l10n("#{@i18n.example} #{n[:label]}")
|
113
40
|
end
|
114
|
-
|
115
|
-
ret += "–#{upto}" if upto
|
116
|
-
ret += ")" if type == "list"
|
117
|
-
l10n(ret)
|
118
|
-
end
|
119
|
-
|
120
|
-
def prefix_container(container, linkend, target)
|
121
|
-
delim = @xrefs.anchor(target, :type) == "listitem" ? " " : ", "
|
122
|
-
l10n(@xrefs.anchor(container, :xref) + delim + linkend)
|
41
|
+
prefix_name(node, " — ", lbl, "name")
|
123
42
|
end
|
124
43
|
|
125
44
|
def example_span_label(_node, div, name)
|
@@ -141,8 +60,7 @@ module IsoDoc
|
|
141
60
|
def clause(docxml)
|
142
61
|
docxml.xpath(ns("//clause[not(ancestor::annex)] | "\
|
143
62
|
"//terms | //definitions | //references | "\
|
144
|
-
"//preface/introduction[clause]"))
|
145
|
-
.each do |f|
|
63
|
+
"//preface/introduction[clause]")).each do |f|
|
146
64
|
clause1(f)
|
147
65
|
end
|
148
66
|
end
|
@@ -158,9 +76,7 @@ module IsoDoc
|
|
158
76
|
def concept_term(docxml)
|
159
77
|
docxml.xpath(ns("//term")).each do |f|
|
160
78
|
m = {}
|
161
|
-
f.xpath(ns(".//concept")).each
|
162
|
-
concept_term1(c, m)
|
163
|
-
end
|
79
|
+
f.xpath(ns(".//concept")).each { |c| concept_term1(c, m) }
|
164
80
|
end
|
165
81
|
end
|
166
82
|
|
@@ -177,12 +93,11 @@ module IsoDoc
|
|
177
93
|
end
|
178
94
|
|
179
95
|
def concept1_ref_content(ref)
|
180
|
-
if ref.name == "termref"
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
end
|
96
|
+
repl = if ref.name == "termref"
|
97
|
+
@i18n.term_defined_in.sub(/%/, ref.to_xml)
|
98
|
+
else "(#{ref.to_xml})"
|
99
|
+
end
|
100
|
+
ref.replace(repl)
|
186
101
|
end
|
187
102
|
|
188
103
|
def concept1(node)
|
@@ -244,6 +159,43 @@ module IsoDoc
|
|
244
159
|
super
|
245
160
|
end
|
246
161
|
|
162
|
+
def admonition1(elem)
|
163
|
+
super
|
164
|
+
return unless n = elem.at(ns("./name"))
|
165
|
+
|
166
|
+
p = n.next_element
|
167
|
+
return unless p.name == "p"
|
168
|
+
|
169
|
+
p.children.first.previous = admonition_name(n.remove.children.to_xml)
|
170
|
+
end
|
171
|
+
|
172
|
+
def admonition_name(xml)
|
173
|
+
"#{xml} — "
|
174
|
+
end
|
175
|
+
|
176
|
+
def bibrenderer
|
177
|
+
::Relaton::Render::Iso::General.new(language: @lang,
|
178
|
+
i18nhash: @i18n.get)
|
179
|
+
end
|
180
|
+
|
181
|
+
def bibrender(xml)
|
182
|
+
unless xml.at(ns("./formattedref"))
|
183
|
+
xml.children =
|
184
|
+
"#{bibrenderer.render(xml.to_xml)}"\
|
185
|
+
"#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def ol_depth(node)
|
190
|
+
depth = node.ancestors(@iso_class ? "ol" : "ul, ol").size + 1
|
191
|
+
type = :alphabet
|
192
|
+
type = :arabic if [2, 7].include? depth
|
193
|
+
type = :roman if [3, 8].include? depth
|
194
|
+
type = :alphabet_upper if [4, 9].include? depth
|
195
|
+
type = :roman_upper if [5, 10].include? depth
|
196
|
+
type
|
197
|
+
end
|
198
|
+
|
247
199
|
include Init
|
248
200
|
end
|
249
201
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
module Iso
|
3
|
+
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
|
4
|
+
def xref_init(lang, script, klass, labels, options)
|
5
|
+
@xrefs = Xref.new(lang, script, klass, labels, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def eref_delim(delim, type)
|
9
|
+
if delim == ";" then ";"
|
10
|
+
else type == "list" ? " " : delim
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def can_conflate_eref_rendering?(refs)
|
15
|
+
super or return false
|
16
|
+
|
17
|
+
first = subclause?(nil, refs.first.at(ns("./locality/@type"))&.text,
|
18
|
+
refs.first.at(ns("./locality/referenceFrom"))&.text)
|
19
|
+
refs.all? do |r|
|
20
|
+
subclause?(nil, r.at(ns("./locality/@type"))&.text,
|
21
|
+
r.at(ns("./locality/referenceFrom"))&.text) == first
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def locality_delimiter(loc)
|
26
|
+
loc&.next_element&.attribute("type")&.text == "list" and return " "
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def eref_localities_conflated(refs, target, node)
|
31
|
+
droploc = node["droploc"]
|
32
|
+
node["droploc"] = true
|
33
|
+
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
|
34
|
+
node))
|
35
|
+
node["droploc"] = droploc
|
36
|
+
eref_localities1(target,
|
37
|
+
prefix_clause(target, refs.first.at(ns("./locality"))),
|
38
|
+
l10n(ret[1..-1].join), nil, node, @lang)
|
39
|
+
end
|
40
|
+
|
41
|
+
def prefix_clause(target, loc)
|
42
|
+
loc["type"] == "clause" or return loc["type"]
|
43
|
+
|
44
|
+
if subclause?(target, loc["type"],
|
45
|
+
loc&.at(ns("./referenceFrom"))&.text)
|
46
|
+
""
|
47
|
+
else "clause"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def subclause?(target, type, from)
|
52
|
+
(from&.match?(/\./) && type == "clause") ||
|
53
|
+
type == "list" ||
|
54
|
+
target&.gsub(/<[^>]+>/, "")&.match(/^IEV$|^IEC 60050-/)
|
55
|
+
end
|
56
|
+
|
57
|
+
LOCALITY2SPAN = {
|
58
|
+
annex: "citeapp",
|
59
|
+
dunno: "citebase",
|
60
|
+
dunno2: "citebib",
|
61
|
+
dunno3: "citebox",
|
62
|
+
dunno4: "citeen",
|
63
|
+
dunno5: "citeeq",
|
64
|
+
figure: "citefig",
|
65
|
+
dunno6: "citefn",
|
66
|
+
clause: "citesec",
|
67
|
+
dunno7: "citesection",
|
68
|
+
table: "citetbl",
|
69
|
+
dunno8: "citetfn",
|
70
|
+
}.freeze
|
71
|
+
|
72
|
+
def locality_span_wrap(ret, type)
|
73
|
+
type or return ret
|
74
|
+
m = /^(\s*)(.+?)(\s*)$/.match(ret) or return ret
|
75
|
+
ret = [m[1], m[2], m[3]]
|
76
|
+
spanclass = LOCALITY2SPAN[type.to_sym] and
|
77
|
+
ret[1] = "<span class='#{spanclass}'>#{ret[1]}</span>"
|
78
|
+
ret.join
|
79
|
+
end
|
80
|
+
|
81
|
+
def eref_localities1_zh(target, type, from, upto, node)
|
82
|
+
ret = " 第#{from}" if from
|
83
|
+
ret += "–#{upto}" if upto
|
84
|
+
node["droploc"] != "true" && !subclause?(target, type, from) and
|
85
|
+
ret += eref_locality_populate(type, node)
|
86
|
+
ret += ")" if type == "list"
|
87
|
+
locality_span_wrap(ret, type)
|
88
|
+
end
|
89
|
+
|
90
|
+
def eref_localities1(target, type, from, upto, node, lang = "en")
|
91
|
+
return nil if type == "anchor"
|
92
|
+
|
93
|
+
type = type.downcase
|
94
|
+
lang == "zh" and
|
95
|
+
return l10n(eref_localities1_zh(target, type, from, upto, node))
|
96
|
+
ret = ""
|
97
|
+
node["droploc"] != "true" && !subclause?(target, type, from) and
|
98
|
+
ret = eref_locality_populate(type, node)
|
99
|
+
ret += " #{from}" if from
|
100
|
+
ret += "–#{upto}" if upto
|
101
|
+
ret += ")" if type == "list"
|
102
|
+
ret = l10n(ret)
|
103
|
+
locality_span_wrap(ret, type)
|
104
|
+
end
|
105
|
+
|
106
|
+
def prefix_container(container, linkend, target)
|
107
|
+
delim = ", "
|
108
|
+
type = :xref
|
109
|
+
if @xrefs.anchor(target, :type) == "listitem" &&
|
110
|
+
!@xrefs.anchor(target, :refer_list)
|
111
|
+
delim = " "
|
112
|
+
type = :label # 7 a) not Clause 7 a), but Clause 7 List 1 a)
|
113
|
+
end
|
114
|
+
l10n(@xrefs.anchor(container, type) + delim + linkend)
|
115
|
+
end
|
116
|
+
|
117
|
+
def expand_citeas(text)
|
118
|
+
std_docid_semantic(super)
|
119
|
+
end
|
120
|
+
|
121
|
+
def anchor_value(id)
|
122
|
+
locality_span_wrap(super, @xrefs.anchor(id, :subtype) ||
|
123
|
+
@xrefs.anchor(id, :type))
|
124
|
+
end
|
125
|
+
|
126
|
+
def anchor_linkend1(node)
|
127
|
+
locality_span_wrap(super, @xrefs.anchor(node["target"], :subtype) ||
|
128
|
+
@xrefs.anchor(node["target"], :type))
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|