Class: IsoDoc::Iec::WordConvert
- Inherits:
-
IsoDoc::Iso::WordConvert
- Object
- IsoDoc::Iso::WordConvert
- IsoDoc::Iec::WordConvert
show all
- Includes:
- BaseConvert, Init
- Defined in:
- lib/isodoc/iec/word_convert.rb
Constant Summary
collapse
- WORD_TOC_TABLE_PREFACE1 =
<<~TOC.freeze
<span lang="EN-GB"><span
style='mso-element:field-begin'></span><span
style='mso-spacerun:yes'> </span>TOC
\\h \\z \\t "TableTitle,tabletitle" <span
style='mso-element:field-separator'></span></span>
TOC
- WORD_TOC_FIGURE_PREFACE1 =
<<~TOC.freeze
<span lang="EN-GB"><span
style='mso-element:field-begin'></span><span
style='mso-spacerun:yes'> </span>TOC
\\h \\z \\t "FigureTitle,figuretitle" <span
style='mso-element:field-separator'></span></span>
TOC
- BOILERPLATE_PARAS =
Incredibly, the numbered boilerplate list in IEC is NOT A LIST, and it violates numbering conventions for ordered lists (arabic not alpha)
"//div[@class = 'boilerplate_legal']//li/p".freeze
Instance Method Summary
collapse
-
#authority_cleanup(docxml) ⇒ Object
-
#default_file_locations(options) ⇒ Object
-
#default_fonts(options) ⇒ Object
-
#formula_parse1(node, out) ⇒ Object
-
#header_strip(h) ⇒ Object
-
#initialize(options) ⇒ WordConvert
constructor
A new instance of WordConvert.
-
#insert_toc(intro, docxml, level) ⇒ Object
-
#make_body1(body, _docxml) ⇒ Object
-
#make_FigureWordToC(docxml) ⇒ Object
-
#make_TableWordToC(docxml) ⇒ Object
-
#make_tr_attr(td, row, totalrows, header) ⇒ Object
-
#non_annex_h1(docxml) ⇒ Object
-
#tr_parse(node, out, ord, totalrows, header) ⇒ Object
-
#word_annex_cleanup(docxml) ⇒ Object
-
#word_cleanup(docxml) ⇒ Object
-
#word_cover(docxml) ⇒ Object
-
#word_foreword_cleanup(docxml) ⇒ Object
-
#word_table_cleanup(docxml) ⇒ Object
-
#word_table_cleanup1(docxml, style) ⇒ Object
Methods included from Init
#convert1, #i18n_init, #metadata_init, #xref_init
#admitted_term_parse, #biblio_list, #bibliography, #boilerplate, #deprecated_term_parse, #foreword, #iec_orgname, #middle_title, #set_termdomain, #term_parse, #term_suffix, #termref_cleanup, #terms_parse
Constructor Details
#initialize(options) ⇒ WordConvert
Returns a new instance of WordConvert.
9
10
11
12
|
# File 'lib/isodoc/iec/word_convert.rb', line 9
def initialize(options)
super
@libdir = File.dirname(__FILE__)
end
|
Instance Method Details
#authority_cleanup(docxml) ⇒ Object
168
169
170
171
172
|
# File 'lib/isodoc/iec/word_convert.rb', line 168
def authority_cleanup(docxml)
auth = docxml.at("//div[@id = 'boilerplate-feedback' or @class = 'boilerplate-feedback']")
auth&.remove
super
end
|
#default_file_locations(options) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/iec/word_convert.rb', line 26
def default_file_locations(options)
@libdir = File.dirname(__FILE__)
{
wordstylesheet: html_doc_path("wordstyle.scss"),
standardstylesheet: html_doc_path("isodoc.scss"),
header: html_doc_path("header.html"),
wordcoverpage: html_doc_path("word_iec_titlepage.html"),
wordintropage: html_doc_path("word_iec_intro.html"),
ulstyle: "l22",
olstyle: "l2",
}
end
|
#default_fonts(options) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/isodoc/iec/word_convert.rb', line 14
def default_fonts(options)
{
bodyfont: (options[:script] == "Hans" ? '"Source Han Sans",serif' : '"Arial",sans-serif'),
headerfont: (options[:script] == "Hans" ? '"Source Han Sans",sans-serif' : '"Arial",sans-serif'),
monospacefont: '"Courier New",monospace',
normalfontsize: "10.0pt",
footnotefontsize: "8.0pt",
smallerfontsize: "8.0pt",
monospacefontsize: "9.0pt",
}
end
|
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/isodoc/iec/word_convert.rb', line 180
def formula_parse1(node, out)
out.div **attr_code(class: "formula") do |div|
div.p **attr_code(class: "formula") do |p|
insert_tab(div, 1)
parse(node.at(ns("./stem")), div)
lbl = node&.at(ns("./name"))&.text
unless lbl.nil?
insert_tab(div, 1)
div << "(#{lbl})"
end
end
end
end
|
85
86
87
88
|
# File 'lib/isodoc/iec/word_convert.rb', line 85
def (h)
h = h.to_s.gsub(/<\/?p[^>]*>/, "")
super
end
|
#insert_toc(intro, docxml, level) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/isodoc/iec/word_convert.rb', line 39
def insert_toc(intro, docxml, level)
toc = ""
toc += make_WordToC(docxml, level)
if docxml.at("//p[@class = 'TableTitle']")
toc += make_TableWordToC(docxml)
end
if docxml.at("//p[@class = 'FigureTitle']")
toc += make_FigureWordToC(docxml)
end
intro.sub(/WORDTOC/, toc)
end
|
#make_body1(body, _docxml) ⇒ Object
174
175
|
# File 'lib/isodoc/iec/word_convert.rb', line 174
def make_body1(body, _docxml)
end
|
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/iec/word_convert.rb', line 76
def make_FigureWordToC(docxml)
toc = ""
docxml.xpath("//p[@class = 'FigureTitle']").each do |h|
toc += word_toc_entry(1, (h))
end
toc.sub(/(<p class="MsoToc1">)/,
%{\\1#{WORD_TOC_FIGURE_PREFACE1}}) + WORD_TOC_SUFFIX1
end
|
#make_TableWordToC(docxml) ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/isodoc/iec/word_convert.rb', line 67
def make_TableWordToC(docxml)
toc = ""
docxml.xpath("//p[@class = 'TableTitle']").each do |h|
toc += word_toc_entry(1, (h))
end
toc.sub(/(<p class="MsoToc1">)/,
%{\\1#{WORD_TOC_TABLE_PREFACE1}}) + WORD_TOC_SUFFIX1
end
|
#make_tr_attr(td, row, totalrows, header) ⇒ Object
96
97
98
99
100
|
# File 'lib/isodoc/iec/word_convert.rb', line 96
def make_tr_attr(td, row, totalrows, )
ret = super
css_class = (td.name == "th" || ) ? "TABLE-col-heading" : "TABLE-cell"
ret.merge( "class": css_class )
end
|
#non_annex_h1(docxml) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/isodoc/iec/word_convert.rb', line 141
def non_annex_h1(docxml)
docxml.xpath("//h1[not(@class)]").each do |h1|
h1["class"] = "main"
end
docxml.xpath("//h1[@class = 'Section3']").each do |h1|
h1["class"] = "main"
end
end
|
#tr_parse(node, out, ord, totalrows, header) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/isodoc/iec/word_convert.rb', line 102
def tr_parse(node, out, ord, totalrows, )
out.tr do |r|
node.elements.each do |td|
attrs = make_tr_attr(td, ord, totalrows - 1, )
attrs[:class] = "TABLE-col-heading" if
r.send td.name, **attr_code(attrs) do |entry|
td.children.each { |n| parse(n, entry) }
end
end
end
end
|
#word_annex_cleanup(docxml) ⇒ Object
136
137
138
139
|
# File 'lib/isodoc/iec/word_convert.rb', line 136
def word_annex_cleanup(docxml)
super
non_annex_h1(docxml)
end
|
#word_cleanup(docxml) ⇒ Object
90
91
92
93
94
|
# File 'lib/isodoc/iec/word_convert.rb', line 90
def word_cleanup(docxml)
word_foreword_cleanup(docxml)
word_table_cleanup(docxml)
super
end
|
#word_cover(docxml) ⇒ Object
177
178
|
# File 'lib/isodoc/iec/word_convert.rb', line 177
def word_cover(docxml)
end
|
#word_foreword_cleanup(docxml) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/isodoc/iec/word_convert.rb', line 155
def word_foreword_cleanup(docxml)
docxml.xpath(BOILERPLATE_PARAS).each_with_index do |l, i|
l["class"] = "FOREWORD"
l.children.first.add_previous_sibling(
%{#{i+1})<span style="mso-tab-count:1">  </span>})
end
docxml.xpath("//div[@class = 'boilerplate_legal']//li").each do |l|
l.replace(l.children)
end
b = docxml.at("div[@class = 'boilerplate_legal']")
b.replace(b.children)
end
|
#word_table_cleanup(docxml) ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/isodoc/iec/word_convert.rb', line 114
def word_table_cleanup(docxml)
docxml.xpath("//table//*[@class = 'Sourcecode']").each do |p|
p["class"] = "CODE-TableCell"
end
%w(TABLE-col-heading TABLE-cell).each do |style|
word_table_cleanup1(docxml, style)
end
end
|
#word_table_cleanup1(docxml, style) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/isodoc/iec/word_convert.rb', line 123
def word_table_cleanup1(docxml, style)
%w(td th).each do |tdh|
docxml.xpath("//#{tdh}[@class = '#{style}'][not(descendant::p)]").each do |td|
p = Nokogiri::XML::Element.new("p", docxml)
td.children.each { |c| c.parent = p }
p.parent = td
end
docxml.xpath("//#{tdh}[@class = '#{style}']//p").each do |p|
p["class"] ||= style
end
end
end
|