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
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
-
#init_dis(options) ⇒ Object
-
#initialize(options) ⇒ WordDISConvert
constructor
A new instance of WordDISConvert.
-
#make_FigureWordToC(docxml) ⇒ Object
-
#make_TableWordToC(docxml) ⇒ Object
-
#make_tr_attr(cell, row, totalrows, header) ⇒ Object
-
#middle_title(_isoxml, out) ⇒ Object
-
#middle_title_dis(out) ⇒ Object
-
#middle_title_dis_amd(para) ⇒ Object
-
#new_styles(docxml) ⇒ Object
-
#note_continued_style(docxml) ⇒ Object
-
#note_style(docxml) ⇒ Object
-
#para_style_change(div, class1, class2) ⇒ Object
-
#quote_style1(div) ⇒ Object
-
#remove_note_label(doc) ⇒ Object
-
#render_identifier(ident) ⇒ Object
-
#span_parse(node, out) ⇒ Object
-
#span_style(xpath, style) ⇒ Object
-
#table_title_attrs(_node) ⇒ 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_toc_preface(level) ⇒ Object
Methods inherited from WordConvert
#annex_name, #annex_name1, #authority_hdr_cleanup, #bibliography, #bibliography_attrs, #bibliography_parse, #colophon, #convert, #default_fonts, #definition_parse, #figure_cleanup, #figure_name_parse, #font_choice, #footnote_reference_format, #make_WordToC, #make_body, #para_class, #quote_style, #style_cleanup, #table_attrs, #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_semantic_full, #xref_init
#admonition_class, #admonition_name_parse, #admonition_p_parse, #admonition_parse, #admonition_parse1, #annex, #clause_etc, #clause_etc1, #cleanup, #error_parse, #example_p_parse, #example_parse, #example_parse1, #example_span_label, #figure_name_parse, #foreword, #formula_where, #implicit_reference, #indexsect, #introduction, #middle, #middle_title_amd, #middle_title_main, #node_begins_with_para, #ol_attrs, #table_th_center
Constructor Details
Returns a new instance of WordDISConvert.
16
17
18
19
20
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 16
def initialize(options)
@libdir ||= File.dirname(__FILE__) options.merge!(default_file_locations(options))
super
end
|
Instance Method Details
#amd_style(docxml) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 57
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
173
174
175
176
177
178
179
180
181
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 173
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
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 140
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
24
25
26
27
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 24
def convert1(docxml, filename, dir)
update_coverpage(docxml)
super
end
|
#copyright_dis(docxml) ⇒ Object
196
197
198
199
200
201
202
203
204
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 196
def copyright_dis(docxml)
docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
p["class"] = "zzCopyright"
p.replace(p.to_xml.gsub(%r{<br/>}, "</p>\n<p class='zzCopyright'>"))
end
docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
p.remove
end
end
|
#copyright_prf(docxml) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
194
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 183
def copyright_prf(docxml)
docxml.xpath("//p[@id = 'boilerplate-address']")&.each do |p|
p["class"] = "zzCopyright"
p["style"] = "text-indent:20.15pt;"
p.replace(p.to_xml.gsub(%r{<br/>}, "</p>\n<p class='zzCopyright' "\
"style='text-indent:20.15pt;'>"))
end
docxml.xpath("//p[@class = 'zzCopyrightHdr']")&.each do |p|
p.remove
end
end
|
#default_file_locations(_options) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 6
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
48
49
50
51
52
53
54
55
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 48
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
38
39
40
41
42
43
44
45
46
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 38
def dis_styles1(docxml)
amd_style(docxml)
code_style(docxml)
figure_style(docxml)
note_style(docxml)
example_style(docxml)
dis_style_interactions(docxml)
quote_style(docxml)
end
|
#example_continued_style(docxml) ⇒ Object
106
107
108
109
110
111
112
113
114
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 106
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
102
103
104
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 102
def example_style(docxml)
example_continued_style(docxml)
end
|
39
40
41
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 39
def figure_name_attrs(_node)
{ class: "FigureTitle", style: "text-align:center;" }
end
|
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 129
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
|
#init_dis(options) ⇒ Object
22
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 22
def init_dis(options); end
|
222
223
224
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 222
def make_FigureWordToC(docxml)
super.sub(/FigureTitle,figuretitle/, "Figure title,Annex Figure Title")
end
|
#make_TableWordToC(docxml) ⇒ Object
226
227
228
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 226
def make_TableWordToC(docxml)
super.sub(/TableTitle,tabletitle/, "Table title,Annex Table Title")
end
|
#make_tr_attr(cell, row, totalrows, header) ⇒ Object
69
70
71
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 69
def make_tr_attr(cell, row, totalrows, )
super.merge(header: )
end
|
#middle_title(_isoxml, out) ⇒ Object
89
90
91
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 89
def middle_title(_isoxml, out)
middle_title_dis(out)
end
|
#middle_title_dis(out) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 93
def middle_title_dis(out)
out.p(**{ class: "zzSTDTitle" }) do |p|
p << @meta.get[:doctitleintro]
@meta.get[:doctitleintro] && @meta.get[:doctitlemain] and p << " — "
p << @meta.get[:doctitlemain]
@meta.get[:doctitlemain] && @meta.get[:doctitlepart] and p << " — "
if @meta.get[:doctitlepart]
b = @meta.get[:doctitlepartlabel] and
p << "<span style='font-weight:normal'>#{b}:</span> "
p << " #{@meta.get[:doctitlepart]}"
end
@meta.get[:doctitleamdlabel] || @meta.get[:doctitleamd] ||
@meta.get[:doctitlecorrlabel] and middle_title_dis_amd(p)
end
end
|
#middle_title_dis_amd(para) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 109
def middle_title_dis_amd(para)
para.span(**{ style: "font-weight:normal" }) do |p|
if a = @meta.get[:doctitleamdlabel]
p << " #{a}"
a = @meta.get[:doctitleamd] and p << ": #{a}"
end
if a = @meta.get[:doctitlecorrlabel]
p << " #{a}"
end
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
116
117
118
119
120
121
122
123
124
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 116
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
97
98
99
100
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 97
def note_style(docxml)
remove_note_label(docxml)
note_continued_style(docxml)
end
|
#para_style_change(div, class1, class2) ⇒ Object
66
67
68
69
70
71
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 66
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 73
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
90
91
92
93
94
95
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 90
def remove_note_label(doc)
doc.xpath("//span[@class = 'note_label' or @class = 'example_label']")
.each do |s|
s.replace(s.children)
end
end
|
#render_identifier(ident) ⇒ Object
63
64
65
66
67
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 63
def render_identifier(ident)
ret = super
ret[:sdo] = std_docid_semantic(ret[:sdo])
ret
end
|
#span_parse(node, out) ⇒ Object
47
48
49
50
51
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 47
def span_parse(node, out)
out.span **{ class: node["class"] } do |x|
node.children.each { |n| parse(n, x) }
end
end
|
#span_style(xpath, style) ⇒ Object
152
153
154
155
156
157
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 152
def span_style(xpath, style)
xpath.each do |elem|
elem.name = "span"
elem["class"] = style
end
end
|
#table_title_attrs(_node) ⇒ Object
43
44
45
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 43
def table_title_attrs(_node)
{ class: "Tabletitle", style: "text-align:center;" }
end
|
#toWord(result, filename, dir, header) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 73
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
29
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 29
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
159
160
161
162
163
164
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 159
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
166
167
168
169
170
171
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 166
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
206
207
208
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 206
def word_section_end_empty_para(docxml)
docxml.at("//div[@class='WordSection1']/p[last()]").remove
end
|
#word_table_cell_para(docxml) ⇒ Object
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/isodoc/iso/word_dis_cleanup.rb', line 210
def word_table_cell_para(docxml)
docxml.xpath("//td | //th").each do |t|
s = t["header"] == "true" ? "Tableheader" : "Tablebody"
t.delete("header")
if t.at("./p |./div")
t.xpath("./p | ./div").each { |p| p["class"] = s }
else
t.children = "<div class='#{s}'>#{t.children.to_xml}</div>"
end
end
end
|
#word_toc_preface(level) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 53
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
|