metanorma-itu 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor/itu/basicdoc.rng +31 -1
- data/lib/asciidoctor/itu/cleanup.rb +1 -1
- data/lib/asciidoctor/itu/isodoc.rng +108 -8
- data/lib/isodoc/itu/html/itu.css +16 -4
- data/lib/isodoc/itu/html/itu.scss +19 -5
- data/lib/isodoc/itu/itu.recommendation-annex.xsl +435 -176
- data/lib/isodoc/itu/itu.recommendation.xsl +435 -176
- data/lib/isodoc/itu/itu.resolution.xsl +435 -176
- data/lib/isodoc/itu/word_cleanup.rb +152 -0
- data/lib/isodoc/itu/word_convert.rb +1 -125
- data/lib/isodoc/itu/xref.rb +1 -1
- data/lib/metanorma/itu/version.rb +1 -1
- metadata +3 -2
@@ -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> </p><p> </p><p> </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> </p><p> </p><p> </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__)
|
@@ -53,71 +51,6 @@ module IsoDoc
|
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
def word_preface_cleanup(docxml)
|
57
|
-
docxml.xpath("//h1[@class = 'AbstractTitle'] | "\
|
58
|
-
"//h1[@class = 'IntroTitle']").each do |h2|
|
59
|
-
h2.name = "p"
|
60
|
-
h2["class"] = "h1Preface"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def word_term_cleanup(docxml)
|
65
|
-
docxml.xpath("//p[@class = 'TermNum']").each do |t|
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def word_cleanup(docxml)
|
70
|
-
word_footnote_cleanup(docxml)
|
71
|
-
word_title_cleanup(docxml)
|
72
|
-
word_preface_cleanup(docxml)
|
73
|
-
word_term_cleanup(docxml)
|
74
|
-
word_history_cleanup(docxml)
|
75
|
-
authority_hdr_cleanup(docxml)
|
76
|
-
super
|
77
|
-
docxml
|
78
|
-
end
|
79
|
-
|
80
|
-
def word_footnote_cleanup(docxml)
|
81
|
-
docxml.xpath("//aside").each do |a|
|
82
|
-
a.first_element_child.children.first.previous =
|
83
|
-
'<span style="mso-tab-count:1"/>'
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def word_title_cleanup(docxml)
|
88
|
-
docxml.xpath("//p[@class = 'annex_obligation']").each do |h|
|
89
|
-
h&.next_element&.name == "p" or next
|
90
|
-
h.next_element["class"] ||= "Normalaftertitle"
|
91
|
-
end
|
92
|
-
docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
|
93
|
-
h&.parent&.next_element&.name == "p" or next
|
94
|
-
h.parent.next_element["class"] ||= "Normalaftertitle"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def word_history_cleanup(docxml)
|
99
|
-
docxml.xpath("//div[@id='_history']//table").each do |t|
|
100
|
-
t["class"] = "MsoNormalTable"
|
101
|
-
t.xpath(".//td").each { |td| td["style"] = nil }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def word_preface(docxml)
|
106
|
-
super
|
107
|
-
abstractbox = docxml.at("//div[@id='abstractbox']")
|
108
|
-
historybox = docxml.at("//div[@id='historybox']")
|
109
|
-
sourcebox = docxml.at("//div[@id='sourcebox']")
|
110
|
-
keywordsbox = docxml.at("//div[@id='keywordsbox']")
|
111
|
-
abstract = docxml.at("//div[@class = 'Abstract']")
|
112
|
-
history = docxml.at("//div[@class = 'history']")
|
113
|
-
source = docxml.at("//div[@class = 'source']")
|
114
|
-
keywords = docxml.at("//div[@class = 'Keywords']")
|
115
|
-
abstract.parent = abstractbox if abstract && abstractbox
|
116
|
-
history.parent = historybox if history && historybox
|
117
|
-
source.parent = sourcebox if source && sourcebox
|
118
|
-
keywords.parent = keywordsbox if keywords && keywordsbox
|
119
|
-
end
|
120
|
-
|
121
54
|
def formula_parse1(node, out)
|
122
55
|
out.div **attr_code(class: "formula") do |div|
|
123
56
|
div.p **attr_code(class: "formula") do |p|
|
@@ -157,24 +90,6 @@ module IsoDoc
|
|
157
90
|
{ class: node["class"], id: node["id"], style: keep_style(node) }
|
158
91
|
end
|
159
92
|
|
160
|
-
def toWord(result, filename, dir, header)
|
161
|
-
result = populate_template(result, :word)
|
162
|
-
result = from_xhtml(word_cleanup(to_xhtml(result)))
|
163
|
-
unless @landscapestyle.nil? || @landscapestyle.empty?
|
164
|
-
@wordstylesheet&.open
|
165
|
-
@wordstylesheet&.write(@landscapestyle)
|
166
|
-
@wordstylesheet&.close
|
167
|
-
end
|
168
|
-
Html2Doc.process(result, filename: filename,
|
169
|
-
stylesheet: @wordstylesheet&.path,
|
170
|
-
header_file: header&.path, dir: dir,
|
171
|
-
asciimathdelims: [@openmathdelim, @closemathdelim],
|
172
|
-
liststyles: { ul: @ulstyle, ol: @olstyle,
|
173
|
-
steps: "l4" })
|
174
|
-
header&.unlink
|
175
|
-
@wordstylesheet&.unlink
|
176
|
-
end
|
177
|
-
|
178
93
|
def link_parse(node, out)
|
179
94
|
out.a **attr_code(href: node["target"], title: node["alt"],
|
180
95
|
class: "url") do |l|
|
@@ -186,45 +101,6 @@ module IsoDoc
|
|
186
101
|
end
|
187
102
|
end
|
188
103
|
|
189
|
-
def authority_hdr_cleanup(docxml)
|
190
|
-
docxml&.xpath("//div[@id = 'draft-warning']").each do |d|
|
191
|
-
d.xpath(".//h1 | .//h2").each do |p|
|
192
|
-
p.name = "p"
|
193
|
-
p["class"] = "draftwarningHdr"
|
194
|
-
end
|
195
|
-
end
|
196
|
-
%w(copyright license legal).each do |t|
|
197
|
-
docxml&.xpath("//div[@class = 'boilerplate-#{t}']").each do |d|
|
198
|
-
p = d&.at("./descendant::h1[2]") and
|
199
|
-
p.previous = "<p> </p><p> </p><p> </p>"
|
200
|
-
d.xpath(".//h1 | .//h2").each do |p|
|
201
|
-
p.name = "p"
|
202
|
-
p["class"] = "boilerplateHdr"
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
def authority_cleanup(docxml)
|
209
|
-
dest = docxml.at("//div[@class = 'draft-warning']")
|
210
|
-
auth = docxml.at("//div[@id = 'draft-warning']")
|
211
|
-
dest and auth and dest.replace(auth.remove)
|
212
|
-
%w(copyright license legal).each do |t|
|
213
|
-
dest = docxml.at("//div[@id = 'boilerplate-#{t}-destination']")
|
214
|
-
auth = docxml.at("//div[@class = 'boilerplate-#{t}']")
|
215
|
-
next unless auth && dest
|
216
|
-
t == "copyright" and p = auth&.at(".//p") and
|
217
|
-
p["class"] = "boilerplateHdr"
|
218
|
-
auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
|
219
|
-
p["class"] = "boilerplate"
|
220
|
-
#i == 0 && t == "copyright" and p["style"] = "text-align:center;"
|
221
|
-
end
|
222
|
-
t == "copyright" or
|
223
|
-
auth << "<p> </p><p> </p><p> </p>"
|
224
|
-
dest.replace(auth.remove)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
104
|
def clause_attrs(node)
|
229
105
|
ret = {}
|
230
106
|
%w(source history).include?(node["type"]) and
|
data/lib/isodoc/itu/xref.rb
CHANGED
@@ -101,7 +101,7 @@ module IsoDoc
|
|
101
101
|
j = 0
|
102
102
|
c.increment(t)
|
103
103
|
end
|
104
|
-
label = c.print + (j.zero? ? "" : "
|
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"])
|
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.
|
4
|
+
version: 1.2.3
|
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-
|
11
|
+
date: 2020-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -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
|