Class: IsoDoc::Iso::WordDISConvert
- Inherits:
-
WordConvert
- Object
- WordConvert
- WordConvert
- IsoDoc::Iso::WordDISConvert
show all
- Defined in:
- lib/isodoc/iso/word_dis_cleanup.rb,
lib/isodoc/iso/word_dis_convert.rb
Constant Summary
collapse
- STYLESMAP =
{
AltTerms: "AdmittedTerm",
TableFootnote: "Tablefootnote",
formula: "Formula",
note: "Note",
example: "Example",
admonition: "Admonition",
admonitiontitle: "AdmonitionTitle",
sourcetitle: "SourceTitle",
TableTitle: "Tabletitle",
titlepagesbhead: "TablePageSubhead",
NormRef: "RefNorm",
Biblio: "BiblioEntry",
MsoNormal: "MsoBodyText",
FigureTitle: "Figuretitle",
zzwarning: "zzWarning",
zzwarninghdr: "zzWarningHdr",
quoteattribution: "QuoteAttribution",
Sourcecode: "Code",
zzSTDTitle1: "zzSTDTitle",
zzSTDTitle2: "zzSTDTitle",
zzCopyright1: "zzCopyright",
}.freeze
- FIGURE_NESTED_STYLES =
{ Note: "Figurenote", example: "Figureexample" }.freeze
Constants inherited
from WordConvert
IsoDoc::Iso::WordConvert::MAIN_ELEMENTS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#amd_style(docxml) ⇒ Object
-
#authority_cleanup(docxml) ⇒ Object
-
#code_style(doc) ⇒ Object
-
#convert1(docxml, filename, dir) ⇒ Object
-
#copyright_dis(docxml) ⇒ Object
-
#copyright_prf(docxml) ⇒ Object
-
#default_file_locations(_options) ⇒ Object
-
#dis_style_interactions(docxml) ⇒ Object
-
#dis_styles1(docxml) ⇒ Object
-
#example_continued_style(docxml) ⇒ Object
-
#example_style(docxml) ⇒ Object
-
#figure_name_attrs(_node) ⇒ Object
-
#figure_style(docxml) ⇒ Object
-
#figure_toc_class ⇒ Object
-
#formula_style(docxml) ⇒ Object
-
#init_dis(opt) ⇒ Object
-
#initialize(options) ⇒ WordDISConvert
constructor
A new instance of WordDISConvert.
-
#make_tr_attr(cell, row, totalrows, header, bordered) ⇒ Object
-
#middle_title(_isoxml, out) ⇒ Object
-
#middle_title_amd(node, out) ⇒ Object
-
#middle_title_dis(node, out) ⇒ Object
-
#middle_title_style(docxml) ⇒ Object
-
#new_styles(docxml) ⇒ Object
-
#note_continued_style(docxml) ⇒ Object
-
#note_style(docxml) ⇒ Object
-
#para_parse(node, out) ⇒ Object
-
#para_style_change(div, class1, class2) ⇒ Object
-
#quote_style1(div) ⇒ Object
-
#remove_note_label(doc) ⇒ Object
-
#sourcecode_style ⇒ Object
-
#span_parse(node, out) ⇒ Object
-
#span_style(xpath, style) ⇒ Object
-
#stripbgcolor(docxml) ⇒ Object
-
#table_title_attrs(_node) ⇒ Object
-
#table_toc_class ⇒ Object
-
#toWord(result, filename, dir, header) ⇒ Object
-
#update_coverpage(docxml) ⇒ Object
-
#word_annex_cleanup1(docxml, lvl) ⇒ Object
-
#word_cleanup(docxml) ⇒ Object
-
#word_section_end_empty_para(docxml) ⇒ Object
-
#word_table_cell_para(docxml) ⇒ Object
-
#word_table_cell_para_style(cell) ⇒ Object
-
#word_toc_preface(level) ⇒ Object
Methods inherited from WordConvert
#annex_name, #annex_name1, #authority_hdr_cleanup, #bibliography, #bibliography_attrs, #bibliography_parse, #br, #colophon_section, #convert, #default_fonts, #definition_parse, #figure_cleanup, #figure_name_parse, #font_choice, #footnote_reference_format, #index_cleanup, #indexsect, #indexsect_section, #indexsect_title, #make_WordToC, #make_body, #para_class, #quote_style, #style_cleanup, #table_attrs, #table_parse, #table_parse_tail, #table_title_parse, #termref_attrs, #termref_parse, #word_annex_cleanup, #word_annex_cleanup_h1
Methods included from Init
#amd?, #clausedelim, #i18n_init, #metadata_init, #requirements_processor, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #xref_init
#admonition_class, #admonition_name_parse, #admonition_p_parse, #admonition_parse, #admonition_parse1, #annex, #clause_etc1, #cleanup, #error_parse, #example_p_parse, #example_parse, #example_parse1, #example_span_label, #figure_name_parse, #figure_parse1, #foreword, #implicit_reference, #measurement_units, #node_begins_with_para, #ol_attrs, #render_identifier, #table_parse, #table_parse_tail, #table_th_center, #top_element_render
Constructor Details
Returns a new instance of WordDISConvert.
18
19
20
21
22
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 18
def initialize(options)
@libdir ||= File.dirname(__FILE__) options.merge!(default_file_locations(options))
super
end
|
Instance Attribute Details
#bgstripcolor ⇒ Object
Returns the value of attribute bgstripcolor.
6
7
8
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 6
def bgstripcolor
@bgstripcolor
end
|
Instance Method Details
#amd_style(docxml) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 92
def amd_style(docxml)
return unless @meta.get[:doctype] == "Amendment"
docxml.xpath("//div[@class = 'WordSection3']//h1").each do |h|
h.name = "p"
h["style"] = "font-style:italic;page-break-after:avoid;"
end
end
|
#authority_cleanup(docxml) ⇒ Object
123
124
125
126
127
128
129
130
131
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 123
def authority_cleanup(docxml)
super
if @meta.get[:stage_int].to_s[0] == "9" ||
@meta.get[:stage_int].to_s[0] == "6"
copyright_prf(docxml)
else
copyright_dis(docxml)
end
end
|
#code_style(doc) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 183
def code_style(doc)
span_style((doc.xpath("//tt//b") - doc.xpath("//tt//i//b")),
"ISOCodebold")
span_style((doc.xpath("//tt//i") - doc.xpath("//tt//b//i")),
"ISOCodeitalic")
span_style((doc.xpath("//b//tt") - doc.xpath("//b//i//tt")),
"ISOCodebold")
span_style((doc.xpath("//i//tt") - doc.xpath("//i//b//tt")),
"ISOCodeitalic")
span_style(doc.xpath("//tt"), "ISOCode")
end
|
#convert1(docxml, filename, dir) ⇒ Object
26
27
28
29
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 26
def convert1(docxml, filename, dir)
update_coverpage(docxml)
super
end
|
#copyright_dis(docxml) ⇒ Object
143
144
145
146
147
148
149
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 143
def copyright_dis(docxml)
docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
p["class"] = "zzCopyright"
p.replace(to_xml(p).gsub(%r{<br/>}, "</p>\n<p class='zzCopyright'>"))
end
docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each(&:remove)
end
|
#copyright_prf(docxml) ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 133
def copyright_prf(docxml)
docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
p["class"] = "zzCopyright"
p["style"] = "text-indent:20.15pt;"
p.replace(to_xml(p).gsub(%r{<br/>}, "</p>\n<p class='zzCopyright' " \
"style='text-indent:20.15pt;'>"))
end
docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each(&:remove)
end
|
#default_file_locations(_options) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 8
def default_file_locations(_options)
{ wordstylesheet: html_doc_path("wordstyle-dis.scss"),
standardstylesheet: html_doc_path("isodoc-dis.scss"),
header: html_doc_path("header-dis.html"),
wordcoverpage: html_doc_path("word_iso_titlepage-dis.html"),
wordintropage: html_doc_path("word_iso_intro-dis.html"),
ulstyle: "l3",
olstyle: "l2" }
end
|
#dis_style_interactions(docxml) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 83
def dis_style_interactions(docxml)
docxml.xpath("//p[@class = 'Code' or @class = 'Code-' or " \
"@class = 'Code--']" \
"[following::p[@class = 'Examplecontinued']]").each do |p|
p["style"] ||= ""
p["style"] = "margin-bottom:12pt;#{p['style']}"
end
end
|
#dis_styles1(docxml) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 42
def dis_styles1(docxml)
amd_style(docxml)
middle_title_style(docxml)
code_style(docxml)
figure_style(docxml)
formula_style(docxml)
note_style(docxml)
example_style(docxml)
dis_style_interactions(docxml)
quote_style(docxml)
stripbgcolor(docxml)
end
|
#example_continued_style(docxml) ⇒ Object
141
142
143
144
145
146
147
148
149
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 141
def example_continued_style(docxml)
docxml.xpath("//div[@class = 'Example']").each do |d|
d.xpath("./p").each_with_index do |p, i|
next if p["class"] && p["class"] != "Example"
p["class"] = (i.zero? ? "Example" : "Examplecontinued")
end
end
end
|
#example_style(docxml) ⇒ Object
137
138
139
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 137
def example_style(docxml)
example_continued_style(docxml)
end
|
41
42
43
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 41
def figure_name_attrs(_node)
{ class: "FigureTitle", style: "text-align:center;" }
end
|
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 164
def figure_style(docxml)
docxml.xpath("//div[@class = 'figure']").each do |f|
FIGURE_NESTED_STYLES.each do |k, v|
f.xpath(".//*[@class = '#{k}']").each { |n| n["class"] = v }
end
f.xpath("./img").each do |i|
i.replace("<p class='FigureGraphic'>#{i.to_xml}</p>")
end
end
end
|
243
244
245
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 243
def figure_toc_class
["Figure Title", "Annex Figure Title", "AnnexFigureTitle"] + super
end
|
175
176
177
178
179
180
181
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 175
def formula_style(docxml)
docxml.xpath("//div[@class = 'Formula']").each do |f|
f.xpath(".//p[not(@class)]").each do |p|
p["class"] = "Formula"
end
end
end
|
#init_dis(opt) ⇒ Object
24
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 24
def init_dis(opt); end
|
#make_tr_attr(cell, row, totalrows, header, bordered) ⇒ Object
59
60
61
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 59
def make_tr_attr(cell, row, totalrows, , bordered)
super.merge(header: )
end
|
#middle_title(_isoxml, out) ⇒ Object
79
80
81
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 79
def middle_title(_isoxml, out)
middle_title_dis(out)
end
|
#middle_title_amd(node, out) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 89
def middle_title_amd(node, out)
out.p(class: "zzSTDTitle2") do |p|
p.span(style: "font-weight:normal") do |s|
node.children.each { |n| parse(n, s) }
end
end
end
|
#middle_title_dis(node, out) ⇒ Object
83
84
85
86
87
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 83
def middle_title_dis(node, out)
out.p(class: "zzSTDTitle") do |p|
node.children.each { |n| parse(n, p) }
end
end
|
#middle_title_style(docxml) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 75
def middle_title_style(docxml)
docxml.xpath("//p[@class = 'zzSTDTitle2']").each do |p|
p1 = p.previous_element && p1.name == p &&
p1["class"] = "zzSTDTitle2" or next
p1 << " #{p.remove.children.to_xml}"
end
end
|
#new_styles(docxml) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 28
def new_styles(docxml)
STYLESMAP.each do |k, v|
docxml.xpath("//*[@class = '#{k}']").each { |s| s["class"] = v }
end
docxml.xpath("//h1[@class = 'ForewordTitle' or @class = 'IntroTitle']")
.each { |h| h.name = "p" }
dis_styles1(docxml)
docxml.xpath("//p[not(@class)]").each { |p| p["class"] = "MsoBodyText" }
end
|
#note_continued_style(docxml) ⇒ Object
151
152
153
154
155
156
157
158
159
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 151
def note_continued_style(docxml)
docxml.xpath("//div[@class = 'Note']").each do |d|
d.xpath("./p").each_with_index do |p, i|
next if p["class"] && p["class"] != "Note"
p["class"] = (i.zero? ? "Note" : "Notecontinued")
end
end
end
|
#note_style(docxml) ⇒ Object
132
133
134
135
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 132
def note_style(docxml)
remove_note_label(docxml)
note_continued_style(docxml)
end
|
#para_parse(node, out) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 97
def para_parse(node, out)
case node["class"]
when "zzSTDTitle1" then middle_title_dis(node, out)
when "zzSTDTitle2" then middle_title_amd(node, out)
else super
end
end
|
#para_style_change(div, class1, class2) ⇒ Object
101
102
103
104
105
106
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 101
def para_style_change(div, class1, class2)
s = class1 ? "@class = '#{class1}'" : "not(@class)"
div.xpath(".//p[#{s}]").each do |p|
p["class"] = class2
end
end
|
#quote_style1(div) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 108
def quote_style1(div)
para_style_change(div, nil, "BodyTextindent1")
para_style_change(div, "Code-", "Code--")
para_style_change(div, "Code", "Code-")
if div["class"] != "Example"
para_style_change(div, "Example", "Exampleindent")
para_style_change(div, "Examplecontinued", "Exampleindentcontinued")
end
if div["class"] != "Note"
para_style_change(div, "Note", "Noteindent")
para_style_change(div, "Notecontinued", "Noteindentcontinued")
end
div.xpath(".//table[@class = 'dl']").each do |t|
t["style"] = "margin-left: 1cm;"
end
end
|
#remove_note_label(doc) ⇒ Object
125
126
127
128
129
130
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 125
def remove_note_label(doc)
doc.xpath("//span[@class = 'note_label' or @class = 'example_label']")
.each do |s|
s.replace(s.children)
end
end
|
#sourcecode_style ⇒ Object
38
39
40
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 38
def sourcecode_style
"Code"
end
|
#span_parse(node, out) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 105
def span_parse(node, out)
st = node["style"]
case node["class"]
when "nonboldtitle"
out.span **attr_code(style: "#{st};font-weight:normal") do |s|
node.children.each { |n| parse(n, s) }
end
when "boldtitle"
out.span **attr_code(style: st) do |s|
node.children.each { |n| parse(n, s) }
end
else
out.span **attr_code(class: node["class"], style: st) do |x|
node.children.each { |n| parse(n, x) }
end
end
end
|
#span_style(xpath, style) ⇒ Object
195
196
197
198
199
200
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 195
def span_style(xpath, style)
xpath.each do |elem|
elem.name = "span"
elem["class"] = style
end
end
|
#stripbgcolor(docxml) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 55
def stripbgcolor(docxml)
@bgstripcolor == "true" or return
%w(aucollab audeg aufname aurole ausuffix ausurname bibarticle bibetal
bibfname bibfpage bibissue bibjournal biblpage bibnumber
biborganization bibsuppl bibsurname biburl bibvolume bibyear
citebib citeen citefig citefn citetbl bibextlink citeeq citetfn
auprefix citeapp citesec stddocNumber stddocPartNumber
stddocTitle aumember stdfootnote stdpublisher stdsection stdyear
stddocumentType bibalt-year bibbook bbichapterno bibchaptertitle
bibed-etal bibed-fname bibeditionno bibed-organization bibed-suffix
bibed-surname bibinstitution bibisbn biblocation bibpagecount
bibpatent bibpublisher bibreportnum bibschool bibseries bibseriesno
bibtrans stdsuppl citesection).each do |t|
docxml.xpath("//span[@class = '#{t}']").each do |s|
s["style"] ||= ""
s["style"] = "mso-pattern:none;#{s['style']}"
end
end
end
|
#table_title_attrs(_node) ⇒ Object
45
46
47
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 45
def table_title_attrs(_node)
{ class: "TableTitle", style: "text-align:center;" }
end
|
#table_toc_class ⇒ Object
238
239
240
241
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 238
def table_toc_class
["Table title", "Tabletitle", "Annex Table Title", "AnnexTableTitle"] +
super
end
|
#toWord(result, filename, dir, header) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 63
def toWord(result, filename, dir, )
result = from_xhtml(word_cleanup(to_xhtml(result)))
.gsub("-DOUBLE_HYPHEN_ESCAPE-", "--")
@wordstylesheet = wordstylesheet_update
::Html2Doc::IsoDIS.new(
filename: filename,
imagedir: @localdir,
stylesheet: @wordstylesheet&.path,
header_file: &.path, dir: dir,
asciimathdelims: [@openmathdelim, @closemathdelim],
liststyles: { ul: @ulstyle, ol: @olstyle }
).process(result)
&.unlink
@wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
end
|
#update_coverpage(docxml) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 31
def update_coverpage(docxml)
stage = docxml.at(ns("//bibdata/status/stage"))&.text
substage = docxml.at(ns("//bibdata/status/substage"))&.text
if /^9/.match?(stage) || (stage == "60" && substage == "60")
@wordcoverpage = html_doc_path("word_iso_titlepage.html")
elsif stage == "60" && substage == "00"
@wordcoverpage = html_doc_path("word_iso_titlepage-prf.html")
end
end
|
#word_annex_cleanup1(docxml, lvl) ⇒ Object
202
203
204
205
206
207
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 202
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_cleanup(docxml) ⇒ Object
209
210
211
212
213
214
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 209
def word_cleanup(docxml)
word_table_cell_para(docxml)
super
word_section_end_empty_para(docxml)
docxml
end
|
#word_section_end_empty_para(docxml) ⇒ Object
216
217
218
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 216
def word_section_end_empty_para(docxml)
docxml.at("//div[@class='WordSection1']/p[last()]").remove
end
|
#word_table_cell_para(docxml) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 220
def word_table_cell_para(docxml)
docxml.xpath("//td | //th").each do |t|
s = word_table_cell_para_style(t)
t.delete("header")
if t.at("./p |./div")
t.xpath("./p | ./div").each { |p| p["class"] = s }
else
t.children = "<div class='#{s}'>#{to_xml(t.children)}</div>"
end
end
end
|
#word_table_cell_para_style(cell) ⇒ Object
232
233
234
235
236
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 232
def word_table_cell_para_style(cell)
ret = cell["header"] == "true" ? "Tableheader" : "Tablebody"
cell["class"] == "rouge-code" and ret = "Code"
ret
end
|
#word_toc_preface(level) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 49
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 "2-#{level}" \\h \\z \\t
"Heading 1,1,ANNEX,1,Biblio Title,1,Foreword Title,1,Intro Title,1,ANNEXN,1,ANNEXZ,1,na2,1,na3,1,na4,1,na5,1,na6,1,Title,1,Base_Heading,1,Box-title,1,Front Head,1,Index Head,1,AMEND Terms Heading,1,AMEND Heading 1 Unnumbered,1"
<span style='mso-element:field-separator'></span></span>
TOC
end
|