Class: IsoDoc::IEEE::WordConvert

Inherits:
WordConvert
  • Object
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,
lib/isodoc/ieee/word_cleanup_blocks.rb

Constant Summary collapse

STYLESMAP =
{
  example: "IEEEStdsParagraph",
  MsoNormal: "IEEEStdsParagraph",
  NormRef: "IEEEStdsParagraph",
  Biblio: "IEEEStdsBibliographicEntry",
  figure: "IEEEStdsImage",
  formula: "IEEEStdsEquation",
  Sourcecode: "IEEEStdsComputerCode",
  TableTitle: "IEEEStdsRegularTableCaption",
  FigureTitle: "IEEEStdsRegularFigureCaption",
}.freeze
SECTIONBREAK =
"<span lang=\"EN-US\" style='font-size:9.0pt;mso-bidi-font-size:10.0pt;font-family:\n\"Times New Roman\",serif;mso-fareast-font-family:\"Times New Roman\";mso-ansi-language:\nEN-US;mso-fareast-language:JA;mso-bidi-language:AR-SA'><br clear=\"all\"\nstyle='page-break-before:auto;mso-break-type:section-break'></span>\n".freeze

Instance Method Summary collapse

Methods included from Init

#fileloc, #i18n_init, #metadata_init, #xref_init

Methods included from BaseConvert

#bracket_if_num, #clause_attrs, #example_label, #middle_clause, #note_delim, #note_p_parse, #note_parse1, #para_attrs, #scope, #termnote_delim

Constructor Details

#initialize(options) ⇒ WordConvert

Returns a new instance of WordConvert.



10
11
12
13
# File 'lib/isodoc/ieee/word_convert.rb', line 10

def initialize(options)
  @libdir = File.dirname(__FILE__)
  super
end

Instance Method Details

#abstract(isoxml, out) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/isodoc/ieee/word_convert.rb', line 50

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



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/isodoc/ieee/word_authority.rb', line 179

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)
    abstract_header(dest)
  end
end

#abstract_cleanup1(source, dest) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
# File 'lib/isodoc/ieee/word_authority.rb', line 191

def abstract_cleanup1(source, dest)
  source.elements.reject { |e| %w(h1 h2).include?(e.name) }.each do |e|
    e1 = e.dup
    e1.xpath(".//p").each do |p|
      p["style"] ||= ""
      p["style"] = 'font-family: "Arial", sans-serif;' + p["style"]
    end
    %w(ul ol).include?(e1.name) or e1["class"] = "IEEEStdsAbstractBody"
    dest << e1
  end
end

#abstract_header(dest) ⇒ Object



203
204
205
206
207
# File 'lib/isodoc/ieee/word_authority.rb', line 203

def abstract_header(dest)
  dest.elements.first.children.first.previous =
    "<span class='IEEEStdsAbstractHeader'><span lang='EN-US'>"\
    "Abstract:</span></span> "
end

#admonition_class(node) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/isodoc/ieee/word_convert.rb', line 91

def admonition_class(node)
  if node["type"] == "editorial" then "zzHelp"
  elsif node.ancestors("introduction").empty?
    "IEEEStdsWarning"
  else "IEEEStdsIntroduction"
  end
end

#admonition_cleanup(docxml) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 4

def admonition_cleanup(docxml)
  super
  docxml.xpath("//div[@class = 'zzHelp']").each do |d|
    d.xpath(".//p").each do |p|
      %w(IEEEStdsWarning IEEEStdsParagraph).include?(p["class"]) ||
        !p["class"] or next

      p["class"] = "zzHelp"
    end
  end
  docxml
end

#admonition_name_parse(_node, div, name) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/isodoc/ieee/word_convert.rb', line 83

def admonition_name_parse(_node, div, name)
  div.p **{ class: "IEEEStdsWarning", style: "text-align:center;" } do |p|
    p.b do |b|
      name.children.each { |n| parse(n, b) }
    end
  end
end

#annex_attrs(node) ⇒ Object



124
125
126
# File 'lib/isodoc/ieee/word_convert.rb', line 124

def annex_attrs(node)
  { id: node["id"], class: "Annex" }
end

#annex_name(_annex, name, div) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/isodoc/ieee/word_convert.rb', line 128

def annex_name(_annex, name, div)
  preceding_floating_titles(name, div)
  return if name.nil?

  name&.at(ns("./strong"))&.remove # supplied by CSS list numbering
  div.h1 **{ class: "Annex" } do |t|
    annex_name1(name, t)
    clause_parse_subtitle(name, t)
  end
end

#annex_name1(name, out) ⇒ Object



139
140
141
142
143
144
145
146
147
148
# File 'lib/isodoc/ieee/word_convert.rb', line 139

def annex_name1(name, out)
  name.children.each do |c2|
    if c2.name == "span" && c2["class"] == "obligation"
      out.span **{ style: "font-weight:normal;" } do |s|
        c2.children.each { |c3| parse(c3, s) }
      end
    else parse(c2, out)
    end
  end
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)
  feedback_footnote(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



161
162
163
164
165
166
167
168
# File 'lib/isodoc/ieee/word_authority.rb', line 161

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



170
171
172
173
174
175
176
177
# File 'lib/isodoc/ieee/word_authority.rb', line 170

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

#biblio_cleanup(docxml) ⇒ Object



51
52
53
54
55
# File 'lib/isodoc/ieee/word_cleanup.rb', line 51

def biblio_cleanup(docxml)
  docxml.xpath("//p[@class = 'Biblio']").each do |p|
    headings_strip(p)
  end
end

#caption_cleanup(docxml) ⇒ Object



75
76
77
78
79
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 75

def caption_cleanup(docxml)
  table_caption(docxml)
  figure_caption(docxml)
  example_caption(docxml)
end

#convert1(docxml, filename, dir) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/isodoc/ieee/word_convert.rb', line 15

def convert1(docxml, filename, dir)
  doctype = docxml.at(ns("//bibdata/ext/doctype"))
  if %w(amendment corrigendum).include?(doctype&.text)
    @header = html_doc_path("header_amd.html")
  end
  super
end


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



41
42
43
44
45
46
47
48
# File 'lib/isodoc/ieee/word_convert.rb', line 41

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: "l11", olstyle: "l16" }
end

#default_fonts(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/isodoc/ieee/word_convert.rb', line 23

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



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/isodoc/ieee/word_cleanup.rb', line 89

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\d*$/.match?(div["class"])

    i += 1
    div["class"] = "WordSection#{i}"
  end
end

#dt_dd?(node) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/isodoc/ieee/word_convert.rb', line 99

def dt_dd?(node)
  %w{dt dd}.include? node.name
end

#example_caption(docxml) ⇒ Object



95
96
97
98
99
100
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 95

def example_caption(docxml)
  docxml.xpath("//p[@class = 'example-title']").each do |s|
    s.children = "<em>#{to_xml(s.children)}</em>"
    s["class"] = "IEEEStdsParagraph"
  end
end

#feedback_footnote(docxml) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/isodoc/ieee/word_authority.rb', line 13

def feedback_footnote(docxml)
  feedback_style(docxml)
  feedback_table(docxml)
  f = docxml.at("//div[@class = 'boilerplate-feedback']") or return
  docxml.at("//aside").previous = "    <aside id=\"ftn0\">\#{to_xml(f.remove)}</aside>\n  FN\nend\n"

#feedback_style(docxml) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/isodoc/ieee/word_authority.rb', line 140

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>&#xa0;</p>"
    i == 4 and
      div.xpath(".//p[br]").each do |p|
        p.replace(to_xml(p).gsub(%r{<br/>}, "</p><p>"))
      end
    feedback_style1(div, i)
  end
end

#feedback_style1(div, idx) ⇒ Object



152
153
154
155
156
157
158
159
# File 'lib/isodoc/ieee/word_authority.rb', line 152

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



121
122
123
124
125
126
127
128
129
# File 'lib/isodoc/ieee/word_authority.rb', line 121

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



131
132
133
134
135
136
137
138
# File 'lib/isodoc/ieee/word_authority.rb', line 131

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

#figure_caption(docxml) ⇒ Object



88
89
90
91
92
93
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 88

def figure_caption(docxml)
  docxml.xpath("//p[@class = 'FigureTitle']").each do |s|
    s.children = to_xml(s.children)
      .sub(/^#{@i18n.figure}(\s+[A-Z0-9.]+)?/, "")
  end
end

#figure_toc_classObject



118
119
120
# File 'lib/isodoc/ieee/word_cleanup.rb', line 118

def figure_toc_class
  %w(IEEEStdsRegularFigureCaption FigureTitle figuretitle)
end

#formula_where(dlist, out) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/isodoc/ieee/word_convert.rb', line 103

def formula_where(dlist, out)
  return unless dlist

  dlist.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
    formula_where1(out, dt, dd)
  end
end

#formula_where1(out, dterm, ddefn) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/isodoc/ieee/word_convert.rb', line 111

def formula_where1(out, dterm, ddefn)
  out.p **{ class: "IEEEStdsEquationVariableList" } do |p|
    dterm.children.each { |n| parse(n, p) }
    insert_tab(p, 1)
    if ddefn.at(ns("./p"))
      ddefn.elements.each do |e|
        e.children.each { |n| parse(n, p) }
      end
    else ddefn.children.each { |n| parse(n, p) }
    end
  end
end

#headings_cleanup(docxml) ⇒ Object



57
58
59
60
# File 'lib/isodoc/ieee/word_cleanup.rb', line 57

def headings_cleanup(docxml)
  (1..9).each { |i| headings_cleanup1(docxml, i) }
  docxml.xpath("//div[@class = 'Annex']").each { |a| a.delete("class") }
end

#headings_cleanup1(docxml, idx) ⇒ Object



62
63
64
65
66
67
# File 'lib/isodoc/ieee/word_cleanup.rb', line 62

def headings_cleanup1(docxml, idx)
  docxml.xpath("//h#{idx}").each do |h|
    headings_strip(h)
    headings_style(h, idx)
  end
end

#headings_strip(hdr) ⇒ Object



82
83
84
85
86
87
# File 'lib/isodoc/ieee/word_cleanup.rb', line 82

def headings_strip(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

#headings_style(hdr, idx) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/isodoc/ieee/word_cleanup.rb', line 69

def headings_style(hdr, idx)
  if hdr.at("./ancestor::div[@class = 'Annex']")
    hdr.delete("class")
    hdr["style"] = "mso-list:l13 level#{idx} lfo33;"
  elsif hdr.at("./ancestor::div[@class = 'Section3']")
    hdr.name = "p"
    hdr["class"] = "IEEEStdsLevel#{idx}frontmatter"
  else
    hdr.name = "p"
    hdr["class"] = "IEEEStdsLevel#{idx}Header"
  end
end

#introduction_cleanup(docxml) ⇒ Object



209
210
211
212
213
214
215
216
# File 'lib/isodoc/ieee/word_authority.rb', line 209

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



218
219
220
221
222
223
224
225
226
227
# File 'lib/isodoc/ieee/word_authority.rb', line 218

def introduction_cleanup1(intro, dest)
  docxml = intro.document
  intro.previous_element.remove
  dest.replace(intro.remove)
  i = docxml.at("//h1[@class = 'IntroTitle']")
  if i.next_element.name == "div" &&
      i.next_element["class"] == "IEEEStdsIntroduction"
    i.next_element.name = "p"
  end
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



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/isodoc/ieee/word_convert.rb', line 59

def make_body3(body, docxml)
  body.div **{ class: "WordSectionMiddleTitle" } do |_div3|
    middle_title_ieee(docxml, body)
  end
  section_break(body, continuous: true)
  body.div **{ class: "WordSectionMain" } do |div3|
    middle docxml, div3
    footnotes div3
    comments div3
  end
end

#make_WordToC(docxml, level) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/isodoc/ieee/word_cleanup.rb', line 39

def make_WordToC(docxml, level)
  toc = ""
  xpath = (1..level).each.map do |i|
    "//h#{i}[not(ancestor::*[@class = 'WordSection2'])]"
  end.join (" | ")
  docxml.xpath(xpath).each do |h|
    toc += word_toc_entry(h.name[1].to_i, header_strip(h))
  end
  toc.sub(/(<p class="MsoToc1">)/,
          %{\\1#{word_toc_preface(level)}}) + WORD_TOC_SUFFIX1
end

#middle_title(isoxml, out) ⇒ Object



71
# File 'lib/isodoc/ieee/word_convert.rb', line 71

def middle_title(isoxml, out); end

#middle_title_ieee(_docxml, out) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/isodoc/ieee/word_convert.rb', line 73

def middle_title_ieee(_docxml, out)
  out.p(**{ class: "IEEEStdsTitle", style: "margin-top:70.0pt" }) do |p|
    p << @meta.get[:full_doctitle]
    @meta.get[:amd] || @meta.get[:corr] and p << "<br/>"
    @meta.get[:amd] and p << "Amendment #{@meta.get[:amd]}"
    @meta.get[:amd] && @meta.get[:corr] and p << " "
    @meta.get[:corr] and p << "Corrigenda #{@meta.get[:corr]}"
  end
end

#note_style_cleanup(docxml) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 112

def note_style_cleanup(docxml)
  docxml.xpath("//span[@class = 'note_label']").each do |s|
    multi = /^#{@i18n.note}\s+[A-Z0-9.]+/.match?(s.text)
    div = s.at("./ancestor::div[@class = 'Note']")
    if multi
      s.remove
      seq = notesequence(div)
    else seq = nil
    end
    note_style_cleanup1(multi, div, seq)
  end
end

#note_style_cleanup1(multi, div, seq) ⇒ Object

hardcoded list style for notes



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 138

def note_style_cleanup1(multi, div, seq)
  div.xpath(".//p[@class = 'Note' or not(@class)]")
    .each_with_index do |p, i|
    p["class"] =
      i.zero? && multi ? "IEEEStdsMultipleNotes" : "IEEEStdsSingleNote"
    if multi
      p["style"] ||= ""
      p["style"] += "mso-list:l17 level1 lfo#{seq};"
    end
  end
end

#notesequence(div) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 125

def notesequence(div)
  @notesequences ||= { max: 0, lookup: {} }
  unless id = @notesequences[:lookup][@xrefs.anchor(div["id"],
                                                    :sequence)]
    @notesequences[:max] += 1
    id = @notesequences[:max]
    @notesequences[:lookup][@xrefs.anchor(div["id"], :sequence)] =
      id
  end
  id
end

#officeholder_style(para) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/isodoc/ieee/word_authority.rb', line 54

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



71
72
73
74
75
76
77
78
79
# File 'lib/isodoc/ieee/word_authority.rb', line 71

def officemember_style(docxml)
  docxml.xpath("//p[@type = 'officemember' or @type = 'officeorgmember']")
    .each do |p|
    p["class"] = "IEEEStdsNamesList"
  end
  docxml.xpath("//p[@type = 'emeritus_sign']").each do |p|
    p["class"] = "IEEEStdsParaMemEmeritus"
  end
end

#officeorgrep_style(docxml) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/isodoc/ieee/word_authority.rb', line 81

def officeorgrep_style(docxml)
  docxml.xpath("//p[@type = 'officeorgrepmemberhdr']").each do |p|
    p["class"] = "IEEEStdsNamesList"
    p["style"] =
      "margin-bottom:6.0pt;tab-stops:right 432.0pt;"
  end
  docxml.xpath("//p[@type = 'officeorgrepmember']").each do |p|
    p["class"] = "IEEEStdsNamesList"
    p["style"] =
      "margin-top:6.0pt;tab-stops:right dotted 432.0pt;"
  end
end

#officer_style(docxml) ⇒ Object



44
45
46
47
48
49
50
51
52
# 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)
  officeorgrep_style(docxml)
  three_column_officemembers(docxml
    .at("//div[@id = 'boilerplate-participants']"))
end

#para_type_cleanup(html) ⇒ Object



108
109
110
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 108

def para_type_cleanup(html)
  html.xpath("//p[@type]").each { |p| p.delete("type") }
end

#sourcecode_cleanup(docxml) ⇒ Object



102
103
104
105
106
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 102

def sourcecode_cleanup(docxml)
  docxml.xpath("//p[@class = 'Sourcecode']").each do |s|
    s.replace(to_xml(s).gsub(%r{<br/>}, "</p><p class='Sourcecode'>"))
  end
end

#sourcecode_styleObject



20
21
22
# File 'lib/isodoc/ieee/word_cleanup.rb', line 20

def sourcecode_style
  "IEEEStdsComputerCode"
end

#style_cleanup(docxml) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/isodoc/ieee/word_cleanup.rb', line 122

def style_cleanup(docxml)
  note_style_cleanup(docxml)
  docxml.xpath("//div[@class = 'formula']/p").each do |p|
    p["class"] = "IEEEStdsEquation"
  end
  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

#table_caption(docxml) ⇒ Object



81
82
83
84
85
86
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 81

def table_caption(docxml)
  docxml.xpath("//p[@class = 'TableTitle']").each do |s|
    s.children = to_xml(s.children)
      .sub(/^#{@i18n.table}(\s+[A-Z0-9.]+)?/, "")
  end
end

#table_cleanup(docxml) ⇒ Object



17
18
19
20
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 17

def table_cleanup(docxml)
  thead_cleanup(docxml)
  tbody_cleanup(docxml)
end

#table_toc_classObject



114
115
116
# File 'lib/isodoc/ieee/word_cleanup.rb', line 114

def table_toc_class
  %w(IEEEStdsRegularTableCaption TableTitle tabletitle)
end

#tbody_cleanup(docxml) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 37

def tbody_cleanup(docxml)
  docxml.xpath("//tbody | //tfoot").each do |h|
    next if h.at("./ancestor::div[@class = 'boilerplate-feedback']")

    h.xpath(".//th").each { |t| tbody_head_cleanup(t) }
    h.xpath(".//td | .//th").each { |t| tbody_cleanup1(t) }
  end
end

#tbody_cleanup1(cell) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 54

def tbody_cleanup1(cell)
  if cell.at("./p")
    cell.xpath("./p").each_with_index do |p, i|
      p["class"] = td_style(cell, i)
    end
  else
    cell.children =
      "<p class='#{td_style(cell, 0)}'>#{to_xml(cell.children)}</p>"
  end
end

#tbody_head_cleanup(cell) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 46

def tbody_head_cleanup(cell)
  cell.at("./p") or
    cell.children = "<p>#{to_xml(cell.children)}</p>"
  cell.xpath("./p").each do |p|
    p.replace to_xml(p).gsub(%r{<br/>}, "</p><p>")
  end
end

#td_style(cell, idx) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 65

def td_style(cell, idx)
  if cell.name == "th" && idx.zero? then "IEEEStdsTableLineHead"
  elsif cell.name == "th" then "IEEEStdsTableLineSubhead"
  elsif cell["align"] == "center" ||
      /text-align:center/.match?(cell["style"])
    "IEEEStdsTableData-Center"
  else "IEEEStdsTableData-Left"
  end
end

#termnote_label(para, name) ⇒ Object



160
161
162
163
164
165
# File 'lib/isodoc/ieee/word_convert.rb', line 160

def termnote_label(para, name)
  para.span **{ class: "note_label" } do |s|
    name.children.each { |n| parse(n, s) }
    s << termnote_delim
  end
end

#termnote_parse(node, out) ⇒ Object



150
151
152
153
154
155
156
157
158
# File 'lib/isodoc/ieee/word_convert.rb', line 150

def termnote_parse(node, out)
  name = node&.at(ns("./name"))&.remove
  out.div **note_attrs(node) do |div|
    div.p do |p|
      name and termnote_label(p, name)
      para_then_remainder(node.first_element_child, node, p, div)
    end
  end
end

#thead_cleanup(docxml) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 22

def thead_cleanup(docxml)
  docxml.xpath("//thead").each do |h|
    h.xpath(".//td | .//th").each do |t|
      if t.at("./p")
        t.xpath("./p").each do |p|
          p["class"] = "IEEEStdsTableColumnHead"
        end
      else
        t.children =
          "<p class='IEEEStdsTableColumnHead'>#{to_xml(t.children)}</p>"
      end
    end
  end
end

#three_column_officemembers(div) ⇒ Object



94
95
96
97
98
99
# File 'lib/isodoc/ieee/word_authority.rb', line 94

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



111
112
113
114
115
116
117
118
119
# File 'lib/isodoc/ieee/word_authority.rb', line 111

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>&#xa0;</p>" : ""
    "<div class='WordSection'>#{para}#{d}</div>"
  end.join(SECTIONBREAK)
  div.document.at("//div[@class = 'WordSectionIntro']")
    .previous_element.previous = SECTIONBREAK + out
end

#three_column_officemembers_split(div) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/isodoc/ieee/word_authority.rb', line 101

def three_column_officemembers_split(div)
  prev = false
  div.xpath(".//div").each { |d| d.replace(d.children) }
  div.elements.each_with_object([[]]) do |e, m|
    member = e.name == "p" && e["type"] == "officemember"
    (prev == member and m[-1] << to_xml(e)) or m << [to_xml(e)]
    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, header)
  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: header&.path, dir: dir,
    asciimathdelims: [@openmathdelim, @closemathdelim],
    liststyles: { ul: @ulstyle, ol: @olstyle }
  ).process(result)
  header&.unlink
  @wordstylesheet.unlink if @wordstylesheet.is_a?(Tempfile)
end

#word_cleanup(docxml) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/isodoc/ieee/word_cleanup.rb', line 24

def word_cleanup(docxml)
  super
  abstract_cleanup(docxml)
  introduction_cleanup(docxml)
  sourcecode_cleanup(docxml)
  div_cleanup(docxml)
  biblio_cleanup(docxml)
  headings_cleanup(docxml)
  caption_cleanup(docxml)
  table_cleanup(docxml)
  style_cleanup(docxml)
  para_type_cleanup(docxml)
  docxml
end