metanorma-iso 2.1.1 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/html2doc/lists.rb +145 -10
- data/lib/isodoc/iso/base_convert.rb +10 -0
- data/lib/isodoc/iso/html/html_iso_titlepage.html +2 -0
- data/lib/isodoc/iso/html/isodoc-dis.css +173 -257
- data/lib/isodoc/iso/html/isodoc-dis.scss +173 -249
- 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 +1 -6
- data/lib/isodoc/iso/html/word_iso_titlepage-dis.html +24 -13
- data/lib/isodoc/iso/html/word_iso_titlepage-prf.html +58 -0
- data/lib/isodoc/iso/html/word_iso_titlepage.html +6 -2
- data/lib/isodoc/iso/html_convert.rb +5 -0
- data/lib/isodoc/iso/i18n-en.yaml +32 -4
- data/lib/isodoc/iso/i18n-fr.yaml +29 -3
- data/lib/isodoc/iso/i18n-ru.yaml +32 -4
- data/lib/isodoc/iso/i18n-zh-Hans.yaml +32 -3
- data/lib/isodoc/iso/i18n.rb +1 -1
- data/lib/isodoc/iso/iso.amendment.xsl +750 -307
- data/lib/isodoc/iso/iso.international-standard.xsl +750 -307
- data/lib/isodoc/iso/metadata.rb +63 -63
- data/lib/isodoc/iso/presentation_bibdata.rb +74 -0
- data/lib/isodoc/iso/presentation_xml_convert.rb +15 -4
- data/lib/isodoc/iso/presentation_xref.rb +8 -2
- data/lib/isodoc/iso/sections.rb +1 -1
- data/lib/isodoc/iso/word_cleanup.rb +3 -0
- data/lib/isodoc/iso/word_convert.rb +6 -3
- data/lib/isodoc/iso/word_dis_cleanup.rb +243 -0
- data/lib/isodoc/iso/word_dis_convert.rb +47 -108
- data/lib/isodoc/iso/xref.rb +34 -6
- data/lib/metanorma/iso/base.rb +14 -1
- data/lib/metanorma/iso/biblio.rng +134 -39
- data/lib/metanorma/iso/boilerplate-fr.xml +3 -0
- data/lib/metanorma/iso/boilerplate-ru.xml +3 -0
- data/lib/metanorma/iso/boilerplate.xml +3 -0
- data/lib/metanorma/iso/cleanup.rb +53 -13
- data/lib/metanorma/iso/front.rb +38 -6
- data/lib/metanorma/iso/front_id.rb +2 -0
- data/lib/metanorma/iso/isodoc.rng +32 -0
- data/lib/metanorma/iso/isostandard.rng +32 -12
- data/lib/metanorma/iso/validate_section.rb +0 -12
- data/lib/metanorma/iso/version.rb +1 -1
- data/spec/isodoc/amd_spec.rb +4 -30
- data/spec/isodoc/blocks_spec.rb +499 -2
- data/spec/isodoc/i18n_spec.rb +145 -80
- data/spec/isodoc/iso_spec.rb +50 -169
- data/spec/isodoc/metadata_spec.rb +223 -83
- data/spec/isodoc/postproc_spec.rb +41 -5
- data/spec/isodoc/section_spec.rb +9 -9
- data/spec/isodoc/word_dis_spec.rb +1332 -146
- data/spec/isodoc/xref_spec.rb +87 -13
- data/spec/metanorma/amd_spec.rb +39 -23
- data/spec/metanorma/base_spec.rb +174 -44
- data/spec/metanorma/blocks_spec.rb +21 -0
- data/spec/metanorma/cleanup_spec.rb +196 -196
- data/spec/metanorma/lists_spec.rb +2 -2
- data/spec/metanorma/section_spec.rb +2 -2
- data/spec/metanorma/validate_spec.rb +8 -19
- data/spec/spec_helper.rb +10 -7
- data/spec/vcr_cassettes/withdrawn_iso.yml +30 -30
- metadata +6 -8
- 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/lib/isodoc/iso/presentation_inline.rb +0 -90
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
|
@@ -37,13 +34,14 @@ module IsoDoc
|
|
37
34
|
def docstatus1(isoxml, docstatus)
|
38
35
|
set(:stage, docstatus.text)
|
39
36
|
set(:stage_int, docstatus.text.to_i)
|
37
|
+
set(:substage_int, isoxml.at(ns("//bibdata/status/substage"))&.text)
|
40
38
|
set(:unpublished, unpublished(docstatus.text))
|
41
39
|
set(:statusabbr,
|
42
40
|
status_abbrev(docstatus["abbreviation"] || "??",
|
43
|
-
isoxml
|
44
|
-
isoxml
|
45
|
-
isoxml
|
46
|
-
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))
|
47
45
|
unpublished(docstatus.text) and
|
48
46
|
set(:stageabbr, docstatus["abbreviation"])
|
49
47
|
end
|
@@ -65,28 +63,11 @@ module IsoDoc
|
|
65
63
|
|
66
64
|
# we don't leave this to i18n.rb, because we have both English and
|
67
65
|
# French titles in the same document
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def amd_label(lang)
|
77
|
-
case lang
|
78
|
-
when "en", "fr" then "AMENDMENT"
|
79
|
-
when "ru" then "ПОПРАВКА"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def corr_label(lang)
|
84
|
-
case lang
|
85
|
-
when "en" then "TECHNICAL CORRIGENDUM"
|
86
|
-
when "fr" then "RECTIFICATIF TECHNIQUE"
|
87
|
-
when "ru" then "ТЕХНИЧЕСКОЕ ИСПРАВЛЕНИЕ"
|
88
|
-
end
|
89
|
-
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
|
90
71
|
|
91
72
|
def part_title(part, titlenums, lang)
|
92
73
|
return "" unless part
|
@@ -96,7 +77,7 @@ module IsoDoc
|
|
96
77
|
titlenums[:part] && titlenums[:subpart] and
|
97
78
|
p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
|
98
79
|
titlenums[:part] and
|
99
|
-
suffix = "#{
|
80
|
+
suffix = "#{PART_LABEL[lang.to_sym]} #{p}: " + suffix
|
100
81
|
suffix
|
101
82
|
end
|
102
83
|
|
@@ -104,15 +85,15 @@ module IsoDoc
|
|
104
85
|
p = titlenums[:part]
|
105
86
|
titlenums[:part] && titlenums[:subpart] and
|
106
87
|
p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
|
107
|
-
"#{
|
88
|
+
"#{PART_LABEL[lang.to_sym]} #{p}"
|
108
89
|
end
|
109
90
|
|
110
91
|
def amd_prefix(titlenums, lang)
|
111
|
-
"#{
|
92
|
+
"#{AMD_LABEL[lang.to_sym]} #{titlenums[:amd]}"
|
112
93
|
end
|
113
94
|
|
114
95
|
def corr_prefix(titlenums, lang)
|
115
|
-
"#{
|
96
|
+
"#{CORR_LABEL[lang.to_sym]} #{titlenums[:corr]}"
|
116
97
|
end
|
117
98
|
|
118
99
|
def compose_title(tparts, tnums, lang)
|
@@ -130,20 +111,21 @@ module IsoDoc
|
|
130
111
|
end
|
131
112
|
|
132
113
|
def title_nums(isoxml)
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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")) }
|
137
119
|
end
|
138
120
|
|
139
121
|
def title_parts(isoxml, lang)
|
140
|
-
{ intro: isoxml.at(ns("//bibdata
|
122
|
+
{ intro: isoxml.at(ns("//bibdata/title[@type='title-intro' and "\
|
141
123
|
"@language='#{lang}']")),
|
142
|
-
main: isoxml.at(ns("//bibdata
|
124
|
+
main: isoxml.at(ns("//bibdata/title[@type='title-main' and "\
|
143
125
|
"@language='#{lang}']")),
|
144
|
-
part: isoxml.at(ns("//bibdata
|
126
|
+
part: isoxml.at(ns("//bibdata/title[@type='title-part' and "\
|
145
127
|
"@language='#{lang}']")),
|
146
|
-
amd: isoxml.at(ns("//bibdata
|
128
|
+
amd: isoxml.at(ns("//bibdata/title[@type='title-amd' and "\
|
147
129
|
"@language='#{lang}']")) }
|
148
130
|
end
|
149
131
|
|
@@ -197,40 +179,58 @@ module IsoDoc
|
|
197
179
|
tc(xml)
|
198
180
|
sc(xml)
|
199
181
|
wg(xml)
|
182
|
+
approvalgroup(xml)
|
200
183
|
secretariat(xml)
|
201
184
|
end
|
202
185
|
|
203
186
|
def tc(xml)
|
204
|
-
|
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/"\
|
205
196
|
"@type"))&.text || "TC"
|
206
|
-
|
207
|
-
"technical-committee/@number"))
|
208
|
-
tcid = "#{tc_type} #{tc_num.text}"
|
209
|
-
set(:tc, tcid)
|
210
|
-
set(:editorialgroup, get[:editorialgroup] << tcid)
|
211
|
-
end
|
197
|
+
"#{tc_type} #{tc_num.text}"
|
212
198
|
end
|
213
199
|
|
214
200
|
def sc(xml)
|
215
|
-
|
216
|
-
|
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/"\
|
217
210
|
"@type"))&.text || "SC"
|
218
|
-
|
219
|
-
scid = "#{sc_type} #{sc_num.text}"
|
220
|
-
set(:sc, scid)
|
221
|
-
set(:editorialgroup, get[:editorialgroup] << scid)
|
222
|
-
end
|
211
|
+
"#{sc_type} #{sc_num.text}"
|
223
212
|
end
|
224
213
|
|
225
214
|
def wg(xml)
|
226
|
-
|
227
|
-
|
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/"\
|
228
224
|
"@type"))&.text || "WG"
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
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.compact)
|
234
234
|
end
|
235
235
|
|
236
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,8 +1,8 @@
|
|
1
1
|
require_relative "init"
|
2
2
|
require "isodoc"
|
3
3
|
require_relative "index"
|
4
|
-
require_relative "presentation_inline"
|
5
4
|
require_relative "presentation_xref"
|
5
|
+
require_relative "presentation_bibdata"
|
6
6
|
require_relative "../../relaton/render/general"
|
7
7
|
|
8
8
|
module IsoDoc
|
@@ -38,7 +38,7 @@ module IsoDoc
|
|
38
38
|
lbl = if n.nil? || blank?(n[:label]) then @i18n.example
|
39
39
|
else l10n("#{@i18n.example} #{n[:label]}")
|
40
40
|
end
|
41
|
-
prefix_name(node,
|
41
|
+
prefix_name(node, block_delim, lbl, "name")
|
42
42
|
end
|
43
43
|
|
44
44
|
def example_span_label(_node, div, name)
|
@@ -172,9 +172,10 @@ module IsoDoc
|
|
172
172
|
def admonition_name(xml)
|
173
173
|
"#{xml} — "
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
def bibrenderer
|
177
|
-
::Relaton::Render::Iso::General.new(language: @lang,
|
177
|
+
::Relaton::Render::Iso::General.new(language: @lang,
|
178
|
+
i18nhash: @i18n.get)
|
178
179
|
end
|
179
180
|
|
180
181
|
def bibrender(xml)
|
@@ -185,6 +186,16 @@ module IsoDoc
|
|
185
186
|
end
|
186
187
|
end
|
187
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
|
+
|
188
199
|
include Init
|
189
200
|
end
|
190
201
|
end
|
@@ -104,8 +104,14 @@ module IsoDoc
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def prefix_container(container, linkend, target)
|
107
|
-
delim =
|
108
|
-
|
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)
|
109
115
|
end
|
110
116
|
|
111
117
|
def expand_citeas(text)
|
data/lib/isodoc/iso/sections.rb
CHANGED
@@ -14,10 +14,11 @@ module IsoDoc
|
|
14
14
|
@wordToClevels = 3 if @wordToClevels.zero?
|
15
15
|
@htmlToClevels = options[:htmltoclevels].to_i
|
16
16
|
@htmlToClevels = 3 if @htmlToClevels.zero?
|
17
|
-
init_dis
|
17
|
+
init_dis(options)
|
18
18
|
end
|
19
19
|
|
20
|
-
def init_dis
|
20
|
+
def init_dis(options)
|
21
|
+
@wordtemplate = options[:isowordtemplate]
|
21
22
|
@dis = ::IsoDoc::Iso::WordDISConvert.new(options)
|
22
23
|
end
|
23
24
|
|
@@ -55,8 +56,10 @@ module IsoDoc
|
|
55
56
|
output_filename = nil)
|
56
57
|
file = File.read(input_filename, encoding: "utf-8") if file.nil?
|
57
58
|
docxml = Nokogiri::XML(file) { |config| config.huge }
|
59
|
+
stage = docxml&.at(ns("//bibdata/status/stage"))&.text
|
58
60
|
if @dis &&
|
59
|
-
/^[
|
61
|
+
((/^[4569].$/.match?(stage) && @wordtemplate != "simple") ||
|
62
|
+
(/^[0-3].$/.match?(stage) && @wordtemplate == "dis"))
|
60
63
|
@dis.convert(input_filename, file, debug, output_filename)
|
61
64
|
else
|
62
65
|
super
|
@@ -0,0 +1,243 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
module Iso
|
3
|
+
class WordDISConvert < WordConvert
|
4
|
+
def style_cleanup(docxml)
|
5
|
+
super
|
6
|
+
dis_styles(docxml)
|
7
|
+
end
|
8
|
+
|
9
|
+
STYLESMAP = {
|
10
|
+
AltTerms: "AdmittedTerm",
|
11
|
+
TableFootnote: "Tablefootnote",
|
12
|
+
formula: "Formula",
|
13
|
+
note: "Note",
|
14
|
+
example: "Example",
|
15
|
+
admonition: "Admonition",
|
16
|
+
admonitiontitle: "AdmonitionTitle",
|
17
|
+
sourcetitle: "SourceTitle",
|
18
|
+
tabletitle: "TableTitle",
|
19
|
+
titlepagesbhead: "TablePageSubhead",
|
20
|
+
NormRef: "RefNorm",
|
21
|
+
Biblio: "BiblioEntry",
|
22
|
+
MsoNormal: "MsoBodyText",
|
23
|
+
FigureTitle: "Figuretitle",
|
24
|
+
zzwarning: "zzWarning",
|
25
|
+
zzwarninghdr: "zzWarningHdr",
|
26
|
+
quoteattribution: "QuoteAttribution",
|
27
|
+
Sourcecode: "Code",
|
28
|
+
zzSTDTitle1: "zzSTDTitle",
|
29
|
+
zzSTDTitle2: "zzSTDTitle",
|
30
|
+
zzCopyright1: "zzCopyright",
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
def dis_styles(docxml)
|
34
|
+
STYLESMAP.each do |k, v|
|
35
|
+
docxml.xpath("//*[@class = '#{k}']").each { |s| s["class"] = v }
|
36
|
+
end
|
37
|
+
docxml.xpath("//h1[@class = 'ForewordTitle' or @class = 'IntroTitle']")
|
38
|
+
.each { |h| h.name = "p" }
|
39
|
+
dis_styles1(docxml)
|
40
|
+
docxml.xpath("//p[not(@class)]").each { |p| p["class"] = "MsoBodyText" }
|
41
|
+
end
|
42
|
+
|
43
|
+
def dis_styles1(docxml)
|
44
|
+
amd_style(docxml)
|
45
|
+
code_style(docxml)
|
46
|
+
figure_style(docxml)
|
47
|
+
note_style(docxml)
|
48
|
+
example_style(docxml)
|
49
|
+
quote_style(docxml)
|
50
|
+
dis_style_interactions(docxml)
|
51
|
+
end
|
52
|
+
|
53
|
+
def dis_style_interactions(docxml)
|
54
|
+
docxml.xpath("//p[@class = 'Code' or @class = 'Code-' or "\
|
55
|
+
"@class = 'Code--']"\
|
56
|
+
"[following::p[@class = 'Examplecontinued']]").each do |p|
|
57
|
+
p["style"] ||= ""
|
58
|
+
p["style"] = "margin-bottom:12pt;#{p['style']}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def amd_style(docxml)
|
63
|
+
return unless @meta.get[:doctype] == "Amendment"
|
64
|
+
|
65
|
+
docxml.xpath("//div[@class = 'WordSection3']//h1").each do |h|
|
66
|
+
h.name = "p"
|
67
|
+
h["style"] = "font-style:italic;page-break-after:avoid;"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def quote_style(docxml)
|
72
|
+
docxml.xpath("//div[@class = 'Quote' or @class = 'Note' or "\
|
73
|
+
"@class = 'Example' or @class = 'Admonition']").each do |d|
|
74
|
+
quote_style1(d)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def para_style_change(div, class1, class2)
|
79
|
+
s = class1 ? "@class = '#{class1}'" : "not(@class)"
|
80
|
+
div.xpath(".//p[#{s}]").each do |p|
|
81
|
+
p["class"] = class2
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def quote_style1(div)
|
86
|
+
para_style_change(div, nil, "BodyTextindent1")
|
87
|
+
para_style_change(div, "Code-", "Code--")
|
88
|
+
para_style_change(div, "Code", "Code-")
|
89
|
+
if div["class"] != "Example"
|
90
|
+
para_style_change(div, "Example", "Exampleindent")
|
91
|
+
para_style_change(div, "Examplecontinued", "Exampleindentcontinued")
|
92
|
+
end
|
93
|
+
if div["class"] != "Note"
|
94
|
+
para_style_change(div, "Note", "Noteindent")
|
95
|
+
para_style_change(div, "Notecontinued", "Noteindentcontinued")
|
96
|
+
end
|
97
|
+
div.xpath(".//table[@class = 'dl']").each do |t|
|
98
|
+
t["style"] = "margin-left: 1cm;"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def remove_note_label(doc)
|
103
|
+
doc.xpath("//span[@class = 'note_label' or @class = 'example_label']")
|
104
|
+
.each do |s|
|
105
|
+
s.replace(s.children)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def note_style(docxml)
|
110
|
+
remove_note_label(docxml)
|
111
|
+
note_continued_style(docxml)
|
112
|
+
end
|
113
|
+
|
114
|
+
def example_style(docxml)
|
115
|
+
example_continued_style(docxml)
|
116
|
+
end
|
117
|
+
|
118
|
+
def example_continued_style(docxml)
|
119
|
+
docxml.xpath("//div[@class = 'Example']").each do |d|
|
120
|
+
d.xpath("./p").each_with_index do |p, i|
|
121
|
+
next if p["class"] && p["class"] != "Example"
|
122
|
+
|
123
|
+
p["class"] = (i.zero? ? "Example" : "Examplecontinued")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def note_continued_style(docxml)
|
129
|
+
docxml.xpath("//div[@class = 'Note']").each do |d|
|
130
|
+
d.xpath("./p").each_with_index do |p, i|
|
131
|
+
next if p["class"] && p["class"] != "Note"
|
132
|
+
|
133
|
+
p["class"] = (i.zero? ? "Note" : "Notecontinued")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
FIGURE_NESTED_STYLES =
|
139
|
+
{ Note: "Figurenote", example: "Figureexample" }.freeze
|
140
|
+
|
141
|
+
def figure_style(docxml)
|
142
|
+
docxml.xpath("//div[@class = 'figure']").each do |f|
|
143
|
+
FIGURE_NESTED_STYLES.each do |k, v|
|
144
|
+
f.xpath(".//*[@class = '#{k}']").each { |n| n["class"] = v }
|
145
|
+
end
|
146
|
+
f.xpath("./img").each do |i|
|
147
|
+
i.replace("<p class='FigureGraphic'>#{i.to_xml}</p>")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def code_style(doc)
|
153
|
+
span_style((doc.xpath("//tt//b") - doc.xpath("//tt//i//b")),
|
154
|
+
"ISOCodebold")
|
155
|
+
span_style((doc.xpath("//tt//i") - doc.xpath("//tt//b//i")),
|
156
|
+
"ISOCodeitalic")
|
157
|
+
span_style((doc.xpath("//b//tt") - doc.xpath("//b//i//tt")),
|
158
|
+
"ISOCodebold")
|
159
|
+
span_style((doc.xpath("//i//tt") - doc.xpath("//i//b//tt")),
|
160
|
+
"ISOCodeitalic")
|
161
|
+
span_style(doc.xpath("//tt"), "ISOCode")
|
162
|
+
end
|
163
|
+
|
164
|
+
def span_style(xpath, style)
|
165
|
+
xpath.each do |elem|
|
166
|
+
elem.name = "span"
|
167
|
+
elem["class"] = style
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def word_annex_cleanup1(docxml, lvl)
|
172
|
+
docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
|
173
|
+
h2.name = "p"
|
174
|
+
h2["class"] = "a#{lvl}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def word_cleanup(docxml)
|
179
|
+
word_table_cell_para(docxml)
|
180
|
+
super
|
181
|
+
word_section_end_empty_para(docxml)
|
182
|
+
docxml
|
183
|
+
end
|
184
|
+
|
185
|
+
def authority_cleanup(docxml)
|
186
|
+
super
|
187
|
+
if @meta.get[:stage_int].to_s[0] == "9" ||
|
188
|
+
@meta.get[:stage_int].to_s[0] == "6"
|
189
|
+
copyright_prf(docxml)
|
190
|
+
else
|
191
|
+
copyright_dis(docxml)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def copyright_prf(docxml)
|
196
|
+
docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
|
197
|
+
p["class"] = "zzCopyright"
|
198
|
+
p["style"] = "text-indent:20.15pt;"
|
199
|
+
p.replace(p.to_xml.gsub(%r{<br/>}, "</p>\n<p class='zzCopyright' "\
|
200
|
+
"style='text-indent:20.15pt;'>"))
|
201
|
+
end
|
202
|
+
docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
|
203
|
+
# p["class"] = "zzCopyright"
|
204
|
+
p.remove
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def copyright_dis(docxml)
|
209
|
+
docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
|
210
|
+
p["class"] = "zzCopyright"
|
211
|
+
p.replace(p.to_xml.gsub(%r{<br/>}, "</p>\n<p class='zzCopyright'>"))
|
212
|
+
end
|
213
|
+
docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
|
214
|
+
p.remove
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def word_section_end_empty_para(docxml)
|
219
|
+
docxml.at("//div[@class='WordSection1']/p[last()]").remove
|
220
|
+
end
|
221
|
+
|
222
|
+
def word_table_cell_para(docxml)
|
223
|
+
docxml.xpath("//td | //th").each do |t|
|
224
|
+
s = t["header"] == "true" ? "Tableheader" : "Tablebody"
|
225
|
+
t.delete("header")
|
226
|
+
if t.at("./p |./div")
|
227
|
+
t.xpath("./p | ./div").each { |p| p["class"] = s }
|
228
|
+
else
|
229
|
+
t.children = "<div class='#{s}'>#{t.children.to_xml}</div>"
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def make_FigureWordToC(docxml)
|
235
|
+
super.sub(/FigureTitle,figuretitle/, "Figure title,Annex Figure Title")
|
236
|
+
end
|
237
|
+
|
238
|
+
def make_TableWordToC(docxml)
|
239
|
+
super.sub(/TableTitle,tabletitle/, "Table title,Annex Table Title")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|