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
Instance Method Summary
collapse
-
#annex_name(_annex, name, div) ⇒ Object
-
#authority_cleanup(docxml) ⇒ Object
-
#authority_hdr_cleanup(docxml) ⇒ Object
-
#bibliography(xml, out) ⇒ Object
-
#bibliography_attrs ⇒ Object
-
#bibliography_parse(node, out) ⇒ Object
-
#colophon(body, _docxml) ⇒ 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
-
#font_choice(options) ⇒ Object
-
#footnote_reference_format(link) ⇒ Object
-
#initialize(options) ⇒ WordConvert
constructor
A new instance of WordConvert.
-
#make_body(xml, docxml) ⇒ Object
-
#para_class(node) ⇒ Object
-
#style_cleanup(docxml) ⇒ Object
-
#style_cleanup1(docxml) ⇒ Object
-
#table_title_attrs(node) ⇒ Object
-
#table_title_parse(node, out) ⇒ Object
-
#termref_attrs ⇒ Object
-
#termref_parse(node, out) ⇒ Object
-
#word_annex_cleanup(docxml) ⇒ Object
-
#word_annex_cleanup1(docxml, lvl) ⇒ Object
force Annex h2 down to be p.h2Annex, so it is not picked up by ToC.
-
#word_annex_cleanup_h1(docxml) ⇒ Object
-
#word_cleanup(docxml) ⇒ Object
-
#word_toc_preface(level) ⇒ Object
Methods included from Init
#amd, #clausedelim, #i18n_init, #metadata_init, #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, #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
#initialize(options) ⇒ WordConvert
Returns a new instance of WordConvert.
9
10
11
12
13
14
15
16
|
# File 'lib/isodoc/iso/word_convert.rb', line 9
def initialize(options)
@libdir = File.dirname(__FILE__)
super
@wordToClevels = options[:doctoclevels].to_i
@wordToClevels = 3 if @wordToClevels.zero?
@htmlToClevels = options[:htmltoclevels].to_i
@htmlToClevels = 3 if @htmlToClevels.zero?
end
|
Instance Method Details
#annex_name(_annex, name, div) ⇒ Object
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/isodoc/iso/word_convert.rb', line 156
def annex_name(_annex, name, div)
preceding_floating_titles(name, div)
return if name.nil?
name&.at(ns("./strong"))&.remove
div.h1 **{ class: "Annex" } do |t|
name.children.each { |c2| parse(c2, t) }
clause_parse_subtitle(name, t)
end
end
|
#authority_cleanup(docxml) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 64
def authority_cleanup(docxml)
insert = docxml.at("//div[@id = 'boilerplate-license-destination']")
auth = docxml&.at("//div[@class = 'boilerplate-license']")&.remove
auth&.xpath(".//p[not(@class)]")&.each { |p| p["class"] = "zzWarning" }
auth and insert.children = auth
insert = docxml.at("//div[@id = 'boilerplate-copyright-destination']")
auth = docxml&.at("//div[@class = 'boilerplate-copyright']")&.remove
auth&.xpath(".//p[not(@class)]")&.each do |p|
p["class"] = "zzCopyright"
end
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
auth and insert.children = auth
end
|
#authority_hdr_cleanup(docxml) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 49
def authority_hdr_cleanup(docxml)
docxml&.xpath("//div[@class = 'boilerplate-license']")&.each do |d|
d.xpath(".//h1").each do |p|
p.name = "p"
p["class"] = "zzWarningHdr"
end
end
docxml&.xpath("//div[@class = 'boilerplate-copyright']")&.each do |d|
d.xpath(".//h1").each do |p|
p.name = "p"
p["class"] = "zzCopyrightHdr"
end
end
end
|
#bibliography(xml, out) ⇒ Object
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/isodoc/iso/word_convert.rb', line 88
def bibliography(xml, out)
(f = xml.at(ns(bibliography_xpath)) and f["hidden"] != "true") or return
page_break(out)
out.div do |div|
div.h1 **bibliography_attrs do |h1|
f&.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
end
biblio_list(f, div, true)
end
end
|
#bibliography_attrs ⇒ Object
84
85
86
|
# File 'lib/isodoc/iso/word_convert.rb', line 84
def bibliography_attrs
{ class: "BiblioTitle" }
end
|
#bibliography_parse(node, out) ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'lib/isodoc/iso/word_convert.rb', line 99
def bibliography_parse(node, out)
node["hidden"] != true or return
out.div do |div|
clause_parse_title(node, div, node.at(ns("./title")), out,
bibliography_attrs)
biblio_list(node, div, true)
end
end
|
#colophon(body, _docxml) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/isodoc/iso/word_convert.rb', line 58
def colophon(body, _docxml)
stage = @meta.get[:stage_int]
return if !stage.nil? && stage < 60
body.br **{ clear: "all", style: "page-break-before:left;"\
"mso-break-type:section-break" }
body.div **{ class: "colophon" } do |div|
end
end
|
#default_file_locations(options) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/isodoc/iso/word_convert.rb', line 34
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
24
25
26
27
28
29
30
31
32
|
# File 'lib/isodoc/iso/word_convert.rb', line 24
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
108
109
110
111
112
|
# File 'lib/isodoc/iso/word_convert.rb', line 108
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
|
131
132
133
134
|
# File 'lib/isodoc/iso/word_convert.rb', line 131
def figure_name_attrs(node)
s = node.ancestors("annex").empty? ? "FigureTitle" : "AnnexFigureTitle"
{ class: s, style: "text-align:center;" }
end
|
136
137
138
139
140
141
142
|
# File 'lib/isodoc/iso/word_convert.rb', line 136
def figure_name_parse(node, div, name)
return if name.nil?
div.p **figure_name_attrs(node) do |p|
name.children.each { |n| parse(n, p) }
end
end
|
#font_choice(options) ⇒ Object
18
19
20
21
22
|
# File 'lib/isodoc/iso/word_convert.rb', line 18
def font_choice(options)
if options[:script] == "Hans" then '"Source Han Sans",serif'
else '"Cambria",serif'
end
end
|
79
80
81
82
|
# File 'lib/isodoc/iso/word_convert.rb', line 79
def (link)
link.children =
"<span class='MsoFootnoteReference'>#{link.children.to_xml}</span>)"
end
|
#make_body(xml, docxml) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/isodoc/iso/word_convert.rb', line 48
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)
colophon(body, docxml)
end
end
|
#para_class(node) ⇒ Object
114
115
116
117
118
119
|
# File 'lib/isodoc/iso/word_convert.rb', line 114
def para_class(node)
if @definition && ! then "Definition"
elsif @foreword && ! then "ForewordText"
else super
end
end
|
#style_cleanup(docxml) ⇒ Object
38
39
40
41
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 38
def style_cleanup(docxml)
word_annex_cleanup_h1(docxml)
style_cleanup1(docxml)
end
|
#style_cleanup1(docxml) ⇒ Object
43
44
45
46
47
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 43
def style_cleanup1(docxml)
docxml.xpath("//*[@class = 'example']").each do |p|
p["class"] = "Example"
end
end
|
#table_title_attrs(node) ⇒ Object
144
145
146
147
|
# File 'lib/isodoc/iso/word_convert.rb', line 144
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
149
150
151
152
153
154
|
# File 'lib/isodoc/iso/word_convert.rb', line 149
def table_title_parse(node, out)
name = node.at(ns("./name")) or return
out.p **table_title_attrs(node) do |p|
name&.children&.each { |n| parse(n, p) }
end
end
|
#termref_attrs ⇒ Object
121
122
123
|
# File 'lib/isodoc/iso/word_convert.rb', line 121
def termref_attrs
{ class: "Source" }
end
|
#termref_parse(node, out) ⇒ Object
125
126
127
128
129
|
# File 'lib/isodoc/iso/word_convert.rb', line 125
def termref_parse(node, out)
out.p **termref_attrs do |p|
node.children.each { |n| parse(n, p) }
end
end
|
#word_annex_cleanup(docxml) ⇒ Object
22
23
24
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 22
def word_annex_cleanup(docxml)
(2..6).each { |i| word_annex_cleanup1(docxml, i) }
end
|
#word_annex_cleanup1(docxml, lvl) ⇒ Object
force Annex h2 down to be p.h2Annex, so it is not picked up by ToC
15
16
17
18
19
20
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 15
def word_annex_cleanup1(docxml, lvl)
docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
h2.name = "p"
h2["class"] = "h#{lvl}Annex"
end
end
|
#word_annex_cleanup_h1(docxml) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 26
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
86
87
88
89
90
91
|
# File 'lib/isodoc/iso/word_cleanup.rb', line 86
def word_cleanup(docxml)
authority_hdr_cleanup(docxml)
super
style_cleanup(docxml)
docxml
end
|
#word_toc_preface(level) ⇒ Object
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/isodoc/iso/word_convert.rb', line 68
def word_toc_preface(level)
" <span lang=\"EN-GB\"><span\n style='mso-element:field-begin'></span><span\n style='mso-spacerun:yes'> </span>TOC\n \\\\o "1-\#{level}" \\\\h \\\\z \\\\t "Heading\n 1;1;ANNEX;1;Biblio Title;1;Foreword Title;1;Intro Title;1" <span\n style='mso-element:field-separator'></span></span>\n TOC\nend\n".freeze
|