Class: IsoDoc::IEEE::WordConvert
- Inherits:
-
WordConvert
- Object
- WordConvert
- IsoDoc::IEEE::WordConvert
show all
- Includes:
- BaseConvert, Init
- Defined in:
- lib/isodoc/ieee/word_cleanup.rb,
lib/isodoc/ieee/word_convert.rb,
lib/isodoc/ieee/word_authority.rb
Constant Summary
collapse
- STYLESMAP =
{
MsoNormal: "IEEEStdsParagraph",
NormRef: "IEEEStdsBibliographicEntry",
Biblio: "IEEEStdsBibliographicEntry",
}.freeze
- SECTIONBREAK =
<<~BREAK.freeze
<span lang="EN-US" style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:
"Times New Roman",serif;mso-fareast-font-family:"Times New Roman";mso-ansi-language:
EN-US;mso-fareast-language:JA;mso-bidi-language:AR-SA'><br clear="all"
style='page-break-before:auto;mso-break-type:section-break'></span>
BREAK
Instance Method Summary
collapse
-
#abstract(isoxml, out) ⇒ Object
-
#abstract_cleanup(docxml) ⇒ Object
-
#abstract_cleanup1(source, dest) ⇒ Object
-
#authority_cleanup(docxml) ⇒ Object
-
#authority_cleanup1(docxml, klass) ⇒ Object
-
#authority_cleanup_hdr(auth) ⇒ Object
-
#authority_style(docxml) ⇒ Object
-
#copyright_style(docxml) ⇒ Object
-
#default_file_locations(_options) ⇒ Object
-
#default_fonts(options) ⇒ Object
-
#div_cleanup(docxml) ⇒ Object
-
#feedback_footnote(docxml) ⇒ Object
-
#feedback_style(docxml) ⇒ Object
-
#feedback_style1(div, idx) ⇒ Object
-
#feedback_table(docxml) ⇒ Object
-
#feedback_table1(trow) ⇒ Object
-
#headings_cleanup(docxml) ⇒ Object
-
#headings_cleanup1(hdr) ⇒ Object
-
#initialize(options) ⇒ WordConvert
constructor
A new instance of WordConvert.
-
#introduction_cleanup(docxml) ⇒ Object
-
#introduction_cleanup1(intro, dest) ⇒ Object
-
#license_style(docxml) ⇒ Object
-
#make_body3(body, docxml) ⇒ Object
-
#middle_title(isoxml, out) ⇒ Object
-
#middle_title_ieee(_docxml, out) ⇒ Object
-
#officeholder_style(para) ⇒ Object
-
#officemember_style(docxml) ⇒ Object
-
#officer_style(docxml) ⇒ Object
-
#para_type_cleanup(html) ⇒ Object
-
#span_style_cleanup(html) ⇒ Object
-
#style_cleanup(docxml) ⇒ Object
-
#three_column_officemembers(div) ⇒ Object
-
#three_column_officemembers_render(div, ret) ⇒ Object
-
#three_column_officemembers_split(div) ⇒ Object
-
#toWord(result, filename, dir, header) ⇒ Object
-
#word_cleanup(docxml) ⇒ Object
Methods included from Init
#fileloc, #i18n_init, #metadata_init, #xref_init
#clause_attrs, #middle_clause, #para_attrs, #scope
Constructor Details
#initialize(options) ⇒ WordConvert
Returns a new instance of WordConvert.
9
10
11
12
|
# File 'lib/isodoc/ieee/word_convert.rb', line 9
def initialize(options)
@libdir = File.dirname(__FILE__)
super
end
|
Instance Method Details
#abstract(isoxml, out) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/isodoc/ieee/word_convert.rb', line 42
def abstract(isoxml, out)
f = isoxml.at(ns("//preface/abstract")) || return
page_break(out)
out.div **attr_code(id: f["id"], class: "abstract") do |s|
clause_name(nil, f.at(ns("./title")), s, { class: "AbstractTitle" })
f.elements.each { |e| parse(e, s) unless e.name == "title" }
end
end
|
#abstract_cleanup(docxml) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 20
def abstract_cleanup(docxml)
dest = docxml.at("div[@id = 'abstract-destination']") or return
if f = docxml.at("//div[@class = 'abstract']")
f.previous_element.remove
abstract_cleanup1(f, dest)
f.remove
elsif f = docxml.at("//div[@type = 'scope']")
abstract_cleanup1(f, dest)
end
end
|
#abstract_cleanup1(source, dest) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 31
def abstract_cleanup1(source, dest)
source.elements.each do |e|
next if %w(h1 h2).include?(e.name)
dest << e.dup
dest.elements.last["class"] = "IEEEStdsAbstractBody"
end
dest.elements.first.children.first.previous =
"<span class='IEEEStdsAbstractHeader'><span lang='EN-US'>"\
"Abstract:</span></span> "
end
|
#authority_cleanup(docxml) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/isodoc/ieee/word_authority.rb', line 4
def authority_cleanup(docxml)
(docxml)
%w(copyright license disclaimers participants).each do |t|
authority_cleanup1(docxml, t)
end
coverpage_note_cleanup(docxml)
authority_style(docxml)
end
|
#authority_cleanup1(docxml, klass) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/isodoc/ieee/word_authority.rb', line 141
def authority_cleanup1(docxml, klass)
dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']")
auth = docxml.at("//div[@id = 'boilerplate-#{klass}' "\
"or @class = 'boilerplate-#{klass}']")
auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each(&:remove)
authority_cleanup_hdr(auth)
dest and auth and dest.replace(auth.remove)
end
|
#authority_cleanup_hdr(auth) ⇒ Object
150
151
152
153
154
155
156
157
|
# File 'lib/isodoc/ieee/word_authority.rb', line 150
def authority_cleanup_hdr(auth)
(1..2).each do |i|
auth&.xpath(".//h#{i}")&.each do |h|
h.name = "p"
h["class"] = "IEEEStdsLevel#{i}frontmatter"
end
end
end
|
#authority_style(docxml) ⇒ Object
22
23
24
25
26
|
# File 'lib/isodoc/ieee/word_authority.rb', line 22
def authority_style(docxml)
copyright_style(docxml)
license_style(docxml)
officer_style(docxml)
end
|
#copyright_style(docxml) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/isodoc/ieee/word_authority.rb', line 28
def copyright_style(docxml)
docxml.at("//div[@class = 'boilerplate-copyright']")&.xpath(".//p")
&.reverse&.each_with_index do |p, i|
p["class"] =
i.zero? ? "IEEEStdsTitleDraftCRBody" : "IEEEStdsTitleDraftCRaddr"
end
end
|
#default_file_locations(_options) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/isodoc/ieee/word_convert.rb', line 32
def default_file_locations(_options)
{ wordstylesheet: html_doc_path("wordstyle.scss"),
standardstylesheet: html_doc_path("ieee.scss"),
header: html_doc_path("header.html"),
wordcoverpage: html_doc_path("word_ieee_titlepage.html"),
wordintropage: html_doc_path("word_ieee_intro.html"),
ulstyle: "l3",
olstyle: "l2" }
end
|
#default_fonts(options) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/isodoc/ieee/word_convert.rb', line 14
def default_fonts(options)
{ bodyfont: (if options[:script] == "Hans"
'"Source Han Sans",serif'
else
'"Times New Roman",serif'
end),
headerfont: (if options[:script] == "Hans"
'"Source Han Sans",sans-serif'
else
'"Arial",sans-serif'
end),
monospacefont: '"Courier New",monospace',
normalfontsize: "12.0pt",
footnotefontsize: "11.0pt",
smallerfontsize: "10.0pt",
monospacefontsize: "10.0pt" }
end
|
#div_cleanup(docxml) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 90
def div_cleanup(docxml)
d = docxml.at("//div[@class = 'WordSection2']"\
"[div[@class = 'WordSection2']]") and
d.replace(d.children)
i = 0
docxml.xpath("//div[@class]").each do |div|
next unless /^WordSection/.match?(div["class"])
i += 1
div["class"] = "WordSection#{i}"
end
end
|
13
14
15
16
17
18
19
20
|
# File 'lib/isodoc/ieee/word_authority.rb', line 13
def (docxml)
feedback_style(docxml)
feedback_table(docxml)
f = docxml.at("//div[@class = 'boilerplate-feedback']") or return
docxml.at("//aside").previous = <<~FN
<aside id="ftn0">#{f.remove.to_xml}</aside>
FN
end
|
#feedback_style(docxml) ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/isodoc/ieee/word_authority.rb', line 124
def feedback_style(docxml)
docxml.at("//div[@class = 'boilerplate-feedback']")&.xpath("./div")
&.each_with_index do |div, i|
i.zero? or div.elements.first.previous = "<p> </p>"
feedback_style1(div, i)
end
end
|
#feedback_style1(div, idx) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'lib/isodoc/ieee/word_authority.rb', line 132
def feedback_style1(div, idx)
div.xpath(".//p").each_with_index do |p, j|
p["class"] = idx == 4 ? "IEEEStdsCRTextItal" : "IEEEStdsCRTextReg"
j.zero? && idx.zero? and
p.children.first.previous =
'<a style="mso-footnote-id:ftn0" href="#_ftnref0" name="_ftn0" title=""/>'
end
end
|
#feedback_table(docxml) ⇒ Object
105
106
107
108
109
110
111
112
113
|
# File 'lib/isodoc/ieee/word_authority.rb', line 105
def feedback_table(docxml)
docxml.at("//div[@class = 'boilerplate-feedback']")&.xpath(".//table")
&.each do |t|
t.xpath(".//tr").each do |tr|
feedback_table1(tr)
end
t.replace(t.at(".//tbody").elements)
end
end
|
#feedback_table1(trow) ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/isodoc/ieee/word_authority.rb', line 115
def feedback_table1(trow)
trow.name = "p"
trow["class"] = "IEEEStdsCRTextReg"
trow.xpath("./td").each do |td|
td.next_element and td << "<span style='mso-tab-count:1'> </span>"
td.replace(td.children)
end
end
|
#headings_cleanup(docxml) ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 73
def headings_cleanup(docxml)
(1..4).each do |i|
docxml.xpath("//h#{i}").each do |h|
headings_cleanup1(h)
h.name = "p"
h["class"] = "IEEEStdsLevel#{i}Header"
end
end
end
|
#headings_cleanup1(hdr) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 83
def headings_cleanup1(hdr)
if hdr.children.size > 1 && hdr.children[1].name == "span" &&
hdr.children[1]["style"] == "mso-tab-count:1"
2.times { hdr.children.first.remove }
end
end
|
#introduction_cleanup(docxml) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 43
def introduction_cleanup(docxml)
dest = docxml.at("div[@id = 'introduction-destination']") or return
unless i = docxml.at("//h1[@class = 'IntroTitle']")&.parent
dest.parent.remove
return
end
introduction_cleanup1(i, dest)
end
|
#introduction_cleanup1(intro, dest) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 52
def introduction_cleanup1(intro, dest)
docxml = intro.document
intro.previous_element.remove
dest.replace(intro.remove)
i = docxml.at("//h1[@class = 'IntroTitle']")
i.next_element == "div" && i.next_element["class"] == "Admonition" and
i.next_element["class"] = "IEEEStdsIntroduction"
end
|
#license_style(docxml) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/isodoc/ieee/word_authority.rb', line 36
def license_style(docxml)
docxml.at("//div[@class = 'boilerplate-license']")&.xpath(".//p")
&.reverse&.each_with_index do |p, i|
p["class"] =
i.zero? ? "IEEEStdsTitleDraftCRBody" : "IEEEStdsTitleDraftCRaddr"
end
end
|
#make_body3(body, docxml) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/isodoc/ieee/word_convert.rb', line 51
def make_body3(body, docxml)
body.div **{ class: "WordSection13" } do |_div3|
middle_title_ieee(docxml, body)
end
section_break(body, continuous: true)
body.div **{ class: "WordSection14" } do |div3|
middle docxml, div3
div3
div3
end
end
|
#middle_title(isoxml, out) ⇒ Object
63
|
# File 'lib/isodoc/ieee/word_convert.rb', line 63
def middle_title(isoxml, out); end
|
#middle_title_ieee(_docxml, out) ⇒ Object
65
66
67
68
69
|
# File 'lib/isodoc/ieee/word_convert.rb', line 65
def middle_title_ieee(_docxml, out)
out.p(**{ class: "IEEEStdsTitle", style: "margin-top:70.0pt" }) do |p|
p << @meta.get[:full_doctitle]
end
end
|
#officeholder_style(para) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/isodoc/ieee/word_authority.rb', line 53
def officeholder_style(para)
n = para.next_element
p = para.previous_element
n && n.name == "p" && n["type"] == "officeholder" and
klass = "IEEEStdsNamesCtrCxSpLast"
p && p.name == "p" && p["type"] == "officeholder" and
klass = "IEEEStdsNamesCtrCxSpFirst"
para["class"] = klass || "IEEEStdsNamesCtrCxSpMiddle"
end
|
#officemember_style(docxml) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/isodoc/ieee/word_authority.rb', line 70
def officemember_style(docxml)
docxml.xpath("//p[@type = 'officemember']").each do |p|
p["class"] = "IEEEStdsNamesList"
end
docxml.xpath("//p[@type = 'emeritus_sign']").each do |p|
p["class"] = "IEEEStdsParaMemEmeritus"
end
end
|
#officer_style(docxml) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/isodoc/ieee/word_authority.rb', line 44
def officer_style(docxml)
docxml.xpath("//p[@type = 'officeholder']").each do |p|
officeholder_style(p)
end
officemember_style(docxml)
three_column_officemembers(docxml
.at("//div[@id = 'boilerplate-participants']"))
end
|
#para_type_cleanup(html) ⇒ Object
103
104
105
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 103
def para_type_cleanup(html)
html.xpath("//p[@type]").each { |p| p.delete("type") }
end
|
#span_style_cleanup(html) ⇒ Object
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 107
def span_style_cleanup(html)
html.xpath("//strong").each do |s|
s.name = "span"
s["class"] = "IEEEStdsParaBold"
end
html.xpath("//em").each do |s|
s.name = "span"
s["class"] = "IEEEStdsAddItal"
end
end
|
#style_cleanup(docxml) ⇒ Object
124
125
126
127
128
129
130
131
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 124
def style_cleanup(docxml)
STYLESMAP.each do |k, v|
docxml.xpath("//*[@class = '#{k}']").each { |s| s["class"] = v }
end
docxml.xpath("//p[not(@class)]").each do |p|
p["class"] = "IEEEStdsParagraph"
end
end
|
#three_column_officemembers(div) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/isodoc/ieee/word_authority.rb', line 79
def three_column_officemembers(div)
return unless div
ret = three_column_officemembers_split(div)
three_column_officemembers_render(div, ret)
end
|
#three_column_officemembers_render(div, ret) ⇒ Object
95
96
97
98
99
100
101
102
103
|
# File 'lib/isodoc/ieee/word_authority.rb', line 95
def three_column_officemembers_render(div, ret)
div.children = ret[0]
out = ret[1..-1].map.with_index do |d, i|
para = i % 2 == 1 && i != ret.size - 2 ? "<p> </p>" : ""
"<div class='WordSection'>#{para}#{d}</div>"
end.join(SECTIONBREAK)
div.document.at("//div[@class = 'WordSection11']")
.previous_element.previous = SECTIONBREAK + out
end
|
#three_column_officemembers_split(div) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/isodoc/ieee/word_authority.rb', line 86
def three_column_officemembers_split(div)
prev = false
div.elements.each_with_object([[]]) do |e, m|
member = e.name == "p" && e["type"] == "officemember"
(prev == member and m[-1] << e.to_xml) or m << [e.to_xml]
prev = member
end.map(&:join)
end
|
#toWord(result, filename, dir, header) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 4
def toWord(result, filename, dir, )
result = from_xhtml(word_cleanup(to_xhtml(result)))
.gsub(/-DOUBLE_HYPHEN_ESCAPE-/, "--")
@wordstylesheet = wordstylesheet_update
::Html2Doc::IEEE.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_cleanup(docxml) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/ieee/word_cleanup.rb', line 61
def word_cleanup(docxml)
super
abstract_cleanup(docxml)
introduction_cleanup(docxml)
div_cleanup(docxml)
headings_cleanup(docxml)
span_style_cleanup(docxml)
style_cleanup(docxml)
para_type_cleanup(docxml)
docxml
end
|