metanorma-itu 1.2.0 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,12 @@ module IsoDoc
23
23
  main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
24
24
  "[@type = 'subtitle']"))&.text
25
25
  set(:docsubtitle, main)
26
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
27
+ "[@type = 'amendment']"))&.text
28
+ set(:amendmenttitle, main)
29
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
30
+ "[@type = 'corrigendum']"))&.text
31
+ set(:corrigendumtitle, main)
26
32
  series = isoxml&.at(ns("//bibdata/series[@type='main']/title"))&.text
27
33
  set(:series, series)
28
34
  series1 =
@@ -54,6 +60,10 @@ module IsoDoc
54
60
  oblig = isoxml&.at(ns("//annex/@obligation"))&.text
55
61
  lbl = oblig == "informative" ? @labels["appendix"] : @labels["annex"]
56
62
  dn and set(:annexid, @i18n.l10n("#{lbl} #{dn&.text}"))
63
+ dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/amendment")) and
64
+ set(:amendmentid, @i18n.l10n("#{@labels["amendment"]} #{dn&.text}"))
65
+ dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/corrigendum")) and
66
+ set(:corrigendumid, @i18n.l10n("#{@labels["corrigendum"]} #{dn&.text}"))
57
67
  end
58
68
 
59
69
  def unpublished(status)
@@ -48,6 +48,14 @@ module IsoDoc
48
48
  node.add_child(link)
49
49
  end
50
50
 
51
+ def bibdata_i18n(b)
52
+ super
53
+ dn = b.at(ns("./ext/structuredidentifier/amendment")) and
54
+ dn.children = @i18n.l10n("#{@i18n.get["amendment"]} #{dn&.text}")
55
+ dn = b.at(ns("./ext/structuredidentifier/corrigendum")) and
56
+ dn.children = @i18n.l10n("#{@i18n.get["corrigendum"]} #{dn&.text}")
57
+ end
58
+
51
59
  include Init
52
60
  end
53
61
  end
@@ -0,0 +1,152 @@
1
+ module IsoDoc
2
+ module ITU
3
+ class WordConvert < IsoDoc::WordConvert
4
+ def word_preface_cleanup(docxml)
5
+ docxml.xpath("//h1[@class = 'AbstractTitle'] | "\
6
+ "//h1[@class = 'IntroTitle']").each do |h2|
7
+ h2.name = "p"
8
+ h2["class"] = "h1Preface"
9
+ end
10
+ end
11
+
12
+ def word_term_cleanup(docxml)
13
+ end
14
+
15
+ def word_cleanup(docxml)
16
+ word_footnote_cleanup(docxml)
17
+ word_title_cleanup(docxml)
18
+ word_preface_cleanup(docxml)
19
+ word_term_cleanup(docxml)
20
+ word_history_cleanup(docxml)
21
+ authority_hdr_cleanup(docxml)
22
+ table_list_style(docxml)
23
+ super
24
+ docxml
25
+ end
26
+
27
+ def word_footnote_cleanup(docxml)
28
+ docxml.xpath("//aside").each do |a|
29
+ a.first_element_child.children.first.previous =
30
+ '<span style="mso-tab-count:1"/>'
31
+ end
32
+ end
33
+
34
+ def word_title_cleanup(docxml)
35
+ docxml.xpath("//p[@class = 'annex_obligation']").each do |h|
36
+ h&.next_element&.name == "p" or next
37
+ h.next_element["class"] ||= "Normalaftertitle"
38
+ end
39
+ docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
40
+ h&.parent&.next_element&.name == "p" or next
41
+ h.parent.next_element["class"] ||= "Normalaftertitle"
42
+ end
43
+ end
44
+
45
+ def word_history_cleanup(docxml)
46
+ docxml.xpath("//div[@id='_history']//table").each do |t|
47
+ t["class"] = "MsoNormalTable"
48
+ t.xpath(".//td").each { |td| td["style"] = nil }
49
+ end
50
+ end
51
+
52
+ def word_preface(docxml)
53
+ super
54
+ abstractbox = docxml.at("//div[@id='abstractbox']")
55
+ historybox = docxml.at("//div[@id='historybox']")
56
+ sourcebox = docxml.at("//div[@id='sourcebox']")
57
+ keywordsbox = docxml.at("//div[@id='keywordsbox']")
58
+ abstract = docxml.at("//div[@class = 'Abstract']")
59
+ history = docxml.at("//div[@class = 'history']")
60
+ source = docxml.at("//div[@class = 'source']")
61
+ keywords = docxml.at("//div[@class = 'Keywords']")
62
+ abstract.parent = abstractbox if abstract && abstractbox
63
+ history.parent = historybox if history && historybox
64
+ source.parent = sourcebox if source && sourcebox
65
+ keywords.parent = keywordsbox if keywords && keywordsbox
66
+ end
67
+
68
+ def toWord(result, filename, dir, header)
69
+ result = populate_template(result, :word)
70
+ result = from_xhtml(word_cleanup(to_xhtml(result)))
71
+ unless @landscapestyle.nil? || @landscapestyle.empty?
72
+ @wordstylesheet&.open
73
+ @wordstylesheet&.write(@landscapestyle)
74
+ @wordstylesheet&.close
75
+ end
76
+ Html2Doc.process(
77
+ result, filename: filename,
78
+ stylesheet: @wordstylesheet&.path,
79
+ header_file: header&.path, dir: dir,
80
+ asciimathdelims: [@openmathdelim, @closemathdelim],
81
+ liststyles: { ul: @ulstyle, ol: @olstyle, steps: "l4" })
82
+ header&.unlink
83
+ @wordstylesheet&.unlink
84
+ end
85
+
86
+ def authority_hdr_cleanup(docxml)
87
+ docxml&.xpath("//div[@id = 'draft-warning']").each do |d|
88
+ d.xpath(".//h1 | .//h2").each do |p|
89
+ p.name = "p"
90
+ p["class"] = "draftwarningHdr"
91
+ end
92
+ end
93
+ %w(copyright license legal).each do |t|
94
+ docxml&.xpath("//div[@class = 'boilerplate-#{t}']").each do |d|
95
+ p = d&.at("./descendant::h1[2]") and
96
+ p.previous = "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
97
+ d.xpath(".//h1 | .//h2").each do |p|
98
+ p.name = "p"
99
+ p["class"] = "boilerplateHdr"
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ def authority_cleanup(docxml)
106
+ dest = docxml.at("//div[@class = 'draft-warning']")
107
+ auth = docxml.at("//div[@id = 'draft-warning']")
108
+ dest and auth and dest.replace(auth.remove)
109
+ %w(copyright license legal).each do |t|
110
+ dest = docxml.at("//div[@id = 'boilerplate-#{t}-destination']")
111
+ auth = docxml.at("//div[@class = 'boilerplate-#{t}']")
112
+ next unless auth && dest
113
+ t == "copyright" and p = auth&.at(".//p") and
114
+ p["class"] = "boilerplateHdr"
115
+ auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
116
+ p["class"] = "boilerplate"
117
+ #i == 0 && t == "copyright" and p["style"] = "text-align:center;"
118
+ end
119
+ t == "copyright" or
120
+ auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
121
+ dest.replace(auth.remove)
122
+ end
123
+ end
124
+
125
+ TOPLIST = "[not(ancestor::ul) and not(ancestor::ol)]".freeze
126
+
127
+ def table_list_style(xml)
128
+ xml.xpath("//table//ul#{TOPLIST} | //table//ol#{TOPLIST}").each do |t|
129
+ table_list_style1(t, 1)
130
+ end
131
+ end
132
+
133
+ def table_list_style1(t, num)
134
+ (t.xpath(".//li") - t.xpath(".//ol//li | .//ul//li")).each do |t1|
135
+ indent_list(t1, num)
136
+ t1.xpath("./div | ./p").each { |p| indent_list(p, num) }
137
+ (t1.xpath(".//ul") - t1.xpath(".//ul//ul | .//ol//ul")).each do |t2|
138
+ table_list_style1(t2, num + 1)
139
+ end
140
+ (t1.xpath(".//ol") - t1.xpath(".//ul//ol | .//ol//ol")).each do |t2|
141
+ table_list_style1(t2, num + 1)
142
+ end
143
+ end
144
+ end
145
+
146
+ def indent_list(li, num)
147
+ li["style"] = (li["style"] ? li["style"] + ";" : "")
148
+ li["style"] += "margin-left: #{num * 0.5}cm;text-indent: -0.5cm;"
149
+ end
150
+ end
151
+ end
152
+ end
@@ -1,12 +1,10 @@
1
1
  require "isodoc"
2
2
  require_relative "init"
3
+ require_relative "word_cleanup"
3
4
  require "fileutils"
4
5
 
5
6
  module IsoDoc
6
7
  module ITU
7
- # A {Converter} implementation that generates Word output, and a document
8
- # schema encapsulation of the document for validation
9
-
10
8
  class WordConvert < IsoDoc::WordConvert
11
9
  def initialize(options)
12
10
  @libdir = File.dirname(__FILE__)
@@ -27,6 +25,7 @@ module IsoDoc
27
25
  body.div **{ class: "WordSection2" } do |div2|
28
26
  info docxml, div2
29
27
  boilerplate docxml, div2
28
+ preface_block docxml, div2
30
29
  abstract docxml, div2
31
30
  keywords docxml, div2
32
31
  preface docxml, div2
@@ -52,71 +51,6 @@ module IsoDoc
52
51
  end
53
52
  end
54
53
 
55
- def word_preface_cleanup(docxml)
56
- docxml.xpath("//h1[@class = 'AbstractTitle'] | "\
57
- "//h1[@class = 'IntroTitle']").each do |h2|
58
- h2.name = "p"
59
- h2["class"] = "h1Preface"
60
- end
61
- end
62
-
63
- def word_term_cleanup(docxml)
64
- docxml.xpath("//p[@class = 'TermNum']").each do |t|
65
- end
66
- end
67
-
68
- def word_cleanup(docxml)
69
- word_footnote_cleanup(docxml)
70
- word_title_cleanup(docxml)
71
- word_preface_cleanup(docxml)
72
- word_term_cleanup(docxml)
73
- word_history_cleanup(docxml)
74
- authority_hdr_cleanup(docxml)
75
- super
76
- docxml
77
- end
78
-
79
- def word_footnote_cleanup(docxml)
80
- docxml.xpath("//aside").each do |a|
81
- a.first_element_child.children.first.previous =
82
- '<span style="mso-tab-count:1"/>'
83
- end
84
- end
85
-
86
- def word_title_cleanup(docxml)
87
- docxml.xpath("//p[@class = 'annex_obligation']").each do |h|
88
- h&.next_element&.name == "p" or next
89
- h.next_element["class"] ||= "Normalaftertitle"
90
- end
91
- docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
92
- h&.parent&.next_element&.name == "p" or next
93
- h.parent.next_element["class"] ||= "Normalaftertitle"
94
- end
95
- end
96
-
97
- def word_history_cleanup(docxml)
98
- docxml.xpath("//div[@id='_history']//table").each do |t|
99
- t["class"] = "MsoNormalTable"
100
- t.xpath(".//td").each { |td| td["style"] = nil }
101
- end
102
- end
103
-
104
- def word_preface(docxml)
105
- super
106
- abstractbox = docxml.at("//div[@id='abstractbox']")
107
- historybox = docxml.at("//div[@id='historybox']")
108
- sourcebox = docxml.at("//div[@id='sourcebox']")
109
- keywordsbox = docxml.at("//div[@id='keywordsbox']")
110
- abstract = docxml.at("//div[@class = 'Abstract']")
111
- history = docxml.at("//div[@class = 'history']")
112
- source = docxml.at("//div[@class = 'source']")
113
- keywords = docxml.at("//div[@class = 'Keywords']")
114
- abstract.parent = abstractbox if abstract && abstractbox
115
- history.parent = historybox if history && historybox
116
- source.parent = sourcebox if source && sourcebox
117
- keywords.parent = keywordsbox if keywords && keywordsbox
118
- end
119
-
120
54
  def formula_parse1(node, out)
121
55
  out.div **attr_code(class: "formula") do |div|
122
56
  div.p **attr_code(class: "formula") do |p|
@@ -156,24 +90,6 @@ module IsoDoc
156
90
  { class: node["class"], id: node["id"], style: keep_style(node) }
157
91
  end
158
92
 
159
- def toWord(result, filename, dir, header)
160
- result = populate_template(result, :word)
161
- result = from_xhtml(word_cleanup(to_xhtml(result)))
162
- unless @landscapestyle.nil? || @landscapestyle.empty?
163
- @wordstylesheet&.open
164
- @wordstylesheet&.write(@landscapestyle)
165
- @wordstylesheet&.close
166
- end
167
- Html2Doc.process(result, filename: filename,
168
- stylesheet: @wordstylesheet&.path,
169
- header_file: header&.path, dir: dir,
170
- asciimathdelims: [@openmathdelim, @closemathdelim],
171
- liststyles: { ul: @ulstyle, ol: @olstyle,
172
- steps: "l4" })
173
- header&.unlink
174
- @wordstylesheet&.unlink
175
- end
176
-
177
93
  def link_parse(node, out)
178
94
  out.a **attr_code(href: node["target"], title: node["alt"],
179
95
  class: "url") do |l|
@@ -185,45 +101,6 @@ module IsoDoc
185
101
  end
186
102
  end
187
103
 
188
- def authority_hdr_cleanup(docxml)
189
- docxml&.xpath("//div[@id = 'draft-warning']").each do |d|
190
- d.xpath(".//h1 | .//h2").each do |p|
191
- p.name = "p"
192
- p["class"] = "draftwarningHdr"
193
- end
194
- end
195
- %w(copyright license legal).each do |t|
196
- docxml&.xpath("//div[@class = 'boilerplate-#{t}']").each do |d|
197
- p = d&.at("./descendant::h1[2]") and
198
- p.previous = "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
199
- d.xpath(".//h1 | .//h2").each do |p|
200
- p.name = "p"
201
- p["class"] = "boilerplateHdr"
202
- end
203
- end
204
- end
205
- end
206
-
207
- def authority_cleanup(docxml)
208
- dest = docxml.at("//div[@class = 'draft-warning']")
209
- auth = docxml.at("//div[@id = 'draft-warning']")
210
- dest and auth and dest.replace(auth.remove)
211
- %w(copyright license legal).each do |t|
212
- dest = docxml.at("//div[@id = 'boilerplate-#{t}-destination']")
213
- auth = docxml.at("//div[@class = 'boilerplate-#{t}']")
214
- next unless auth && dest
215
- t == "copyright" and p = auth&.at(".//p") and
216
- p["class"] = "boilerplateHdr"
217
- auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
218
- p["class"] = "boilerplate"
219
- #i == 0 && t == "copyright" and p["style"] = "text-align:center;"
220
- end
221
- t == "copyright" or
222
- auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
223
- dest.replace(auth.remove)
224
- end
225
- end
226
-
227
104
  def clause_attrs(node)
228
105
  ret = {}
229
106
  %w(source history).include?(node["type"]) and
@@ -20,7 +20,7 @@ module IsoDoc
20
20
  @labels["appendix"] : @labels["annex"]
21
21
  @anchors[clause["id"]] =
22
22
  { label: annex_name_lbl(clause, num), type: "clause",
23
- xref: "#{lbl} #{num}", level: 1 }
23
+ xref: "#{lbl} #{num}", level: 1, value: num }
24
24
  if a = single_annex_special_section(clause)
25
25
  annex_names1(a, "#{num}", 1)
26
26
  else
@@ -101,7 +101,7 @@ module IsoDoc
101
101
  j = 0
102
102
  c.increment(t)
103
103
  end
104
- label = c.print + (j.zero? ? "" : "-#{(96 + j).chr.to_s}")
104
+ label = c.print + (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
105
105
  next if t["id"].nil? || t["id"].empty?
106
106
  @anchors[t["id"]] =
107
107
  anchor_struct(label, nil, @labels["figure"], "figure", t["unnumbered"])
@@ -164,6 +164,7 @@ module IsoDoc
164
164
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
165
165
  @anchors[n["id"]] =
166
166
  { label: termnote_label(idx).strip, type: "termnote",
167
+ value: idx,
167
168
  xref: l10n("#{anchor(t['id'], :xref)}, "\
168
169
  "#{@labels["note_xref"]} #{c.print}") }
169
170
 
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ITU
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.5"
4
4
  end
5
5
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "htmlentities", "~> 4.3.4"
28
28
  spec.add_dependency "ruby-jing"
29
- spec.add_dependency "metanorma-standoc", "~> 1.5.0"
29
+ spec.add_dependency "metanorma-standoc", "~> 1.6.0"
30
30
  spec.add_dependency "isodoc", "~> 1.2.0"
31
31
 
32
32
  spec.add_development_dependency "byebug", "~> 9.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-itu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.5.0
47
+ version: 1.6.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.5.0
54
+ version: 1.6.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: isodoc
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -301,6 +301,7 @@ files:
301
301
  - lib/isodoc/itu/presentation_xml_convert.rb
302
302
  - lib/isodoc/itu/ref.rb
303
303
  - lib/isodoc/itu/terms.rb
304
+ - lib/isodoc/itu/word_cleanup.rb
304
305
  - lib/isodoc/itu/word_convert.rb
305
306
  - lib/isodoc/itu/xref.rb
306
307
  - lib/metanorma-itu.rb