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



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

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

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

#list2para1(list, level, type) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/html2doc/ieee/lists.rb', line 42

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



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

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
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/html2doc/ieee/lists.rb', line 3

def style_list(elem, level, liststyle, listnumber)
  return unless liststyle

  sameelem_level = elem.ancestors.map(&:name).count(elem.parent.name)
  if elem["style"]
    elem["style"] += ";"
  else
    elem["style"] = ""
  end
  sameelem_level1 = sameelem_level
  if liststyle == "l11" && sameelem_level.to_i > 1
    liststyle = "l21"
    sameelem_level1 -= 1
  end
  if liststyle == "l16"
    s = case elem.parent["type"]
        when "a" then 1
        when "1" then 2
        else 3
        end
    sameelem_level1 += s - (sameelem_level1 % 3)
    sameelem_level1 < 1 and sameelem_level1 += 3
  end
  elem["style"] += "mso-list:#{liststyle} level#{sameelem_level1} lfo#{listnumber}-#{level};"
  elem["style"] += "text-indent:-0.79cm; margin-left:#{0.4 + (level.to_i * 0.76)}cm;"
  elem.parent["level"] = level
  elem.parent["sameelem_level"] = sameelem_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