metanorma-standoc 3.0.7 → 3.0.9

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isodoc/html/htmlstyle.css +0 -2
  3. data/lib/metanorma/standoc/anchor.rb +1 -1
  4. data/lib/metanorma/standoc/base.rb +1 -1
  5. data/lib/metanorma/standoc/basicdoc.rng +9 -5
  6. data/lib/metanorma/standoc/blocks.rb +8 -5
  7. data/lib/metanorma/standoc/blocks_image.rb +2 -6
  8. data/lib/metanorma/standoc/blocks_notes.rb +2 -6
  9. data/lib/metanorma/standoc/cleanup.rb +5 -1
  10. data/lib/metanorma/standoc/cleanup_amend.rb +6 -8
  11. data/lib/metanorma/standoc/cleanup_asciibib.rb +17 -13
  12. data/lib/metanorma/standoc/cleanup_bibdata.rb +19 -13
  13. data/lib/metanorma/standoc/cleanup_bibitem.rb +9 -6
  14. data/lib/metanorma/standoc/cleanup_block.rb +6 -6
  15. data/lib/metanorma/standoc/cleanup_boilerplate.rb +5 -4
  16. data/lib/metanorma/standoc/cleanup_footnotes.rb +2 -4
  17. data/lib/metanorma/standoc/cleanup_image.rb +3 -3
  18. data/lib/metanorma/standoc/cleanup_inline.rb +22 -47
  19. data/lib/metanorma/standoc/cleanup_review.rb +7 -5
  20. data/lib/metanorma/standoc/cleanup_section.rb +30 -5
  21. data/lib/metanorma/standoc/cleanup_table.rb +1 -2
  22. data/lib/metanorma/standoc/cleanup_terms.rb +1 -1
  23. data/lib/metanorma/standoc/cleanup_terms_designations.rb +1 -1
  24. data/lib/metanorma/standoc/cleanup_text.rb +5 -3
  25. data/lib/metanorma/standoc/cleanup_toc.rb +1 -1
  26. data/lib/metanorma/standoc/cleanup_xref.rb +1 -1
  27. data/lib/metanorma/standoc/converter.rb +15 -7
  28. data/lib/metanorma/standoc/init.rb +15 -7
  29. data/lib/metanorma/standoc/inline.rb +12 -7
  30. data/lib/metanorma/standoc/isodoc.rng +145 -5
  31. data/lib/metanorma/standoc/localbib.rb +1 -2
  32. data/lib/metanorma/standoc/macros.rb +0 -1
  33. data/lib/metanorma/standoc/macros_form.rb +21 -3
  34. data/lib/metanorma/standoc/macros_inline.rb +24 -1
  35. data/lib/metanorma/standoc/macros_link.rb +13 -5
  36. data/lib/metanorma/standoc/macros_plantuml.rb +28 -14
  37. data/lib/metanorma/standoc/ref.rb +2 -2
  38. data/lib/metanorma/standoc/ref_sect.rb +1 -1
  39. data/lib/metanorma/standoc/ref_utility.rb +4 -3
  40. data/lib/metanorma/standoc/section.rb +9 -10
  41. data/lib/metanorma/standoc/sectiontype.rb +28 -20
  42. data/lib/metanorma/standoc/table.rb +9 -13
  43. data/lib/metanorma/standoc/term_lookup_cleanup.rb +17 -9
  44. data/lib/metanorma/standoc/terms.rb +1 -1
  45. data/lib/metanorma/standoc/utils.rb +4 -0
  46. data/lib/metanorma/standoc/validate.rb +50 -23
  47. data/lib/metanorma/standoc/validate_schema.rb +2 -0
  48. data/lib/metanorma/standoc/validate_term.rb +8 -7
  49. data/lib/metanorma/standoc/version.rb +1 -1
  50. data/metanorma-standoc.gemspec +2 -3
  51. metadata +6 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab57258611b63bcabb64f17d1fe44bf74d8169ffd707ce96db6fa4f074a0f007
4
- data.tar.gz: 3c39749483d8687dbcaea874d3d1e37a90b61e54d45fba10346025eef2378a7a
3
+ metadata.gz: 4234211796c2c39d12d6bf987d799c6cc5c65745105540ca7e2078794ed38511
4
+ data.tar.gz: 3785018f24e1689ff70f7ad53dd4a82ec86e845815f939edecf08562aa57d7c4
5
5
  SHA512:
6
- metadata.gz: c0cff4afac83b0a64838f23be4895f3dc6b5f02d986fd6d08706cb2dd8fc03ef2f5a446bb06e81c3a5a3d30a1a086a3e703af6d074f8dc14f0a93d524407334a
7
- data.tar.gz: 37ebfa958164eca83ddd835efbb50da1d36b7fcba0dc0c350abbf0da3833a132bfc9680c036367ff288c9163230e5c0a7852cded007c9ac50d73fe2117b3bade
6
+ metadata.gz: 7655c4607ed54692a82c533a29345f9f89f5ba6b506b3137d225e27ae47717d303abd17ddae1488b627b4b5a998e486f5b11db9c64fee6871f5f5aee2139feea
7
+ data.tar.gz: 5730669dbca0c7bf59204fb88464e382b67c0c2e4a7a6cbce6acb8b5e84c84d83112beebc7f8f2e2df6824ca41d9dda042fb621345d2b86cbc909d89d8601fcf
@@ -320,8 +320,6 @@ h6:hover > a.anchor,
320
320
 
321
321
  svg {
322
322
  width: 100%;
323
- padding-bottom: 92%;
324
- height: 1px;
325
323
  overflow: visible;
326
324
  }
327
325
 
@@ -14,7 +14,7 @@ module Metanorma
14
14
 
15
15
  def inline_anchor_ref(node)
16
16
  noko do |xml|
17
- xml.bookmark nil, **attr_code(id: node.id)
17
+ xml.bookmark nil, **attr_code(id_attr(node))
18
18
  end
19
19
  end
20
20
 
@@ -59,7 +59,7 @@ module Metanorma
59
59
  thead|tbody|tfoot|th|td|form|requirement|recommendation|permission|
60
60
  imagemap|svgmap|preferred|admitted|related|domain|deprecates|
61
61
  letter-symbol|graphical-symbol|expression|subject|abbreviation-type|
62
- pronunciation|grammar|term|terms|termnote|termexample|termsource|
62
+ pronunciation|grammar|term|terms|termnote|termexample|source|
63
63
  origin|termref|modification)>)}x, "\\1\n")
64
64
  .gsub(%r{(<(title|name))}, "\n\\1")
65
65
  .gsub(%r{(<sourcecode[^<>]*>)\s+(<name[^<>]*>[^<]+</name>)\s+},
@@ -267,6 +267,10 @@ in a document (e.g. sourcecode annotations)</a:documentation>
267
267
  <value>justified</value>
268
268
  </choice>
269
269
  </define>
270
+ <define name="IdRefType">
271
+ <a:documentation>Type of cross-references to elements. In BasicDoc, these always point to id { xsd:ID } </a:documentation>
272
+ <data type="IDREF"/>
273
+ </define>
270
274
  <define name="RequiredId">
271
275
  <a:documentation>Mandatory anchor of element, to be used for cross-references within the document</a:documentation>
272
276
  <attribute name="id">
@@ -409,13 +413,13 @@ in a document (e.g. sourcecode annotations)</a:documentation>
409
413
  <attribute name="from">
410
414
  <a:documentation>Identifier for the start of the text or point in the text to which the comment applies.
411
415
  If not provided, the comment applies in the vicinity of the place it has been inserted into the text</a:documentation>
412
- <data type="IDREF"/>
416
+ <ref name="IdRefType"/>
413
417
  </attribute>
414
418
  </optional>
415
419
  <optional>
416
420
  <attribute name="to">
417
421
  <a:documentation>Identifier for the end of the text to which the comment applies</a:documentation>
418
- <data type="IDREF"/>
422
+ <ref name="IdRefType"/>
419
423
  </attribute>
420
424
  </optional>
421
425
  </define>
@@ -1504,7 +1508,7 @@ Restricted recursively to contain only other such inline elements with no identi
1504
1508
  <attribute name="to">
1505
1509
  <a:documentation>A reference to an anchor element (typically a bookmark),
1506
1510
  to indicate that the index range covers a range of locations between the current index element and the `to` anchor</a:documentation>
1507
- <data type="IDREF"/>
1511
+ <ref name="IdRefType"/>
1508
1512
  </attribute>
1509
1513
  </optional>
1510
1514
  <ref name="index-primary">
@@ -1662,7 +1666,7 @@ which can be bookmarks as well as block or section references</a:documentation>
1662
1666
  <define name="XrefAttributes">
1663
1667
  <attribute name="target">
1664
1668
  <a:documentation>The identifier of a section, block or inlined element being referenced</a:documentation>
1665
- <data type="IDREF"/>
1669
+ <ref name="IdRefType"/>
1666
1670
  </attribute>
1667
1671
  <optional>
1668
1672
  <attribute name="type">
@@ -1723,7 +1727,7 @@ The target of a footnote is the location it is embedded in within the text</a:do
1723
1727
  <attribute name="target">
1724
1728
  <a:documentation>The target of the callout is understood to be the location of the callout within the source code;
1725
1729
  the extent of the target is not expressed overtly</a:documentation>
1726
- <data type="IDREF"/>
1730
+ <ref name="IdRefType"/>
1727
1731
  </attribute>
1728
1732
  <text>
1729
1733
  <a:documentation>The label of the callout, used to identify its target within the source code</a:documentation>
@@ -6,10 +6,13 @@ module Metanorma
6
6
  module Standoc
7
7
  module Blocks
8
8
  def id_attr(node = nil)
9
- { id: Metanorma::Utils::anchor_or_uuid(node),
9
+ anchor = node&.id
10
+ { id: "_#{UUIDTools::UUID.random_create}",
11
+ anchor: anchor && !anchor.empty? ? anchor : nil,
10
12
  tag: node&.attr("tag"),
11
13
  columns: node&.attr("columns"),
12
14
  "multilingual-rendering": node&.attr("multilingual-rendering") }
15
+ .compact
13
16
  end
14
17
 
15
18
  def id_unnum_attrs(node)
@@ -66,9 +69,9 @@ module Metanorma
66
69
  noko do |xml|
67
70
  xml.figure **literal_attrs(node) do |f|
68
71
  figure_title(node, f)
69
- f.pre node.lines.join("\n"),
70
- **attr_code(id: Metanorma::Utils::anchor_or_uuid,
71
- alt: node.attr("alt"))
72
+ pre_attrs = id_attr(node).tap { |h| h.delete(:anchor) }
73
+ .merge(alt: node.attr("alt"))
74
+ f.pre node.lines.join("\n"), **attr_code(pre_attrs)
72
75
  end
73
76
  end
74
77
  end
@@ -229,7 +232,7 @@ module Metanorma
229
232
 
230
233
  # need to validate Metanorma XML before it passes to textcleanup,
231
234
  # where passthrough wrapper and escaped tags are removed:
232
- # <passthrough format="metanorma>&lt;tag&gt</passthrough> => <tag>
235
+ # <passthrough formats="metanorma>&lt;tag&gt</passthrough> => <tag>
233
236
  # Do not treat not well-formed XML as invalid,
234
237
  # as it may be fragment, e.g. unterminated start of element markup
235
238
  def passthrough_validate(node, content, encoded_content)
@@ -2,11 +2,7 @@ module Metanorma
2
2
  module Standoc
3
3
  module Blocks
4
4
  def svgmap_attrs(node)
5
- attr_code(id_attr(node)
6
- .merge(id: node.id, number: node.attr("number"),
7
- unnumbered: node.option?("unnumbered") ? "true" : nil,
8
- subsequence: node.attr("subsequence"))
9
- .merge(keep_attrs(node)))
5
+ attr_code(id_unnum_attrs(node).merge(keep_attrs(node)))
10
6
  end
11
7
 
12
8
  def svgmap_example(node)
@@ -44,7 +40,7 @@ module Metanorma
44
40
  noko do |xml|
45
41
  xml.figure **figure_attrs(node) do |f|
46
42
  figure_title(node, f)
47
- f.image **image_attributes(node)
43
+ f.image **(image_attributes(node).tap { |h| h.delete(:anchor) })
48
44
  end
49
45
  end
50
46
  end
@@ -2,11 +2,8 @@ module Metanorma
2
2
  module Standoc
3
3
  module Blocks
4
4
  def termnote_attrs(node)
5
- attr_code(id_attr(node).merge(keep_attrs(node)
5
+ attr_code(id_unnum_attrs(node).merge(keep_attrs(node)
6
6
  .merge(
7
- unnumbered: node.attr("unnumbered"),
8
- number: node.attr("number"),
9
- subsequence: node.attr("subsequence"),
10
7
  "keep-separate": node.attr("keep-separate"),
11
8
  keepasterm: node.option?("termnote") ? "true" : nil,
12
9
  )))
@@ -61,8 +58,7 @@ module Metanorma
61
58
  end
62
59
 
63
60
  def note(node)
64
- return termnote(node) if node.option?("termnote")
65
-
61
+ node.option?("termnote") and return termnote(node)
66
62
  noko do |xml|
67
63
  xml.note **note_attrs(node) do |c|
68
64
  wrap_in_para(node, c)
@@ -29,10 +29,12 @@ module Metanorma
29
29
  def cleanup(xmldoc)
30
30
  @doctype = xmldoc.at("//bibdata/ext/doctype")&.text
31
31
  element_name_cleanup(xmldoc)
32
- passthrough_cleanup(xmldoc)
32
+ source_include_cleanup(xmldoc) # feeds: misccontainer_cleanup
33
+ passthrough_cleanup(xmldoc) # feeds: smartquotes_cleanup
33
34
  unnumbered_blocks_cleanup(xmldoc)
34
35
  termdocsource_cleanup(xmldoc) # feeds: metadata_cleanup
35
36
  metadata_cleanup(xmldoc) # feeds: boilerplate_cleanup
37
+ misccontainer_cleanup(xmldoc)
36
38
  sections_cleanup(xmldoc) # feeds: obligations_cleanup, toc_cleanup,
37
39
  # floatingtitle_cleanup
38
40
  obligations_cleanup(xmldoc)
@@ -89,10 +91,12 @@ module Metanorma
89
91
  linebreak_cleanup(xmldoc)
90
92
  variant_cleanup(xmldoc)
91
93
  para_cleanup(xmldoc)
94
+ source_id_cleanup(xmldoc)
92
95
  empty_element_cleanup(xmldoc)
93
96
  img_cleanup(xmldoc)
94
97
  anchor_cleanup(xmldoc)
95
98
  link_cleanup(xmldoc)
99
+ passthrough_metanorma_cleanup(xmldoc)
96
100
  xmldoc
97
101
  end
98
102
 
@@ -8,8 +8,8 @@ module Metanorma
8
8
  end
9
9
 
10
10
  def create_amend(clause)
11
- a = clause.add_child("<amend id='_#{UUIDTools::UUID.random_create}'/>")
12
- .first
11
+ a = clause.add_child("<amend/>").first
12
+ add_id(a)
13
13
  clause.elements.each do |e|
14
14
  e.parent = a unless %w(amend title).include? e.name
15
15
  end
@@ -32,8 +32,8 @@ module Metanorma
32
32
  amend.children = "<description>#{amend.children.to_xml}</description>"
33
33
  return
34
34
  end
35
- pre = q.xpath("./preceding-sibling::*")&.remove
36
- post = q.xpath("./following-sibling::*")&.remove
35
+ pre = q.xpath("./preceding-sibling::*").each(&:remove)
36
+ post = q.xpath("./following-sibling::*").each(&:remove)
37
37
  pre.empty? or amend << "<description>#{pre.to_xml}</description>"
38
38
  amend << q.remove
39
39
  post.empty? or amend << "<description>#{post.to_xml}</description>"
@@ -41,13 +41,11 @@ module Metanorma
41
41
 
42
42
  def move_attrs_to_amend(clause, amend)
43
43
  %w(change path path_end title).each do |e|
44
- next unless clause[e]
45
-
44
+ clause[e] or next
46
45
  amend[e] = clause[e]
47
46
  clause.delete(e)
48
47
  end
49
- return unless amend["locality"]
50
-
48
+ amend["locality"] or return
51
49
  loc = amend.children.add_previous_sibling("<location/>")
52
50
  extract_localities1(loc, amend["locality"])
53
51
  loc1 = loc.at("./localityStack") and loc.replace(loc1.elements)
@@ -1,4 +1,3 @@
1
- require "set"
2
1
  require "relaton_bib"
3
2
 
4
3
  module Metanorma
@@ -8,17 +7,24 @@ module Metanorma
8
7
  xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
9
8
  bib = dl_bib_extract(c) or next
10
9
  validate_ref_dl(bib, c)
11
- bibitemxml = RelatonBib::BibliographicItem.from_hash(bib).to_xml or next
12
- bibitem = Nokogiri::XML(bibitemxml)
13
- bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
10
+ xml = RelatonBib::BibliographicItem.from_hash(bib).to_xml or next
11
+ bibitem = Nokogiri::XML(xml)
12
+ ref_dl_cleanup_id(bibitem.root, c)
14
13
  c.replace(bibitem.root)
15
14
  end
16
15
  end
17
16
 
17
+ def ref_dl_cleanup_id(bibitem, clause)
18
+ bibitem["anchor"] = bibitem["id"]
19
+ clause["anchor"] && !/^_/.match(clause["anchor"]) and
20
+ bibitem["anchor"] = clause["anchor"]
21
+ add_id(bibitem)
22
+ end
23
+
18
24
  # do not accept implicit id
19
25
  def validate_ref_dl(bib, clause)
20
26
  id = bib["id"]
21
- id ||= clause["id"] unless /^_/.match?(clause["id"])
27
+ id ||= clause["anchor"] unless /^_/.match?(clause["anchor"])
22
28
  unless id
23
29
  @log.add("Anchors", clause,
24
30
  "The following reference is missing an anchor:\n" \
@@ -57,8 +63,7 @@ module Metanorma
57
63
  end
58
64
 
59
65
  def dd_bib_extract(dtd)
60
- return nil if dtd.children.empty?
61
-
66
+ dtd.children.empty? and return nil
62
67
  dtd.at("./dl") and return dl_bib_extract(dtd)
63
68
  elems = dtd.remove.elements
64
69
  return p_unwrap(dtd) unless elems.size == 1 &&
@@ -74,7 +79,7 @@ module Metanorma
74
79
  end
75
80
 
76
81
  # definition list, with at most one level of unordered lists
77
- def dl_bib_extract(clause, nested = false)
82
+ def dl_bib_extract(clause, nested: false)
78
83
  dl = clause.at("./dl") or return
79
84
  key = ""
80
85
  bib = dl.xpath("./dt | ./dd").each_with_object({}) do |dtd, m|
@@ -82,10 +87,9 @@ module Metanorma
82
87
  add_to_hash(m, key, dd_bib_extract(dtd))
83
88
  end
84
89
  clause.xpath("./clause").each do |c1|
85
- key = c1&.at("./title")&.text&.downcase&.strip
86
- next unless %w(contributor relation series).include? key
87
-
88
- add_to_hash(bib, key, dl_bib_extract(c1, true))
90
+ key = c1.at("./title")&.text&.downcase&.strip
91
+ %w(contributor relation series).include?(key) or next
92
+ add_to_hash(bib, key, dl_bib_extract(c1, nested: true))
89
93
  end
90
94
  dl_bib_extract_title(bib, clause, nested)
91
95
  end
@@ -96,7 +100,7 @@ module Metanorma
96
100
  bib["title"] = [bib["title"]] if bib["title"].is_a?(Hash) ||
97
101
  bib["title"].is_a?(String)
98
102
  bib["title"] ||= []
99
- bib["title"] << title if !title.empty?
103
+ title.empty? or bib["title"] << title
100
104
  bib
101
105
  end
102
106
  end
@@ -25,6 +25,7 @@ module Metanorma
25
25
  def bibdata_anchor_cleanup(xmldoc)
26
26
  xmldoc.xpath("//bibdata//bibitem | //bibdata//note").each do |b|
27
27
  b.delete("id")
28
+ b.delete("anchor")
28
29
  end
29
30
  end
30
31
 
@@ -51,7 +52,7 @@ module Metanorma
51
52
  i = i.add_child("<references hidden='true' normative='false'/>").first
52
53
  refs.each do |x|
53
54
  i << <<~BIB
54
- <bibitem id="#{x}" type="internal">
55
+ <bibitem anchor="#{x}" id="_#{UUIDTools::UUID.random_create}" type="internal">
55
56
  <docidentifier type="repository">#{x.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
56
57
  </bibitem>
57
58
  BIB
@@ -67,27 +68,19 @@ module Metanorma
67
68
  eref.delete("citeas")
68
69
  eref["target"] = loc
69
70
  if id_map
70
- return if id_map.has_key?(loc)
71
+ id_map.has_key?(loc) and return
71
72
  else
72
- eref.document.at("//*[@id = '#{loc}']") and return
73
+ eref.document.at("//*[@anchor = '#{loc}']") and return
73
74
  end
74
75
  eref.children = %(** Missing target #{loc})
75
76
  eref["target"] = ident
76
77
  end
77
78
 
78
79
  def resolve_local_indirect_erefs(xmldoc, refs, prefix)
79
- # Pre-index elements by ID
80
- id_map = xmldoc.xpath("//*[@id]").each_with_object({}) do |node, map|
81
- map[node["id"]] = node
82
- end
83
-
84
- # Pre-index all <eref> elements by bibitemid
85
- eref_map = xmldoc.xpath("//eref[@bibitemid]").group_by { |e| e["bibitemid"] }
86
-
80
+ id_map, eref_map = resolve_local_indirect_erefs_prep(xmldoc)
87
81
  refs.each_with_object([]) do |r, m|
88
82
  id = r.sub(/^#{prefix}_/, "")
89
- n = id_map[id]
90
- if n&.at("./ancestor-or-self::*[@type = '#{prefix}']")
83
+ if id_map[id]&.at("./ancestor-or-self::*[@type = '#{prefix}']")
91
84
  eref_map[r]&.each do |e|
92
85
  indirect_eref_to_xref(e, id, id_map)
93
86
  end
@@ -96,6 +89,19 @@ module Metanorma
96
89
  end
97
90
  end
98
91
 
92
+ def resolve_local_indirect_erefs_prep(xmldoc)
93
+ # Pre-index elements by anchor
94
+ # (which is what bibitemid currently points to)
95
+ id_map = xmldoc.xpath("//*[@anchor]")
96
+ .each_with_object({}) do |node, map|
97
+ map[node["anchor"]] = node
98
+ end
99
+ # Pre-index all <eref> elements by bibitemid
100
+ eref_map = xmldoc.xpath("//eref[@bibitemid]")
101
+ .group_by { |e| e["bibitemid"] }
102
+ [id_map, eref_map]
103
+ end
104
+
99
105
  def biblio_indirect_erefs(xmldoc, prefixes)
100
106
  prefixes&.each do |prefix|
101
107
  refs = gather_indirect_erefs(xmldoc, prefix)
@@ -64,11 +64,11 @@ module Metanorma
64
64
 
65
65
  def reference_names(xmldoc)
66
66
  xmldoc.xpath("//bibitem[not(ancestor::bibitem)]").each do |ref|
67
- @anchors[ref["id"]] =
67
+ @anchors[ref["anchor"]] =
68
68
  if docid = select_docid(ref)
69
69
  reference = format_ref(docid.children.to_xml, docid["type"])
70
70
  { xref: reference, id: idtype2cit(ref) }
71
- else { xref: ref["id"], id: { "" => ref["id"] } }
71
+ else { xref: ref["anchor"], id: { "" => ref["anchor"] } }
72
72
  end
73
73
  end
74
74
  end
@@ -123,6 +123,7 @@ module Metanorma
123
123
  uri = b&.at("./uri[@type = 'citation']")&.text
124
124
  bibitem = read_local_bibitem(uri) or next
125
125
  bibitem["id"] = b["id"]
126
+ bibitem["anchor"] = b["anchor"]
126
127
  b.replace(bibitem)
127
128
  end
128
129
  end
@@ -130,9 +131,11 @@ module Metanorma
130
131
  def bibitem_nested_id(xmldoc)
131
132
  xmldoc.xpath("//bibitem//bibitem").each do |b|
132
133
  b.delete("id")
134
+ b.delete("anchor")
133
135
  end
134
136
  xmldoc.xpath("//bibdata//bibitem").each do |b|
135
137
  b.delete("id")
138
+ b.delete("anchor")
136
139
  end
137
140
  end
138
141
 
@@ -211,11 +214,11 @@ module Metanorma
211
214
  end
212
215
 
213
216
  def bibitem_id_docid_hash(xmldoc)
214
- xmldoc.xpath("//bibitem[@id]").each_with_object({}) do |b, m|
215
- m[b["id"]] ||= {}
217
+ xmldoc.xpath("//bibitem[@anchor]").each_with_object({}) do |b, m|
218
+ m[b["anchor"]] ||= {}
216
219
  docid = b.at("./docidentifier")&.text || "NO ID"
217
- m[b["id"]][docid] ||= []
218
- m[b["id"]][docid] << b
220
+ m[b["anchor"]][docid] ||= []
221
+ m[b["anchor"]][docid] << b
219
222
  end
220
223
  end
221
224
 
@@ -17,7 +17,7 @@ module Metanorma
17
17
 
18
18
  def inject_id(xmldoc, path)
19
19
  xmldoc.xpath(path).each do |x|
20
- x["id"] ||= Metanorma::Utils::anchor_or_uuid
20
+ x["id"] or add_id(x)
21
21
  end
22
22
  end
23
23
 
@@ -112,8 +112,9 @@ module Metanorma
112
112
 
113
113
  def link_callouts_to_annotations(callouts, annotations)
114
114
  callouts.each_with_index do |c, i|
115
- c["target"] = "_#{UUIDTools::UUID.random_create}"
116
- annotations[i]["id"] = c["target"]
115
+ add_id(annotations[i])
116
+ annotations[i]["anchor"] = annotations[i]["id"]
117
+ c["target"] = annotations[i]["id"]
117
118
  end
118
119
  end
119
120
 
@@ -224,8 +225,7 @@ module Metanorma
224
225
  end
225
226
 
226
227
  def blocksource_cleanup(xmldoc)
227
- xmldoc.xpath("//figure//termsource | //table//termsource").each do |s|
228
- s.name = "source"
228
+ xmldoc.xpath("//figure//source | //table//source").each do |s|
229
229
  s.delete("type")
230
230
  end
231
231
  end
@@ -233,7 +233,7 @@ module Metanorma
233
233
  def unnumbered_blocks_cleanup(xmldoc)
234
234
  @blockunnumbered&.each do |b|
235
235
  xmldoc.xpath("//#{b}").each do |e|
236
- /^[^_]/.match?(e["id"]) and e["unnumbered"] = "false"
236
+ /^[^_]/.match?(e["anchor"]) and e["unnumbered"] = "false"
237
237
  e["unnumbered"] ||= "true"
238
238
  end
239
239
  end
@@ -151,8 +151,10 @@ module Metanorma
151
151
  if user_add.at("./clause") then built_in << user_add.children
152
152
  else
153
153
  user_add.name = "clause"
154
- user_add["id"].nil? || uuid?(user_add["id"]) and
155
- user_add["id"] = "_boilerplate-#{statement}-statement-append"
154
+ if user_add["id"].nil? || uuid?(user_add["id"])
155
+ user_add["anchor"] = "_boilerplate-#{statement}-statement-append"
156
+ add_id(user_add)
157
+ end
156
158
  built_in << user_add
157
159
  end
158
160
  end
@@ -187,8 +189,7 @@ module Metanorma
187
189
  xml.traverse do |n|
188
190
  n.element? or next
189
191
  n.namespace.href == ns and n.namespace = nil
190
- /^_\d+$/.match?(n["id"]) and
191
- n["id"] = "_#{UUIDTools::UUID.random_create}"
192
+ /^_\d+$/.match?(n["id"]) and add_id(n)
192
193
  end
193
194
  xml
194
195
  end
@@ -1,5 +1,3 @@
1
- require "date"
2
- require "htmlentities"
3
1
  require "json"
4
2
 
5
3
  module Metanorma
@@ -97,7 +95,7 @@ module Metanorma
97
95
  ids = xmldoc.xpath("//footnoteblock").each_with_object([]) do |f, m|
98
96
  f.name = "fn"
99
97
  m << f.text
100
- if id = xmldoc.at("//*[@id = '#{f.text}']")
98
+ if id = xmldoc.at("//*[@anchor = '#{f.text}']")
101
99
  f.children = id.dup.children
102
100
  else footnote_block_error(f)
103
101
  end
@@ -107,7 +105,7 @@ module Metanorma
107
105
 
108
106
  def footnote_block_remove(xmldoc, ids)
109
107
  ids.each do |id|
110
- n = xmldoc.at("//*[@id = '#{id}']") and
108
+ n = xmldoc.at("//*[@anchor = '#{id}']") and
111
109
  n.remove
112
110
  end
113
111
  end
@@ -15,9 +15,9 @@ module Metanorma
15
15
  f = s.at(".//figure") or next
16
16
  (t = s.at("./name")) && !f.at("./name") and
17
17
  f.children.first.previous = t.remove
18
- if s["id"] && Metanorma::Utils::guid_anchor?(f["id"])
19
- f["id"] = s["id"]
20
- s.delete("id")
18
+ if s["anchor"] # && Metanorma::Utils::guid_anchor?(f["id"])
19
+ f["anchor"] = s["anchor"]
20
+ s.delete("anchor")
21
21
  end
22
22
  svgmap_moveattrs1(s, f)
23
23
  end