Module: IsoDoc::WordFunction::Footnotes

Included in:
IsoDoc::WordConvert
Defined in:
lib/isodoc/word_function/footnotes.rb

Instance Method Summary collapse

Instance Method Details

#bookmarkidObject



4
5
6
7
8
9
10
11
# File 'lib/isodoc/word_function/footnotes.rb', line 4

def bookmarkid
  ret = "X"
  until !@bookmarks_allocated[ret]
    ret = Random.rand(1000000000)
  end
  @bookmarks_allocated[ret] = true
  sprintf "%09d", ret
end

#fmt_fn_body_parse(node, out) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/isodoc/word_function/footnotes.rb', line 13

def fmt_fn_body_parse(node, out)
  node.at(ns(".//fmt-fn-label"))&.remove
  aside = node.parent.name == "fmt-footnote-container"
  tag = aside ? "aside" : "div"
  id = node["is_table"] ? node["reference"] : node["id"]
  out.send tag, id: "ftn#{id}" do |div|
    children_parse(node, div)
  end
end


61
62
63
64
65
66
67
68
# File 'lib/isodoc/word_function/footnotes.rb', line 61

def footnote_hyperlink(node, out)
  if semx = out.parent.at(".//span[@class = 'FMT-PLACEHOLDER']")
    semx.name = "a"
    semx["class"] = "FootnoteRef"
    semx["epub:type"] = "footnote"
    semx["href"] = "#ftn#{node['target']}"
  end
end

#footnote_label_process(node) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/isodoc/word_function/footnotes.rb', line 51

def footnote_label_process(node)
  f = node.at(ns("./fmt-fn-label"))
  sup = f.at(ns(".//sup")) and sup.replace(sup.children)
  if semx = f.at(ns(".//semx[@element = 'autonum']"))
    semx.name = "span"
    semx["class"] = "FMT-PLACEHOLDER"
  end
  f
end

#footnote_parse(node, out) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/isodoc/word_function/footnotes.rb', line 36

def footnote_parse(node, out)
  table_footnote?(node) and return table_footnote_parse(node, out)
  fn = node["reference"] # || UUIDTools::UUID.random_create.to_s
  @seen_footnote.include?(fn) and return seen_footnote_parse(node, out,
                                                             fn)
  @fn_bookmarks[fn] = bookmarkid
  f = footnote_label_process(node)
  out.span style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}",
           class: "MsoFootnoteReference" do |s|
    children_parse(f, s)
  end
  footnote_hyperlink(node, out)
  @seen_footnote << fn
end

#seen_footnote_parse(node, out, footnote) ⇒ Object



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

def seen_footnote_parse(node, out, footnote)
  f = node.at(ns("./fmt-fn-label"))
  sup = f.at(ns(".//sup")) and sup.replace(sup.children)
  s = f.at(ns(".//semx[@source = '#{node['id']}']"))
  semx = <<~SPAN.strip
    <span style="mso-element:field-begin"/> NOTEREF _Ref#{@fn_bookmarks[footnote]} \\f \\h<span style="mso-element:field-separator"/>#{footnote}<span style="mso-element:field-end"/>
  SPAN
  s.replace(semx)
  out.span class: "MsoFootnoteReference" do |fn|
    children_parse(f, fn)
  end
end