Class: IsoDoc::Iso::WordDISConvert
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",
}.freeze
- FIGURE_NESTED_STYLES =
{ Note: "Figurenote", example: "Figureexample" }.freeze
Instance Method Summary
collapse
Methods inherited from WordConvert
#annex_name, #annex_name1, #authority_cleanup, #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, #style_cleanup1, #table_title_parse, #termref_attrs, #termref_parse, #word_annex_cleanup, #word_annex_cleanup_h1
Methods included from Init
#amd, #clausedelim, #i18n_init, #metadata_init, #std_docid_semantic, #xref_init
#admonition_name_parse, #admonition_p_parse, #admonition_parse, #admonition_parse1, #annex, #clause_etc, #clause_etc1, #cleanup, #convert1, #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, #middle_title_amd, #middle_title_main, #node_begins_with_para, #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
#code_style(doc) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 126
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
|
#default_file_locations(_options) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 4
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_styles(docxml) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 49
def dis_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
|
#dis_styles1(docxml) ⇒ Object
59
60
61
62
63
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 59
def dis_styles1(docxml)
code_style(docxml)
figure_style(docxml)
example_style(docxml)
end
|
#example_style(docxml) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 65
def example_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
|
75
76
77
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 75
def figure_name_attrs(_node)
{ class: "FigureTitle", style: "text-align:center;" }
end
|
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 115
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 ⇒ Object
22
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 22
def init_dis; end
|
#make_tr_attr(cell, row, totalrows, header) ⇒ Object
145
146
147
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 145
def make_tr_attr(cell, row, totalrows, )
super.merge(header: )
end
|
#render_identifier(ident) ⇒ Object
106
107
108
109
110
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 106
def render_identifier(ident)
ret = super
ret[:sdo] = std_docid_semantic(ret[:sdo])
ret
end
|
#span_parse(node, out) ⇒ Object
90
91
92
93
94
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 90
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
138
139
140
141
142
143
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 138
def span_style(xpath, style)
xpath.each do |elem|
elem.name = "span"
elem["class"] = style
end
end
|
#style_cleanup(docxml) ⇒ Object
24
25
26
27
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 24
def style_cleanup(docxml)
super
dis_styles(docxml)
end
|
#table_title_attrs(_node) ⇒ Object
79
80
81
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 79
def table_title_attrs(_node)
{ class: "Tabletitle", style: "text-align:center;" }
end
|
#toWord(result, filename, dir, header) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 166
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
|
#word_annex_cleanup1(docxml, lvl) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 83
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
149
150
151
152
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 149
def word_cleanup(docxml)
word_table_cell_para(docxml)
super
end
|
#word_table_cell_para(docxml) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 154
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
96
97
98
99
100
101
102
103
104
|
# File 'lib/isodoc/iso/word_dis_convert.rb', line 96
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
|