Class: Html2Doc::IEEE

Inherits:
Html2Doc show all
Defined in:
lib/html2doc/ieee.rb

Instance Method Summary collapse

Instance Method Details

#footnote_container_nofn(_docxml, idx) ⇒ Object



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

def footnote_container_nofn(_docxml, idx)
  <<~DIV
    <div style='mso-element:footnote' id='ftn#{idx}'>
      <a style='mso-footnote-id:ftn#{idx}' href='#_ftn#{idx}'
         name='_ftnref#{idx}' title='' id='_ftnref#{idx}'></a></div>
  DIV
end

#footnote_div_to_p_unstyled(elem) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/html2doc/ieee.rb', line 28

def footnote_div_to_p_unstyled(elem)
  if %w{div aside}.include? elem.name
    if elem.at(".//p")
      elem.replace(elem.children)
    else
      elem.name = "p"
    end
  end
end

#list2para(list) ⇒ Object



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

def list2para(list)
  return if list.xpath("./li").empty?

  if list.name == "ol"
    list2para_ol(list)
  else
    list2para_ul(list)
  end
end

#list2para_ol(list) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/html2doc/ieee.rb', line 74

def list2para_ol(list)
  list.xpath("./li").first["class"] ||= "IEEEStdsNumberedListLevel1CxSpFirst"
  list.xpath("./li").last["class"] ||= "IEEEStdsNumberedListLevel1CxSpLast"
  list.xpath("./li/p").each do |p|
    p["class"] ||= "IEEEStdsNumberedListLevel1CxSpMiddle"
  end
  list.xpath("./li").each do |l|
    l.name = "p"
    l["class"] ||= "IEEEStdsNumberedListLevel1CxSpMiddle"
    l&.first_element_child&.name == "p" and
      l.first_element_child.replace(l.first_element_child.children)
  end
  list.replace(list.children)
end

#list2para_ul(list) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/html2doc/ieee.rb', line 59

def list2para_ul(list)
  list.xpath("./li").first["class"] ||= "IEEEStdsUnorderedListCxSpFirst"
  list.xpath("./li").last["class"] ||= "IEEEStdsUnorderedListCxSpLast"
  list.xpath("./li/p").each do |p|
    p["class"] ||= "IEEEStdsUnorderedListCxSpMiddle"
  end
  list.xpath("./li").each do |l|
    l.name = "p"
    l["class"] ||= "IEEEStdsUnorderedListCxSpMiddle"
    l&.first_element_child&.name == "p" and
      l.first_element_child.replace(l.first_element_child.children)
  end
  list.replace(list.children)
end

#process_footnote_texts(docxml, footnotes) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/html2doc/ieee.rb', line 3

def process_footnote_texts(docxml, footnotes)
  body = docxml.at("//body")
  list = body.add_child("<div style='mso-element:footnote-list'/>")
  footnotes.each_with_index do |f, i|
    if i.zero?
      fn = list.first.add_child(footnote_container_nofn(docxml, i + 1))
      f.parent = fn.first
      footnote_div_to_p_unstyled(f)
    else
      fn = list.first.add_child(footnote_container(docxml, i + 1))
      f.parent = fn.first
      footnote_div_to_p(f)
    end
  end
  footnote_cleanup(docxml)
end

#transform_footnote_text(note) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/html2doc/ieee.rb', line 38

def transform_footnote_text(note)
  note["id"] = ""
  note.xpath(".//div").each { |div| div.replace(div.children) }
  note.xpath(".//aside | .//p").each do |p|
    p.name = "p"
    %w(IEEEStdsCRTextReg IEEEStdsCRTextItal).include?(p["class"]) or
      p["class"] = "IEEEStdsFootnote"
  end
  note.remove
end