isodoc 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +2 -12
  3. data/lib/isodoc/common.rb +2 -0
  4. data/lib/isodoc/function/blocks.rb +12 -0
  5. data/lib/isodoc/function/cleanup.rb +4 -12
  6. data/lib/isodoc/function/footnotes.rb +57 -0
  7. data/lib/isodoc/function/inline.rb +10 -6
  8. data/lib/isodoc/function/section.rb +7 -0
  9. data/lib/isodoc/function/setup.rb +64 -0
  10. data/lib/isodoc/function/table.rb +2 -0
  11. data/lib/isodoc/function/to_word_html.rb +5 -57
  12. data/lib/isodoc/function/utils.rb +4 -7
  13. data/lib/isodoc/headlesshtml_convert.rb +0 -2
  14. data/lib/isodoc/html_convert.rb +0 -2
  15. data/lib/isodoc/html_function/postprocess.rb +2 -1
  16. data/lib/isodoc/html_function/postprocess_footnotes.rb +2 -1
  17. data/lib/isodoc/pdf_convert.rb +0 -2
  18. data/lib/isodoc/presentation_function/block.rb +21 -25
  19. data/lib/isodoc/presentation_function/concepts.rb +7 -8
  20. data/lib/isodoc/presentation_function/erefs.rb +2 -3
  21. data/lib/isodoc/presentation_function/footnotes.rb +140 -0
  22. data/lib/isodoc/presentation_function/image.rb +0 -18
  23. data/lib/isodoc/presentation_function/inline.rb +11 -13
  24. data/lib/isodoc/presentation_function/refs.rb +9 -4
  25. data/lib/isodoc/presentation_function/sourcecode.rb +2 -19
  26. data/lib/isodoc/presentation_xml_convert.rb +3 -1
  27. data/lib/isodoc/version.rb +1 -1
  28. data/lib/isodoc/word_function/body.rb +5 -3
  29. data/lib/isodoc/word_function/footnotes.rb +57 -68
  30. data/lib/isodoc/word_function/postprocess.rb +6 -2
  31. data/lib/isodoc/xref/xref_gen.rb +1 -9
  32. data/lib/isodoc/xref/xref_gen_seq.rb +47 -92
  33. data/lib/isodoc/xref/xref_util.rb +49 -0
  34. metadata +19 -3
  35. data/lib/isodoc/html_function/footnotes.rb +0 -92
@@ -5,7 +5,7 @@ module IsoDoc
5
5
  def citeas(xmldoc)
6
6
  xmldoc.xpath(ns("//fmt-eref | //fmt-origin | //fmt-link"))
7
7
  .each do |e|
8
- sem_xml_descendant?(e) and next
8
+ sem_xml_descendant?(e) and next
9
9
  e["bibitemid"] && e["citeas"] or next
10
10
  a = @xrefs.anchor(e["bibitemid"], :xref, false) or next
11
11
  e["citeas"] = citeas_cleanup(a)
@@ -35,7 +35,6 @@ module IsoDoc
35
35
  ret = resolve_eref_connectives(locs)
36
36
  elem["id"] ||= "_#{UUIDTools::UUID.random_create}"
37
37
  elem.next = "<semx element='erefstack' source='#{elem['id']}'>#{ret[1]}</semx>"
38
- #elem.replace(ret[1])
39
38
  end
40
39
 
41
40
  def eref_localities(refs, target, node)
@@ -198,7 +197,7 @@ module IsoDoc
198
197
  docxml.xpath(ns("//display-text")).each { |f| f.replace(f.children) }
199
198
  docxml.xpath(ns("//fmt-eref | //fmt-origin[not(.//termref)]"))
200
199
  .each do |e|
201
- sem_xml_descendant?(e) and next
200
+ sem_xml_descendant?(e) and next
202
201
  href = eref_target(e) or next
203
202
  e.xpath(ns("./locality | ./localityStack")).each(&:remove)
204
203
  if href[:type] == :anchor then eref2xref(e)
@@ -0,0 +1,140 @@
1
+ module IsoDoc
2
+ class PresentationXMLConvert < ::IsoDoc::Convert
3
+ def footnote_collect(fnotes)
4
+ seen = {}
5
+ fnotes.each_with_object([]) do |x, m|
6
+ x["id"] ||= "_#{UUIDTools::UUID.random_create}"
7
+ seen[x["reference"]] or m << fnbody(x, seen)
8
+ x["target"] = seen[x["reference"]]
9
+ ref = x["hiddenref"] == "true" ? "" : fn_ref_label(x)
10
+ x << "<fmt-fn-label>#{ref}</fmt-fn-label>"
11
+ end
12
+ end
13
+
14
+ def footnote_container(fnotes, fnbodies)
15
+ fnbodies.empty? and return
16
+ ctr = Nokogiri::XML::Node.new("fmt-footnote-container",
17
+ fnotes.first.document)
18
+ fnbodies.each { |x| ctr << x }
19
+ ctr
20
+ end
21
+
22
+ def fnbody(fnote, seen)
23
+ body = Nokogiri::XML::Node.new("fmt-fn-body", fnote.document)
24
+ body["id"] = "_#{UUIDTools::UUID.random_create}"
25
+ body["target"] = fnote["id"]
26
+ body["reference"] = fnote["reference"]
27
+ body << semx_fmt_dup(fnote)
28
+ insert_fn_body_ref(fnote, body)
29
+ seen[fnote["reference"]] = body["id"]
30
+ body
31
+ end
32
+
33
+ def insert_fn_body_ref(fnote, body)
34
+ ins = body.at(ns(".//p")) ||
35
+ body.at(ns("./semx")).children.first.before("<p> </p>").previous
36
+ lbl = fn_body_label(fnote)
37
+ ins.children.first.previous = <<~FNOTE.strip
38
+ <fmt-fn-label>#{lbl}<span class="fmt-caption-delim"><tab/></fmt-fn-label>
39
+ FNOTE
40
+ end
41
+
42
+ def fn_ref_label(fnote)
43
+ "<sup>#{fn_label(fnote)}</sup>"
44
+ end
45
+
46
+ def fn_body_label(fnote)
47
+ "<sup>#{fn_label(fnote)}</sup>"
48
+ end
49
+
50
+ def fn_label(fnote)
51
+ <<~FNOTE.strip
52
+ <semx element="autonum" source="#{fnote['id']}">#{fnote['reference']}</semx>
53
+ FNOTE
54
+ end
55
+
56
+ def table_fn(elem)
57
+ fnotes = elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn"))
58
+ ret = footnote_collect(fnotes)
59
+ f = footnote_container(fnotes, ret) and elem << f
60
+ end
61
+
62
+ def document_footnotes(docxml)
63
+ sects = sort_footnote_sections(docxml)
64
+ excl = non_document_footnotes(docxml)
65
+ fns = filter_document_footnotes(sects, excl)
66
+ fns = renumber_document_footnotes(fns, 1)
67
+ ret = footnote_collect(fns)
68
+ f = footnote_container(fns, ret) and docxml.root << f
69
+ end
70
+
71
+ # bibdata, boilerplate, @displayorder sections
72
+ def sort_footnote_sections(docxml)
73
+ sects = docxml.xpath(".//*[@displayorder]")
74
+ .sort_by { |c| c["displayorder"].to_i }
75
+ b = docxml.at(ns("//boilerplate")) and sects.unshift b
76
+ b = docxml.at(ns("//bibdata")) and sects.unshift b
77
+ sects
78
+ end
79
+
80
+ def non_document_footnotes(docxml)
81
+ table_fns = docxml.xpath(ns("//table//fn")) -
82
+ docxml.xpath(ns("//table/name//fn"))
83
+ fig_fns = docxml.xpath(ns("//figure//fn")) -
84
+ docxml.xpath(ns("//figure/name//fn"))
85
+ table_fns + fig_fns
86
+ end
87
+
88
+ def filter_document_footnotes(sects, excl)
89
+ sects.each_with_object([]) do |s, m|
90
+ docfns = s.xpath(ns(".//fn")) - excl
91
+ m << docfns
92
+ end
93
+ end
94
+
95
+ # can instead restart at i=1 each section
96
+ def renumber_document_footnotes(fns_by_section, idx)
97
+ fns_by_section.reject(&:empty?).each_with_object({}) do |s, seen|
98
+ s.each do |f|
99
+ idx = renumber_document_footnote(f, idx, seen)
100
+ end
101
+ end
102
+ fns_by_section.flatten
103
+ end
104
+
105
+ def renumber_document_footnote(fnote, idx, seen)
106
+ fnote["original-reference"] = fnote["reference"]
107
+ if seen[fnote["reference"]]
108
+ fnote["reference"] = seen[fnote["reference"]]
109
+ else
110
+ seen[fnote["reference"]] = idx
111
+ fnote["reference"] = idx
112
+ idx += 1
113
+ end
114
+ idx
115
+ end
116
+
117
+ # move footnotes into key
118
+ def figure_fn(elem)
119
+ fn = elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn"))
120
+ fn.empty? and return
121
+ dl = figure_key_insert_pt(elem)
122
+ footnote_collect(fn).each do |f|
123
+ label, fbody = figure_fn_to_dt_dd(f)
124
+ dl.previous = "<dt><p>#{to_xml(label)}</p></dt><dd>#{to_xml(fbody)}</dd>"
125
+ end
126
+ end
127
+
128
+ def figure_fn_to_dt_dd(f)
129
+ label = f.at(ns(".//fmt-fn-label")).remove
130
+ label.at(ns(".//span[@class = 'fmt-caption-delim']"))&.remove
131
+ [label, f]
132
+ end
133
+
134
+ def figure_key_insert_pt(elem)
135
+ elem.at(ns(".//dl/name"))&.next ||
136
+ elem.at(ns(".//dl"))&.children&.first ||
137
+ elem.add_child("<dl> </dl>").first.children.first
138
+ end
139
+ end
140
+ end
@@ -73,24 +73,6 @@ module IsoDoc
73
73
  prefix_name(elem, { caption: figure_delim(elem) }, l10n(s&.strip), "name")
74
74
  end
75
75
 
76
- # move footnotes into key, and get rid of footnote reference
77
- # since it is in diagram
78
- def figure_fn(elem)
79
- fn = elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn"))
80
- fn.empty? and return
81
- dl = figure_key_insert_pt(elem)
82
- fn.each do |f|
83
- dl.previous = "<dt><p><sup>#{f['reference']}</sup></p></dt>" \
84
- "<dd>#{f.remove.children.to_xml}</dd>"
85
- end
86
- end
87
-
88
- def figure_key_insert_pt(elem)
89
- elem.at(ns("//dl/name"))&.next ||
90
- elem.at(ns("//dl"))&.children&.first ||
91
- elem.add_child("<dl> </dl>").first.children.first
92
- end
93
-
94
76
  def figure_label?(elem)
95
77
  elem.at(ns("./figure")) && !elem.at(ns("./name")) and return false
96
78
  true
@@ -39,16 +39,19 @@ module IsoDoc
39
39
  def anchor_id_postprocess(node); end
40
40
 
41
41
  def xref(docxml)
42
- #docxml.xpath(ns("//display-text")).each { |f| f.replace(f.children) }
43
42
  docxml.xpath(ns("//fmt-xref")).each { |f| xref1(f) }
44
- docxml.xpath(ns("//fmt-xref//fmt-xref")).each { |f| f.replace(f.children) }
43
+ docxml.xpath(ns("//fmt-xref//fmt-xref")).each do |f|
44
+ f.replace(f.children)
45
+ end
45
46
  docxml.xpath(ns("//fmt-xref//xref")).each { |f| f.replace(f.children) }
46
47
  end
47
48
 
48
49
  def eref(docxml)
49
50
  docxml.xpath(ns("//eref[@deleteme]")).each { |f| redundant_eref(f) }
50
51
  docxml.xpath(ns("//fmt-eref")).each { |f| xref1(f) }
51
- docxml.xpath(ns("//fmt-eref//fmt-xref")).each { |f| f.replace(f.children) }
52
+ docxml.xpath(ns("//fmt-eref//fmt-xref")).each do |f|
53
+ f.replace(f.children)
54
+ end
52
55
  docxml.xpath(ns("//erefstack")).each { |f| erefstack1(f) }
53
56
  end
54
57
 
@@ -65,19 +68,14 @@ module IsoDoc
65
68
  docxml.xpath(ns("//fmt-origin[not(.//termref)]")).each { |f| xref1(f) }
66
69
  end
67
70
 
68
- # KILL
69
- def quotesourcex(docxml)
70
- docxml.xpath(ns("//quote//source")).each { |f| xref1(f) }
71
- docxml.xpath(ns("//quote//source//xref")).each do |f|
72
- f.replace(f.children)
73
- end
74
- end
75
-
76
71
  # do not change to Presentation XML rendering
77
72
  def sem_xml_descendant?(node)
78
73
  !node.ancestors("preferred, admitted, deprecated, related, " \
79
74
  "definition, termsource").empty? and return true
80
75
  !node.ancestors("xref, eref, origin, link").empty? and return true
76
+ !node.ancestors("name, title").empty? and return true
77
+ node.ancestors("bibitem") &&
78
+ !node.ancestors("formattedref, biblio-tag") and return true
81
79
  !node.ancestors("requirement, recommendation, permission").empty? &&
82
80
  node.ancestors("fmt-provision").empty? and return true
83
81
  false
@@ -112,8 +110,8 @@ module IsoDoc
112
110
  docxml.xpath(ns("//identifier")).each do |n|
113
111
  %w(bibdata bibitem requirement recommendation permission)
114
112
  .include?(n.parent.name) and next
115
- s = semx_fmt_dup(n)
116
- n.next = "<fmt-identifier><tt>#{to_xml(s)}</tt></fmt-identifier>"
113
+ s = semx_fmt_dup(n)
114
+ n.next = "<fmt-identifier><tt>#{to_xml(s)}</tt></fmt-identifier>"
117
115
  end
118
116
  end
119
117
 
@@ -86,10 +86,15 @@ module IsoDoc
86
86
  def bibrender_formattedref(formattedref, xml); end
87
87
 
88
88
  def bibrender_relaton(xml, renderings)
89
- f = renderings[xml["id"]][:formattedref]
89
+ f = renderings[xml["id"]][:formattedref] or return
90
90
  f &&= "<formattedref>#{f}</formattedref>"
91
- x = xml.xpath(ns("./docidentifier | ./uri | ./note | ./biblio-tag"))
92
- xml.children = "#{f}#{x.to_xml}"
91
+ if x = xml.at(ns("./formattedref"))
92
+ x.replace(f)
93
+ elsif xml.children.empty?
94
+ xml << f
95
+ else
96
+ xml.children.first.previous = f
97
+ end
93
98
  end
94
99
 
95
100
  def citestyle
@@ -205,7 +210,7 @@ module IsoDoc
205
210
  ret = ident_fn(bib)
206
211
  date_note = bib.at(ns("./note[@type = 'Unpublished-Status']"))
207
212
  date_note.nil? and return ret
208
- id = UUIDTools::UUID.random_create.to_s
213
+ id = "_#{UUIDTools::UUID.random_create}"
209
214
  "#{ret}<fn reference='#{id}'><p>#{date_note.content}</p></fn>"
210
215
  end
211
216
 
@@ -42,7 +42,7 @@ module IsoDoc
42
42
  sourcehighlighter_css(docxml)
43
43
  @highlighter = sourcehighlighter
44
44
  @callouts = {}
45
- (docxml.xpath(ns("//sourcecode")) -
45
+ (docxml.xpath(ns("//sourcecode")) -
46
46
  docxml.xpath(ns("//metanorma-extension//sourcecode")))
47
47
  .each do |f|
48
48
  sourcecode1(f)
@@ -52,7 +52,6 @@ module IsoDoc
52
52
  def sourcecode1(elem)
53
53
  ret1 = semx_fmt_dup(elem)
54
54
  b = ret1.at(ns(".//body")) and b.replace(b.children)
55
- #sourcecode_annot_id(elem)
56
55
  source_label(elem)
57
56
  source_highlight(ret1, elem["linenums"] == "true", elem["lang"])
58
57
  callouts(elem)
@@ -68,25 +67,11 @@ module IsoDoc
68
67
  elem << ret
69
68
  end
70
69
 
71
- # KILL
72
- def sourcecode_annot_id(elem)
73
- elem.xpath(ns("./annotation")).each do |a|
74
- if a["original-id"]
75
- a["id"] = a["original-id"]
76
- a.delete("original-id")
77
- end
78
- a.xpath(".//*[@original-id]").each do |n|
79
- n["id"] = n["original-id"]
80
- n.delete("original-id")
81
- end
82
- end
83
- end
84
-
85
70
  def annotations(elem, fmt_elem)
86
71
  elem.at(ns("./annotation")) or return
87
72
  ret = ""
88
73
  elem.xpath(ns("./annotation")).each do |a|
89
- id = a['original-id']
74
+ id = a["original-id"]
90
75
  dd = semx_fmt_dup(a)
91
76
  dd["source"] = a["id"]
92
77
  ret += <<~OUT
@@ -183,8 +168,6 @@ module IsoDoc
183
168
  def source_label(elem)
184
169
  if !labelled_ancestor(elem) && # do not number if labelled_ancestor
185
170
  lbl = @xrefs.anchor(elem["id"], :label, false)
186
- #a = autonum(elem["id"], lbl)
187
- #s = "<span class='fmt-element-name'>#{lower2cap @i18n.figure}</span> #{a}"
188
171
  s = labelled_autonum(lower2cap(@i18n.figure), elem["id"], lbl)&.strip
189
172
  end
190
173
  prefix_name(elem, { caption: block_delim }, s, "name")
@@ -10,6 +10,7 @@ require_relative "presentation_function/section"
10
10
  require_relative "presentation_function/index"
11
11
  require_relative "presentation_function/bibdata"
12
12
  require_relative "presentation_function/metadata"
13
+ require_relative "presentation_function/footnotes"
13
14
 
14
15
  module IsoDoc
15
16
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -85,7 +86,8 @@ module IsoDoc
85
86
  floattitle docxml # feeds rearrange_clauses
86
87
  index docxml # fed by strip_duplicate_ids
87
88
  toc docxml
88
- display_order docxml
89
+ display_order docxml # feeds document_footnotes
90
+ document_footnotes docxml
89
91
  end
90
92
 
91
93
  def block(docxml)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "3.1.1".freeze
2
+ VERSION = "3.1.2".freeze
3
3
  end
@@ -51,7 +51,7 @@ module IsoDoc
51
51
  def make_body3(body, docxml)
52
52
  body.div class: "WordSection3" do |div3|
53
53
  content(div3, docxml, ns(self.class::MAIN_ELEMENTS))
54
- footnotes div3
54
+ footnotes docxml, div3
55
55
  comments div3
56
56
  end
57
57
  end
@@ -79,7 +79,8 @@ module IsoDoc
79
79
  node.xpath(ns("./note")).each { |n| parse(n, out) }
80
80
  end
81
81
 
82
- def figure_get_or_make_dl(node)
82
+ # KILL
83
+ def figure_get_or_make_dlx(node)
83
84
  dl = node.at(".//table[@class = 'dl']")
84
85
  if dl.nil?
85
86
  node.add_child("<p><b>#{@i18n.key}</b></p><table class='dl'></table>")
@@ -89,7 +90,8 @@ module IsoDoc
89
90
  end
90
91
 
91
92
  # get rid of footnote link, it is in diagram
92
- def figure_aside_process(fig, aside, key)
93
+ # KILL
94
+ def figure_aside_processx(fig, aside, key)
93
95
  fig.at("./a[@class='TableFootnoteRef']")&.remove
94
96
  fnref = fig.at(".//span[@class='TableFootnoteRef']/..")
95
97
  tr = key.add_child("<tr></tr>").first
@@ -10,75 +10,67 @@ module IsoDoc
10
10
  sprintf "%09d", ret
11
11
  end
12
12
 
13
- def footnotes(div)
14
- return if @footnotes.empty?
15
-
16
- @footnotes.each { |fn| div.parent << fn }
17
- end
18
-
19
- def make_table_footnote_link(out, fnid, fnref)
13
+ def make_table_footnote_link(out, fnid, node)
20
14
  attrs = { href: "##{fnid}", class: "TableFootnoteRef" }
15
+ sup = node.at(ns("./sup")) and sup.replace(sup.children)
21
16
  out.a **attrs do |a|
22
- a << fnref
17
+ children_parse(node, a)
23
18
  end
24
19
  end
25
20
 
26
- def make_table_footnote_target(out, fnid, fnref)
27
- attrs = { id: fnid, class: "TableFootnoteRef" }
28
- out.span do |s|
29
- out.span **attrs do |a|
30
- a << fnref
31
- end
32
- insert_tab(s, 1)
21
+ def fmt_fn_body_parse(node, out)
22
+ node.at(ns(".//fmt-fn-label"))&.remove
23
+ aside = node.parent.name == "fmt-footnote-container"
24
+ tag = aside ? "aside" : "div"
25
+ out.send tag, id: "ftn#{node['reference']}" do |div|
26
+ node.children.each { |n| parse(n, div) }
33
27
  end
34
28
  end
35
29
 
36
- def make_table_footnote_text(node, fnid, fnref)
37
- attrs = { id: "ftn#{fnid}" }
38
- noko do |xml|
39
- xml.div **attr_code(attrs) do |div|
40
- make_table_footnote_target(div, fnid, fnref)
41
- node.children.each { |n| parse(n, div) }
42
- end
43
- end.join("\n")
44
- end
45
-
46
- def make_generic_footnote_text(node, fnid)
47
- noko do |xml|
48
- xml.aside id: "ftn#{fnid}" do |div|
49
- node.children.each { |n| parse(n, div) }
50
- end
51
- end.join("\n")
52
- end
53
-
54
- def get_table_ancestor_id(node)
55
- table = node.ancestors("table") || node.ancestors("figure")
56
- return UUIDTools::UUID.random_create.to_s if table.empty?
57
-
58
- table.last["id"]
30
+ # dupe to HTML
31
+ def get_table_ancestor_id(node)
32
+ table = node.ancestors("table")
33
+ table.empty? and table = node.ancestors("figure")
34
+ table.empty? and return [nil, UUIDTools::UUID.random_create.to_s]
35
+ [table.last, table.last["id"]]
59
36
  end
60
37
 
38
+ # dupe to HTML
61
39
  def table_footnote_parse(node, out)
62
40
  fn = node["reference"] || UUIDTools::UUID.random_create.to_s
63
- tid = get_table_ancestor_id(node)
64
- make_table_footnote_link(out, tid + fn, fn)
41
+ table, tid = get_table_ancestor_id(node)
42
+ make_table_footnote_link(out, tid + fn, node.at(ns("./fmt-fn-label")))
65
43
  # do not output footnote text if we have already seen it for this table
66
44
  return if @seen_footnote.include?(tid + fn)
67
-
68
- @in_footnote = true
69
- out.aside { |a| a << make_table_footnote_text(node, tid + fn, fn) }
70
- @in_footnote = false
45
+ update_table_fn_body_ref(node, table, tid + fn)
71
46
  @seen_footnote << (tid + fn)
72
47
  end
73
48
 
74
- def seen_footnote_parse(_node, out, footnote)
75
- out.span style: "mso-element:field-begin"
76
- out << " NOTEREF _Ref#{@fn_bookmarks[footnote]} \\f \\h"
77
- out.span style: "mso-element:field-separator"
78
- out.span class: "MsoFootnoteReference" do |s|
79
- s << footnote
49
+ # TODO merge with HTML
50
+ def update_table_fn_body_ref(fnote, table, reference)
51
+ fnbody = table.at(ns(".//fmt-fn-body[@id = '#{fnote['target']}']")) or return
52
+ fnbody["reference"] = reference
53
+ sup = fnbody.at(ns(".//fmt-fn-label/sup")) and sup.replace(sup.children)
54
+ fnbody.xpath(ns(".//fmt-fn-label")).each do |s|
55
+ s["class"] = "TableFootnoteRef"
56
+ s.name = "span"
57
+ d = s.at(ns("./span[@class = 'fmt-caption-delim']")) and
58
+ s.next = d
59
+ end
60
+ end
61
+
62
+ def seen_footnote_parse(node, out, footnote)
63
+ f = node.at(ns("./fmt-fn-label"))
64
+ sup = f.at(ns(".//sup")) and sup.replace(sup.children)
65
+ s = f.at(ns(".//semx[@source = '#{node['id']}']"))
66
+
67
+ semx = <<~SPAN.strip
68
+ <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"/>
69
+ SPAN
70
+ s.replace(semx)
71
+ out.span class: "MsoFootnoteReference" do |fn|
72
+ children_parse(f, fn)
80
73
  end
81
- out.span style: "mso-element:field-end"
82
74
  end
83
75
 
84
76
  def footnote_parse(node, out)
@@ -89,26 +81,23 @@ module IsoDoc
89
81
  return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn)
90
82
 
91
83
  @fn_bookmarks[fn] = bookmarkid
92
- out.span style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}" do |s|
93
- s.a class: "FootnoteRef", "epub:type": "footnote",
94
- href: "#ftn#{fn}" do |a|
95
- a.sup { |sup| sup << fn }
96
- end
84
+ f = node.at(ns("./fmt-fn-label"))
85
+ sup = f.at(ns(".//sup")) and sup.replace(sup.children)
86
+ if semx = f.at(ns(".//semx[@element = 'autonum']"))
87
+ semx.name = "span"
88
+ semx["class"] = "FMT-PLACEHOLDER"
89
+ end
90
+ out.span style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}", class: "MsoFootnoteReference" do |s|
91
+ children_parse(f, out)
92
+ end
93
+ if semx = out.parent.at(".//span[@class = 'FMT-PLACEHOLDER']")
94
+ semx.name = "a"
95
+ semx["class"] = "FootnoteRef"
96
+ semx["epub:type"] = "footnote"
97
+ semx["href"] = "#ftn#{fn}"
97
98
  end
98
- @in_footnote = true
99
- @footnotes << make_generic_footnote_text(node, fn)
100
- @in_footnote = false
101
99
  @seen_footnote << fn
102
100
  end
103
-
104
- def make_footnote(node, footnote)
105
- return if @seen_footnote.include?(footnote)
106
-
107
- @in_footnote = true
108
- @footnotes << make_generic_footnote_text(node, footnote)
109
- @in_footnote = false
110
- @seen_footnote << footnote
111
- end
112
101
  end
113
102
  end
114
103
  end
@@ -63,7 +63,7 @@ module IsoDoc
63
63
  word_section_breaks(docxml)
64
64
  word_tab_clean(docxml)
65
65
  authority_cleanup(docxml)
66
- word_footnote_format(docxml)
66
+ #word_footnote_format(docxml)
67
67
  word_remove_empty_toc(docxml)
68
68
  word_remove_empty_sections(docxml)
69
69
  docxml
@@ -172,12 +172,16 @@ module IsoDoc
172
172
  end
173
173
  end
174
174
 
175
- def word_footnote_format(docxml)
175
+ # KILL
176
+ def word_footnote_formatx(docxml)
176
177
  # the content is in a[@epub:type = 'footnote']//sup, but in Word,
177
178
  # we need to inject content around the autonumbered footnote reference
178
179
  docxml.xpath("//a[@epub:type = 'footnote']").each do |x|
179
180
  footnote_reference_format(x)
180
181
  end
182
+ docxml.xpath("//span[@class = 'MsoFootnoteReference']").each do |x|
183
+ footnote_reference_format(x)
184
+ end
181
185
  docxml.xpath("//a[@class = 'TableFootnoteRef'] | " \
182
186
  "//span[@class = 'TableFootnoteRef']").each do |x|
183
187
  table_footnote_reference_format(x)
@@ -36,12 +36,6 @@ module IsoDoc
36
36
  end
37
37
  end
38
38
 
39
- def increment_label(elems, node, counter, increment: true)
40
- elems.size == 1 && !node["number"] and return ""
41
- counter.increment(node) if increment
42
- counter.print
43
- end
44
-
45
39
  def termnote_anchor_names(docxml)
46
40
  docxml.xpath(ns("//*[termnote]")).each do |t|
47
41
  c = Counter.new
@@ -240,8 +234,7 @@ refer_list)
240
234
  def bookmark_container(parent)
241
235
  if parent
242
236
  clause = parent.xpath(CLAUSE_ANCESTOR)&.last
243
- if clause["id"] == id
244
- nil
237
+ if clause["id"] == id then nil
245
238
  else
246
239
  @anchors.dig(clause["id"], :xref)
247
240
  end
@@ -251,7 +244,6 @@ refer_list)
251
244
  def bookmark_anchor_names(xml)
252
245
  xml.xpath(ns(".//bookmark")).noblank.each do |n|
253
246
  _parent, id = id_ancestor(n)
254
- # container = bookmark_container(parent)
255
247
  @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
256
248
  xref: @anchors.dig(id, :xref) || "???",
257
249
  container: @anchors.dig(id, :container) }