Class: Html2Doc::IEEE

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

Instance Method Summary collapse

Instance Method Details

#cleanup(docxml) ⇒ Object



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

def cleanup(docxml)
  super
  docxml.xpath("//div[@class = 'Note']").each do |d|
    d.delete("class")
  end
  docxml
end

#footnote_container_nofn(_docxml, idx) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/html2doc/ieee/notes.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/notes.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



8
9
10
11
12
13
14
# File 'lib/html2doc/ieee/lists.rb', line 8

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

  level = list["level"] || "1"
  list.delete("level")
  list2para1(list, level, list.name)
end

#list2para1(list, level, type) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/html2doc/ieee/lists.rb', line 16

def list2para1(list, level, type)
  list.xpath("./li").first["class"] ||= list_style(type, level, "First")
  list.xpath("./li").last["class"] ||= list_style(type, level, "Last")
  list.xpath("./li/p").each do |p|
    p["class"] ||= list_style(type, level, "Middle")
  end
  list.xpath("./li").each do |l|
    l.name = "p"
    l["class"] ||= list_style(type, level, "Middle")
    next unless l&.first_element_child&.name == "p"

    l["style"] += (l.first_element_child["style"]&.sub(/mso-list[^;]+;/, "") || "")
    l.first_element_child.replace(l.first_element_child.children)
  end
  list.replace(list.children)
end

#list_style(listtype, level, position) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/html2doc/ieee/lists.rb', line 33

def list_style(listtype, level, position)
  case listtype
  when "ol" then "IEEEStdsNumberedListLevel#{level}CxSp#{position}"
  when "ul"
    case level
    when "1" then "IEEEStdsUnorderedListCxSp#{position}"
    else "IEEEStdsUnorderedListLevel2"
    end
  end
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/notes.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

#style_list(elem, level, liststyle, listnumber) ⇒ Object



3
4
5
6
# File 'lib/html2doc/ieee/lists.rb', line 3

def style_list(elem, level, liststyle, listnumber)
  super
  elem.parent["level"] = level
end

#transform_footnote_text(note) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/html2doc/ieee/notes.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