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

Direct Known Subclasses

WordWPConvert

Constant Summary collapse

MAIN_ELEMENTS =
"//sections/*[@displayorder][not(@class = 'zzSTDTitle1')] | " \
"//annex[@displayorder] | " \
"//bibliography/*[@displayorder] | //colophon/*[@displayorder] | " \
"//indexsect[@displayorder]".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

Methods included from Init

#fileloc, #i18n_init, #metadata_init, #std_docid_sdo, #std_docid_semantic, #std_docid_semantic1, #std_docid_semantic_full, #xref_init

Methods included from BaseConvert

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

Constructor Details

#initialize(options) ⇒ WordConvert

Returns a new instance of WordConvert.



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

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

Instance Method Details

#abstract(clause, out) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/isodoc/ieee/word_convert.rb', line 67

def abstract(clause, out)
  page_break(out)
  out.div **attr_code(id: clause["id"], class: "abstract") do |s|
    clause_name(clause, clause.at(ns("./title")), s,
                { class: stylesmap[:AbstractTitle] })
    clause.elements.each { |e| parse(e, s) unless e.name == "title" }
  end
end

#abstract_cleanup(docxml) ⇒ Object



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

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



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

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

#abstract_header(dest) ⇒ Object



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

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



110
111
112
113
114
115
116
# File 'lib/isodoc/ieee/word_convert.rb', line 110

def admonition_class(node)
  if node["type"] == "editorial" then "zzHelp"
  elsif node.ancestors("introduction").empty?
    stylesmap[:admonition]
  else stylesmap[:intro]
  end
end

#admonition_cleanup(docxml) ⇒ Object

STYLE



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

def admonition_cleanup(docxml)
  super
  docxml.xpath("//div[@class = 'zzHelp']").each do |d|
    d.xpath(".//p").each do |p|
      [stylesmap[:admonition], stylesmap[:MsoNormal]]
        .include?(p["class"]) || !p["class"] or next
      p["class"] = "zzHelp"
    end
  end
  docxml
end

#admonition_name_parse(_node, div, name) ⇒ Object



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

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

#annex_attrs(node) ⇒ Object



156
157
158
# File 'lib/isodoc/ieee/word_convert.rb', line 156

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

#annex_name(_annex, name, div) ⇒ Object



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

def annex_name(_annex, 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



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

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



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

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



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

def authority_cleanup_hdr(auth)
  (1..2).each do |i|
    auth&.xpath(".//h#{i}")&.each do |h|
      h.name = "p"
      h["class"] = "level#{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



54
55
56
57
58
# File 'lib/isodoc/ieee/word_cleanup.rb', line 54

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

#caption_cleanup(docxml) ⇒ Object



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

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

#convert(input_filename, file = nil, debug = false, output_filename = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/isodoc/ieee/word_convert.rb', line 28

def convert(input_filename, file = nil, debug = false,
    output_filename = nil)
  file ||= File.read(input_filename, encoding: "utf-8")
  docxml = Nokogiri::XML(file, &:huge)
  doctype = docxml&.at(ns("//bibdata/ext/doctype"))&.text
  if @wp && doctype == "whitepaper"
    @wp.convert(input_filename, file, debug, output_filename)
  else
    super
  end
end

#convert1(docxml, filename, dir) ⇒ Object



21
22
23
24
25
26
# File 'lib/isodoc/ieee/word_convert.rb', line 21

def convert1(docxml, filename, dir)
  if %w(amendment corrigendum).include?(@doctype)
    @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



58
59
60
61
62
63
64
65
# File 'lib/isodoc/ieee/word_convert.rb', line 58

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/isodoc/ieee/word_convert.rb', line 40

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

STYLE



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/isodoc/ieee/word_cleanup.rb', line 93

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)


130
131
132
# File 'lib/isodoc/ieee/word_convert.rb', line 130

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

#example_caption(docxml) ⇒ Object



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

def example_caption(docxml)
  docxml.xpath("//p[@class = 'example-title']").each do |s|
    s.children = "<em>#{to_xml(s.children)}</em>"
    s["class"] = stylesmap[:MsoNormal]
  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 = <<~FN
    <aside id="ftn0">#{to_xml(f.remove)}</aside>
  FN
end

#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

STYLE



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

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



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

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

STYLE



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



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

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



144
145
146
# File 'lib/isodoc/ieee/word_cleanup.rb', line 144

def figure_toc_class
  [stylesmap[:FigureTitle], "FigureTitle", "figuretitle"]
end

#formula_parse(node, out) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/isodoc/ieee/word_convert.rb', line 118

def formula_parse(node, out)
  out.div **formula_attrs(node) do |div|
    formula_parse1(node, div)
    formula_where(node.at(ns("./dl")), div)
    node.children.each do |n|
      next if %w(stem dl name).include? n.name

      parse(n, div)
    end
  end
end

#formula_where(dlist, out) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/isodoc/ieee/word_convert.rb', line 134

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

STYLE



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/isodoc/ieee/word_convert.rb', line 143

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



60
61
62
63
# File 'lib/isodoc/ieee/word_cleanup.rb', line 60

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



65
66
67
68
69
70
# File 'lib/isodoc/ieee/word_cleanup.rb', line 65

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



85
86
87
88
89
90
# File 'lib/isodoc/ieee/word_cleanup.rb', line 85

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



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

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' or @class = 'WordSectionContents']")
    hdr.name = "p"
    hdr["class"] = stylesmap["level#{idx}frontmatter".to_sym]
  else
    hdr.name = "p"
    hdr["class"] = stylesmap["level#{idx}header".to_sym]
  end
end

#init_wp(options) ⇒ Object



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

def init_wp(options)
  @wp = ::IsoDoc::IEEE::WordWPConvert.new(options)
end

#insert_toc(intro, docxml, level) ⇒ Object



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

def insert_toc(intro, docxml, level)
  toc = assemble_toc(docxml, level)
  source = docxml.at("//div[@class = 'WordSectionContents']") and
    source << toc
  intro
end

#introduction_cleanup(docxml) ⇒ Object



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

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



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

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"] == stylesmap[:intro]
    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



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

def make_body3(body, docxml)
  body.div class: "WordSectionMiddleTitle" do |div3|
    middle_title_ieee(docxml, div3)
  end
  section_break(body, continuous: true)
  body.div class: "WordSectionMain" do |div3|
    content(div3, docxml, ns(self.class::MAIN_ELEMENTS))
    footnotes div3
    comments div3
  end
end

#make_WordToC(docxml, level) ⇒ Object



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

def make_WordToC(docxml, level)
  toc = ""
  if source = docxml.at("//div[@class = 'TOC']")
    toc = to_xml(source.children)
  end
  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_ieee(docxml, out) ⇒ Object



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

def middle_title_ieee(docxml, out)
  title = docxml.at(ns("//p[@class = 'zzSTDTitle1']")) or return
  out.p(class: stylesmap[:zzSTDTitle1],
        style: "margin-left:0cm;margin-top:70.0pt") do |p|
    title.children.each { |n| parse(n, p) }
  end
end

#note_style_cleanup(docxml) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 117

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 STYLE



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 144

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



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 130

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"] = stylesmap[:nameslist]
  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"] = stylesmap[:nameslist]
    p["style"] =
      "margin-bottom:6.0pt;tab-stops:right 432.0pt;"
  end
  docxml.xpath("//p[@type = 'officeorgrepmember']").each do |p|
    p["class"] = stylesmap[:nameslist]
    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



113
114
115
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 113

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

#sourcecode_cleanup(docxml) ⇒ Object



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

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
  stylesmap[:Sourcecode]
end

#style_cleanup(docxml) ⇒ Object



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

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

#stylesmapObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/isodoc/ieee/word_cleanup.rb', line 106

def stylesmap
  {
    example: "IEEEStdsParagraph",
    MsoNormal: "IEEEStdsParagraph",
    NormRef: "IEEEStdsParagraph",
    Biblio: "IEEEStdsBibliographicEntry",
    figure: "IEEEStdsImage",
    formula: "IEEEStdsEquation",
    Sourcecode: "IEEEStdsComputerCode",
    TableTitle: "IEEEStdsRegularTableCaption",
    FigureTitle: "IEEEStdsRegularFigureCaption",
    admonition: "IEEEStdsWarning",
    abstract: "IEEEStdsAbstractBody",
    AbstractTitle: "AbstractTitle",
    level1frontmatter: "IEEEStdsLevel1frontmatter",
    level2frontmatter: "IEEEStdsLevel2frontmatter",
    level3frontmatter: "IEEEStdsLevel3frontmatter",
    level1header: "IEEEStdsLevel1Header",
    level2header: "IEEEStdsLevel2Header",
    level3header: "IEEEStdsLevel3Header",
    level4header: "IEEEStdsLevel4Header",
    level5header: "IEEEStdsLevel5Header",
    level6header: "IEEEStdsLevel6Header",
    zzSTDTitle1: "IEEEStdsTitle",
    tabledata_center: "IEEEStdsTableData-Center",
    tabledata_left: "IEEEStdsTableData-Left",
    table_head: "IEEEStdsTableLineHead",
    table_subhead: "IEEEStdsTableLineSubhead",
    table_columnhead: "IEEEStdsTableColumnHead",
    nameslist: "IEEEStdsNamesList",
    intro: "IEEEStdsIntroduction",
  }
end

#table_caption(docxml) ⇒ Object



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

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_of_contents(clause, out) ⇒ Object

STYLE



199
200
201
202
203
204
205
206
207
# File 'lib/isodoc/ieee/word_convert.rb', line 199

def table_of_contents(clause, out)
  out.div class: "WordSectionContents" do |div|
    clause_name(clause, clause.at(ns("./title")), div,
                { class: "IEEEStdsLevel1frontmatter" })
    clause.elements.each do |e|
      parse(e, div) unless e.name == "title"
    end
  end
end

#table_toc_classObject



140
141
142
# File 'lib/isodoc/ieee/word_cleanup.rb', line 140

def table_toc_class
  [stylesmap[:TableTitle], "TableTitle", "tabletitle"]
end

#tbody_cleanup(docxml) ⇒ Object



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

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



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

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



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

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



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

def td_style(cell, idx)
  if cell.name == "th" && idx.zero? then stylesmap[:table_head]
  elsif cell.name == "th" then stylesmap[:table_subhead]
  elsif cell["align"] == "center" ||
      cell["style"].include?("text-align:center")
    stylesmap[:tabledata_center]
  else stylesmap[:tabledata_left]
  end
end

#termnote_label(para, name) ⇒ Object



191
192
193
194
195
196
# File 'lib/isodoc/ieee/word_convert.rb', line 191

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



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

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_cell_cleanup(cell) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/isodoc/ieee/word_cleanup_blocks.rb', line 30

def thead_cell_cleanup(cell)
  s = stylesmap[:table_columnhead]
  if cell.at("./p")
    cell.xpath("./p").each do |p|
      p["class"] = s
    end
  else
    cell.children =
      "<p class='#{s}'>#{to_xml(cell.children)}</p>"
  end
end

#thead_cleanup(docxml) ⇒ Object



22
23
24
25
26
27
28
# 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|
      thead_cell_cleanup(t)
    end
  end
end

#three_column_officemembers(div) ⇒ Object



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

def three_column_officemembers(div)
  div or return
  ret = three_column_officemembers_split(div)
  three_column_officemembers_render(div, ret)
end

#three_column_officemembers_render(div, ret) ⇒ Object



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

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



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

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