Module: IsoDoc::HtmlFunction::Footnotes

Included in:
IsoDoc::HeadlessHtmlConvert, IsoDoc::HtmlConvert, PdfConvert
Defined in:
lib/isodoc/html_function/footnotes.rb

Instance Method Summary collapse

Instance Method Details

#footnote_parse(node, out) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/isodoc/html_function/footnotes.rb', line 62

def footnote_parse(node, out)
  return table_footnote_parse(node, out) if @in_table || @in_figure
  fn = node["reference"]
  attrs = { "epub:type": "footnote", rel: "footnote", href: "#fn:#{fn}" }
  out.a **attrs do |a|
    a.sup { |sup| sup << fn }
  end
  make_footnote(node, fn)
end

#footnotes(div) ⇒ Object



4
5
6
7
# File 'lib/isodoc/html_function/footnotes.rb', line 4

def footnotes(div)
  return if @footnotes.empty?
  @footnotes.each { |fn| div.parent << fn }
end

#get_table_ancestor_id(node) ⇒ Object



42
43
44
45
46
# File 'lib/isodoc/html_function/footnotes.rb', line 42

def get_table_ancestor_id(node)
  table = node.ancestors("table") || node.ancestors("figure")
  return UUIDTools::UUID.random_create.to_s if table.empty?
  table.last["id"]
end

#make_footnote(node, fn) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/isodoc/html_function/footnotes.rb', line 72

def make_footnote(node, fn)
  return if @seen_footnote.include?(fn)
  @in_footnote = true
  @footnotes << make_generic_footnote_text(node, fn)
  @in_footnote = false
  @seen_footnote << fn
end

#make_generic_footnote_text(node, fnid) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/isodoc/html_function/footnotes.rb', line 34

def make_generic_footnote_text(node, fnid)
  noko do |xml|
    xml.aside **{ id: "fn:#{fnid}", class: "footnote" } do |div|
      node.children.each { |n| parse(n, div) }
    end
  end.join("\n")
end


9
10
11
12
13
14
# File 'lib/isodoc/html_function/footnotes.rb', line 9

def make_table_footnote_link(out, fnid, fnref)
  attrs = { href: "##{fnid}", class: "TableFootnoteRef" }
  out.a **attrs do |a|
    a << fnref
  end
end

#make_table_footnote_target(out, fnid, fnref) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/isodoc/html_function/footnotes.rb', line 16

def make_table_footnote_target(out, fnid, fnref)
  attrs = { id: fnid, class: "TableFootnoteRef" }
  out.a **attrs do |a|
    a << fnref
    insert_tab(a, 1)
  end
end

#make_table_footnote_text(node, fnid, fnref) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/isodoc/html_function/footnotes.rb', line 24

def make_table_footnote_text(node, fnid, fnref)
  attrs = { id: "fn:#{fnid}" }
  noko do |xml|
    xml.div **attr_code(attrs) do |div|
      make_table_footnote_target(div, fnid, fnref)
      node.children.each { |n| parse(n, div) }
    end
  end.join("\n")
end

#table_footnote_parse(node, out) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/isodoc/html_function/footnotes.rb', line 48

def table_footnote_parse(node, out)
  fn = node["reference"]
  tid = get_table_ancestor_id(node)
  make_table_footnote_link(out, tid + fn, fn)
  # do not output footnote text if we have already seen it for this table
  return if @seen_footnote.include?(tid + fn)
  @in_footnote = true
  out.aside **{ class: "footnote" } do |a|
    a << make_table_footnote_text(node, tid + fn, fn)
  end
  @in_footnote = false
  @seen_footnote << (tid + fn)
end