Class: IsoDoc::Iso::WordConvert
- Inherits:
-
WordConvert
- Object
- WordConvert
- IsoDoc::Iso::WordConvert
show all
- Includes:
- BaseConvert, Init
- Defined in:
- lib/isodoc/iso/word_cleanup.rb,
lib/isodoc/iso/word_convert.rb
Constant Summary
collapse
- STYLESMAP =
{
example: "Example",
note: "Note",
Sourcecode: "Code",
tabletitle: "Tabletitle",
Biblio: "MsoNormal",
figure: "MsoNormal",
SourceTitle: "FigureTitle",
}.freeze
- MAIN_ELEMENTS =
"//sections/*[@displayorder] | //annex[@displayorder] | " \
"//bibliography/*[@displayorder]".freeze
Instance Method Summary
collapse
-
#annex_name(_annex, name, div) ⇒ Object
-
#annex_name1(name, out) ⇒ Object
-
#authority_cleanup(docxml) ⇒ Object
-
#authority_copyright_cleanup(docxml) ⇒ Object
-
#authority_copyright_populate(doc, auth) ⇒ Object
-
#authority_copyright_style(auth) ⇒ Object
-
#authority_hdr_cleanup(docxml) ⇒ Object
-
#authority_license_cleanup(docxml) ⇒ Object
-
#bibliography(node, out) ⇒ Object
-
#bibliography_attrs ⇒ Object
-
#bibliography_parse(node, out) ⇒ Object
-
#br(out, pagebreak) ⇒ Object
-
#colophon_section(_isoxml, out) ⇒ Object
-
#convert(input_filename, file = nil, debug = false, output_filename = nil) ⇒ Object
-
#default_file_locations(options) ⇒ Object
-
#default_fonts(options) ⇒ Object
-
#definition_parse(node, out) ⇒ Object
-
#figure_cleanup(xml) ⇒ Object
-
#figure_name_attrs(node) ⇒ Object
-
#figure_name_parse(node, div, name) ⇒ Object
-
#figure_style(docxml) ⇒ Object
-
#font_choice(options) ⇒ Object
-
#index_cleanup(docxml) ⇒ Object
-
#indexsect(elem, out) ⇒ Object
-
#indexsect_section(isoxml, out) ⇒ Object
-
#indexsect_title(clause, out) ⇒ Object
-
#init_dis(opt) ⇒ Object
-
#initialize(options) ⇒ WordConvert
constructor
A new instance of WordConvert.
-
#make_body(xml, docxml) ⇒ Object
-
#make_WordToC(docxml, level) ⇒ Object
supply missing annex title.
-
#new_styles(docxml) ⇒ Object
-
#para_class(node) ⇒ Object
-
#quote_style(docxml) ⇒ Object
-
#quote_style1(div) ⇒ Object
-
#sourcecode_style ⇒ Object
-
#style_cleanup(docxml) ⇒ Object
-
#table_attrs(node) ⇒ Object
-
#table_parse(node, out) ⇒ Object
-
#table_parse_tail(node, out) ⇒ Object
-
#table_title_attrs(node) ⇒ Object
-
#table_title_parse(node, out) ⇒ Object
-
#termref_attrs ⇒ Object
-
#termref_parse(node, out) ⇒ Object
-
#use_dis?(input_filename, file) ⇒ Boolean
-
#word_annex_cleanup(docxml) ⇒ Object
-
#word_annex_cleanup1(docxml, lvl) ⇒ Object
-
#word_annex_cleanup_h1(docxml) ⇒ Object
-
#word_cleanup(docxml) ⇒ Object
-
#word_toc_preface(level) ⇒ Object
Methods included from Init
#amd?, #bibrenderer, #clausedelim, #i18n_conditional_set, #i18n_init, #metadata_init, #requirements_processor, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #update_i18n, #xref_init
#admonition_class, #admonition_name_para_delim, #admonition_p_parse, #annex, #clause_etc1, #cleanup, #convert1, #convert_i18n_init, #error_parse, #example_p_class, #example_p_parse, #example_parse, #example_parse1, #example_span_label, #figure_parse1, #foreword, #measurement_units, #ol_attrs, #span_parse, #table_cleanup, #table_th_center, #top_element_render
Constructor Details
#initialize(options) ⇒ WordConvert
Returns a new instance of WordConvert.
10
11
12
13
14
|
# File 'lib/isodoc/iso/word_convert.rb', line 10
def initialize(options)
@libdir = File.dirname(__FILE__)
super
init_dis(options)
end
|
Instance Method Details
#annex_name(_annex, name, div) ⇒ Object
200
201
202
203
204
205
206
207
|
# File 'lib/isodoc/iso/word_convert.rb', line 200
def annex_name(_annex, name, div)
name.nil? and return
name&.at(ns(".//strong"))&.remove div.h1 class: "Annex" do |t|
annex_name1(name, t)
clause_parse_subtitle(name, t)
end
end
|
#annex_name1(name, out) ⇒ Object
209
210
211
212
213
214
215
216
|
# File 'lib/isodoc/iso/word_convert.rb', line 209
def annex_name1(name, out)
n = name.dup
n.xpath(ns(".//span[@class = 'fmt-obligation']")).each do |s|
s.delete("class")
s["style"] = "font-weight:normal;"
end
children_parse(n, out)
end
|
#authority_cleanup(docxml) ⇒ Object
112
113
114
115
116
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 112
def authority_cleanup(docxml)
authority_license_cleanup(docxml)
authority_copyright_cleanup(docxml)
coverpage_note_cleanup(docxml)
end
|
#authority_copyright_cleanup(docxml) ⇒ Object
118
119
120
121
122
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 118
def authority_copyright_cleanup(docxml)
auth = docxml.at("//div[@class = 'boilerplate-copyright']") or return
authority_copyright_style(auth)
authority_copyright_populate(docxml, auth)
end
|
#authority_copyright_populate(doc, auth) ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 137
def authority_copyright_populate(doc, auth)
i = doc.at("//div[@id = 'boilerplate-copyright-default-destination']")
j = doc.at("//div[@id = 'boilerplate-copyright-append-destination']")
default = auth.at(".//div[@id = 'boilerplate-copyright-default']")
default and i and i.children = default.remove
j and j.children = auth.remove
end
|
#authority_copyright_style(auth) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 124
def authority_copyright_style(auth)
auth.xpath(".//p[not(@class)]").each { |p| p["class"] = "zzCopyright" }
auth.xpath(".//p[@id = 'boilerplate-message']").each do |p|
p["class"] = "zzCopyright1"
end
auth.xpath(".//p[@id = 'boilerplate-address']").each do |p|
p["class"] = "zzAddress"
end
auth.xpath(".//p[@id = 'boilerplate-place']").each do |p|
p["class"] = "zzCopyright1"
end
end
|
#authority_hdr_cleanup(docxml) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 100
def authority_hdr_cleanup(docxml)
{ "boilerplate-license": "zzWarningHdr",
"boilerplate-copyright": "zzCopyrightHdr" }.each do |k, v|
docxml.xpath("//div[@class = '#{k}']").each do |d|
d.xpath(".//h1").each do |p|
p.name = "p"
p["class"] = v
end
end
end
end
|
#authority_license_cleanup(docxml) ⇒ Object
145
146
147
148
149
150
151
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 145
def authority_license_cleanup(docxml)
dest = docxml.at("//div[@id = 'boilerplate-license-destination']") or
return
auth = docxml.at("//div[@class = 'boilerplate-license']") or return
auth.xpath(".//p[not(@class)]").each { |p| p["class"] = "zzWarning" }
dest.children = auth.remove
end
|
#bibliography(node, out) ⇒ Object
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/isodoc/iso/word_convert.rb', line 133
def bibliography(node, out)
node["hidden"] != "true" or return
page_break(out)
out.div do |div|
div.h1 **bibliography_attrs do |h1|
node&.at(ns("./fmt-title"))&.children&.each { |c2| parse(c2, h1) }
end
biblio_list(node, div, true)
end
end
|
#bibliography_attrs ⇒ Object
129
130
131
|
# File 'lib/isodoc/iso/word_convert.rb', line 129
def bibliography_attrs
{ class: "BiblioTitle" }
end
|
#bibliography_parse(node, out) ⇒ Object
144
145
146
147
148
149
150
151
|
# File 'lib/isodoc/iso/word_convert.rb', line 144
def bibliography_parse(node, out)
node["hidden"] != true or return
out.div do |div|
clause_parse_title(node, div, node.at(ns("./fmt-title")), out,
bibliography_attrs)
biblio_list(node, div, true)
end
end
|
#br(out, pagebreak) ⇒ Object
80
81
82
83
|
# File 'lib/isodoc/iso/word_convert.rb', line 80
def br(out, pagebreak)
out.br clear: "all", style: "page-break-before:#{pagebreak};" \
"mso-break-type:section-break"
end
|
#colophon_section(_isoxml, out) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/isodoc/iso/word_convert.rb', line 89
def colophon_section(_isoxml, out)
stage = @meta.get[:stage_int]
!stage.nil? && stage < 60 and return
br(out, "left")
out.div class: "colophon" do |div|
end
end
|
#convert(input_filename, file = nil, debug = false, output_filename = nil) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/isodoc/iso/word_convert.rb', line 52
def convert(input_filename, file = nil, debug = false,
output_filename = nil)
if @dis && use_dis?(input_filename, file)
swap_renderer(self, @dis, file, input_filename, debug)
@dis.convert(input_filename, file, debug, output_filename)
else super
end
end
|
#default_file_locations(options) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/iso/word_convert.rb', line 38
def default_file_locations(options)
a = options[:alt] ? "style-human.scss" : "style-iso.scss"
{ htmlstylesheet: html_doc_path(a),
htmlcoverpage: html_doc_path("html_iso_titlepage.html"),
htmlintropage: html_doc_path("html_iso_intro.html"),
wordstylesheet: html_doc_path("wordstyle.scss"),
standardstylesheet: html_doc_path("isodoc.scss"),
header: html_doc_path("header.html"),
wordcoverpage: html_doc_path("word_iso_titlepage.html"),
wordintropage: html_doc_path("word_iso_intro.html"),
ulstyle: "l3",
olstyle: "l2" }
end
|
#default_fonts(options) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/isodoc/iso/word_convert.rb', line 28
def default_fonts(options)
{ bodyfont: font_choice(options),
headerfont: font_choice(options),
monospacefont: '"Courier New",monospace',
normalfontsize: "11.0pt",
monospacefontsize: "9.0pt",
smallerfontsize: "10.0pt",
footnotefontsize: "10.0pt" }
end
|
#definition_parse(node, out) ⇒ Object
153
154
155
156
157
|
# File 'lib/isodoc/iso/word_convert.rb', line 153
def definition_parse(node, out)
@definition = true
super
@definition = false
end
|
4
5
6
7
8
9
10
11
12
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 4
def figure_cleanup(xml)
super
xml.xpath("//div[@class = 'figure']//table[@class = 'dl']").each do |t|
t["class"] = "figdl"
d = t.add_previous_sibling("<div class='figdl' " \
"style='page-break-after:avoid;'/>")
t.parent = d.first
end
end
|
176
177
178
179
|
# File 'lib/isodoc/iso/word_convert.rb', line 176
def figure_name_attrs(node)
s = node.ancestors("annex").empty? ? "FigureTitle" : "AnnexFigureTitle"
{ class: s, style: "text-align:center;" }
end
|
181
182
183
184
185
186
|
# File 'lib/isodoc/iso/word_convert.rb', line 181
def figure_name_parse(node, div, name)
name.nil? and return
div.p **figure_name_attrs(node) do |p|
name.children.each { |n| parse(n, p) }
end
end
|
53
54
55
56
57
58
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 53
def figure_style(docxml)
docxml.xpath("//div[@class = 'figure']").each do |f|
f["style"] ||= ""
f["style"] += "text-align:center;"
end
end
|
#font_choice(options) ⇒ Object
23
24
25
26
|
# File 'lib/isodoc/iso/word_convert.rb', line 23
def font_choice(options)
options[:script] == "Hans" and return '"Source Han Sans",serif'
'"Cambria",serif'
end
|
#index_cleanup(docxml) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 44
def index_cleanup(docxml)
docxml.xpath("//div[@class = 'index']").each do |i|
i.xpath(".//p | .//li").each do |p|
p["style"] ||= ""
p["style"] += "margin-bottom:0px;"
end
end
end
|
#indexsect(elem, out) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/isodoc/iso/word_convert.rb', line 101
def indexsect(elem, out)
indexsect_title(elem, out)
br(out, "auto")
out.div class: "index" do |div|
elem.children.each do |e|
parse(e, div) unless e.name == "fmt-title"
end
end
end
|
#indexsect_section(isoxml, out) ⇒ Object
97
98
99
|
# File 'lib/isodoc/iso/word_convert.rb', line 97
def indexsect_section(isoxml, out)
isoxml.xpath(ns("//indexsect")).each { |i| indexsect(i, out) }
end
|
#indexsect_title(clause, out) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/isodoc/iso/word_convert.rb', line 111
def indexsect_title(clause, out)
br(out, "always")
out.div class: "WordSection3" do |div|
clause_name(clause, clause.at(ns("./fmt-title")), div, nil)
end
end
|
#init_dis(opt) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/isodoc/iso/word_convert.rb', line 16
def init_dis(opt)
@wordtemplate = opt[:isowordtemplate]
opt[:isowordbgstripcolor] ||= "true"
@dis = ::IsoDoc::Iso::WordDISConvert.new(opt)
@dis.bgstripcolor = opt[:isowordbgstripcolor]
end
|
#make_body(xml, docxml) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/isodoc/iso/word_convert.rb', line 69
def make_body(xml, docxml)
body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
xml.body **body_attr do |body|
make_body1(body, docxml)
make_body2(body, docxml)
make_body3(body, docxml)
indexsect_section(docxml, body)
colophon_section(docxml, body)
end
end
|
#make_WordToC(docxml, level) ⇒ Object
supply missing annex title
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 161
def make_WordToC(docxml, level)
toc = ""
s = docxml.at("//div[@class = 'TOC']") and toc = to_xml(s.children)
xpath = (1..level).each.map { |i| "//h#{i}" }.join (" | ")
docxml.xpath(xpath).each do |h|
x = ""
x = @anchor[h.parent["id"]][:xref] if h["class"] == "ANNEX"
toc += word_toc_entry(h.name[1].to_i, x + (h))
end
toc.sub(/(<p class="MsoToc1">)/,
%{\\1#{word_toc_preface(level)}}) + WORD_TOC_SUFFIX1
end
|
#new_styles(docxml) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 88
def new_styles(docxml)
self.class::STYLESMAP.each do |k, v|
docxml.xpath("//*[@class = '#{k}']").each { |s| s["class"] = v }
end
docxml.xpath("//div[@class = 'Section3']//p[@class = 'Tabletitle']")
.each { |t| t["class"] = "AnnexTableTitle" }
docxml.xpath("//*[@class = 'zzHelp']/p[not(@class)]").each do |p|
p["class"] = "zzHelp"
end
quote_style(docxml)
end
|
#para_class(node) ⇒ Object
159
160
161
162
163
164
|
# File 'lib/isodoc/iso/word_convert.rb', line 159
def para_class(node)
if @definition && !@in_footnote then "Definition"
elsif @foreword && !@in_footnote then "ForewordText"
else super
end
end
|
#quote_style(docxml) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 60
def quote_style(docxml)
docxml.xpath("//div[@class = 'Quote' or @class = 'Note' or " \
"@class = 'Example' or @class = 'Admonition']").each do |d|
quote_style1(d)
end
end
|
#quote_style1(div) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 67
def quote_style1(div)
div.xpath(".//li").each do |p|
p["style"] ||= ""
p["style"] += "font-size:#{default_fonts({})[:smallerfontsize]};"
end
end
|
#sourcecode_style ⇒ Object
74
75
76
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 74
def sourcecode_style
"Code"
end
|
#style_cleanup(docxml) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 37
def style_cleanup(docxml)
word_annex_cleanup_h1(docxml)
figure_style(docxml)
new_styles(docxml)
index_cleanup(docxml)
end
|
#table_attrs(node) ⇒ Object
218
219
220
221
222
|
# File 'lib/isodoc/iso/word_convert.rb', line 218
def table_attrs(node)
ret = super
node["class"] == "modspec" and ret[:width] = "100%"
ret
end
|
#table_parse(node, out) ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/isodoc/iso/word_convert.rb', line 224
def table_parse(node, out)
@in_table = true
table_title_parse(node, out)
measurement_units(node, out)
out.div align: "center", class: "table_container" do |div|
div.table **table_attrs(node) do |t|
table_parse_core(node, t)
table_parse_tail(node, t)
end
end
@in_table = false
end
|
#table_parse_tail(node, out) ⇒ Object
237
238
239
240
241
242
243
244
|
# File 'lib/isodoc/iso/word_convert.rb', line 237
def table_parse_tail(node, out)
(dl = node.at(ns("./dl"))) && parse(dl, out)
node.xpath(ns("./source")).each { |n| parse(n, out) }
node.xpath(ns("./note[not(@type = 'units')]"))
.each { |n| parse(n, out) }
node.xpath(ns("./fmt-footnote-container/fmt-fn-body"))
.each { |n| parse(n, out) }
end
|
#table_title_attrs(node) ⇒ Object
188
189
190
191
|
# File 'lib/isodoc/iso/word_convert.rb', line 188
def table_title_attrs(node)
s = node.ancestors("annex").empty? ? "Tabletitle" : "AnnexTableTitle"
{ class: s, style: "text-align:center;" }
end
|
#table_title_parse(node, out) ⇒ Object
193
194
195
196
197
198
|
# File 'lib/isodoc/iso/word_convert.rb', line 193
def table_title_parse(node, out)
name = node.at(ns("./fmt-name")) or return
out.p **table_title_attrs(node) do |p|
name&.children&.each { |n| parse(n, p) }
end
end
|
#termref_attrs ⇒ Object
166
167
168
|
# File 'lib/isodoc/iso/word_convert.rb', line 166
def termref_attrs
{ class: "Source" }
end
|
#termref_parse(node, out) ⇒ Object
170
171
172
173
174
|
# File 'lib/isodoc/iso/word_convert.rb', line 170
def termref_parse(node, out)
out.p **termref_attrs do |p|
node.children.each { |n| parse(n, p) }
end
end
|
#use_dis?(input_filename, file) ⇒ Boolean
61
62
63
64
65
66
67
|
# File 'lib/isodoc/iso/word_convert.rb', line 61
def use_dis?(input_filename, file)
file ||= File.read(input_filename, encoding: "utf-8")
stage = Nokogiri::XML(file, &:huge)
.at(ns("//bibdata/status/stage"))&.text
(/^[4569].$/.match?(stage) && @wordtemplate != "simple") ||
(/^[0-3].$/.match?(stage) && @wordtemplate == "dis")
end
|
#word_annex_cleanup(docxml) ⇒ Object
21
22
23
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 21
def word_annex_cleanup(docxml)
(2..6).each { |i| word_annex_cleanup1(docxml, i) }
end
|
#word_annex_cleanup1(docxml, lvl) ⇒ Object
14
15
16
17
18
19
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 14
def word_annex_cleanup1(docxml, lvl)
docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
h2.name = "p"
h2["class"] = "a#{lvl}"
end
end
|
#word_annex_cleanup_h1(docxml) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 25
def word_annex_cleanup_h1(docxml)
docxml.xpath("//h1[@class = 'Annex']").each do |h|
h.name = "p"
h["class"] = "ANNEX"
end
%w(BiblioTitle ForewordTitle IntroTitle).each do |s|
docxml.xpath("//*[@class = '#{s}']").each do |h|
h.name = "p"
end
end
end
|
#word_cleanup(docxml) ⇒ Object
153
154
155
156
157
158
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 153
def word_cleanup(docxml)
authority_hdr_cleanup(docxml)
super
style_cleanup(docxml)
docxml
end
|
#word_toc_preface(level) ⇒ Object
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/isodoc/iso/word_convert.rb', line 118
def word_toc_preface(level)
<<~TOC.freeze
<span lang="EN-GB"><span
style='mso-element:field-begin'></span><span
style='mso-spacerun:yes'> </span>TOC
\\o "1-#{level}" \\h \\z \\t "Heading
1;1;ANNEX;1;Biblio Title;1;Foreword Title;1;Intro Title;1" <span
style='mso-element:field-separator'></span></span>
TOC
end
|