Module: IsoDoc::WordFunction::Footnotes
- Included in:
- IsoDoc::WordConvert
- Defined in:
- lib/isodoc/word_function/footnotes.rb
Instance Method Summary collapse
- #bookmarkid ⇒ Object
- #fmt_fn_body_parse(node, out) ⇒ Object
- #footnote_parse(node, out) ⇒ Object
-
#get_table_ancestor_id(node) ⇒ Object
dupe to HTML.
- #make_table_footnote_link(out, fnid, node) ⇒ Object
- #seen_footnote_parse(node, out, footnote) ⇒ Object
-
#table_footnote_parse(node, out) ⇒ Object
dupe to HTML.
-
#update_table_fn_body_ref(fnote, table, reference) ⇒ Object
TODO merge with HTML.
Instance Method Details
#bookmarkid ⇒ Object
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
21 22 23 24 25 26 27 28 |
# File 'lib/isodoc/word_function/footnotes.rb', line 21 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" out.send tag, id: "ftn#{node['reference']}" do |div| node.children.each { |n| parse(n, div) } end end |
#footnote_parse(node, out) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/isodoc/word_function/footnotes.rb', line 76 def footnote_parse(node, out) return table_footnote_parse(node, out) if (@in_table || @in_figure) && !node.ancestors.map(&:name).include?("fmt-name") fn = node["reference"] || UUIDTools::UUID.random_create.to_s return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn) @fn_bookmarks[fn] = bookmarkid 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 out.span style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}", class: "MsoFootnoteReference" do |s| children_parse(f, out) end if semx = out.parent.at(".//span[@class = 'FMT-PLACEHOLDER']") semx.name = "a" semx["class"] = "FootnoteRef" semx["epub:type"] = "footnote" semx["href"] = "#ftn#{fn}" end @seen_footnote << fn end |
#get_table_ancestor_id(node) ⇒ Object
dupe to HTML
31 32 33 34 35 36 |
# File 'lib/isodoc/word_function/footnotes.rb', line 31 def get_table_ancestor_id(node) table = node.ancestors("table") table.empty? and table = node.ancestors("figure") table.empty? and return [nil, UUIDTools::UUID.random_create.to_s] [table.last, table.last["id"]] end |
#make_table_footnote_link(out, fnid, node) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/isodoc/word_function/footnotes.rb', line 13 def make_table_footnote_link(out, fnid, node) attrs = { href: "##{fnid}", class: "TableFootnoteRef" } sup = node.at(ns("./sup")) and sup.replace(sup.children) out.a **attrs do |a| children_parse(node, a) end end |
#seen_footnote_parse(node, out, footnote) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/isodoc/word_function/footnotes.rb', line 62 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 |
#table_footnote_parse(node, out) ⇒ Object
dupe to HTML
39 40 41 42 43 44 45 46 47 |
# File 'lib/isodoc/word_function/footnotes.rb', line 39 def table_footnote_parse(node, out) fn = node["reference"] || UUIDTools::UUID.random_create.to_s table, tid = get_table_ancestor_id(node) make_table_footnote_link(out, tid + fn, node.at(ns("./fmt-fn-label"))) # do not output footnote text if we have already seen it for this table return if @seen_footnote.include?(tid + fn) update_table_fn_body_ref(node, table, tid + fn) @seen_footnote << (tid + fn) end |
#update_table_fn_body_ref(fnote, table, reference) ⇒ Object
TODO merge with HTML
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/isodoc/word_function/footnotes.rb', line 50 def update_table_fn_body_ref(fnote, table, reference) fnbody = table.at(ns(".//fmt-fn-body[@id = '#{fnote['target']}']")) or return fnbody["reference"] = reference sup = fnbody.at(ns(".//fmt-fn-label/sup")) and sup.replace(sup.children) fnbody.xpath(ns(".//fmt-fn-label")).each do |s| s["class"] = "TableFootnoteRef" s.name = "span" d = s.at(ns("./span[@class = 'fmt-caption-delim']")) and s.next = d end end |