metanorma-standoc 3.0.7 → 3.0.8
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.
- checksums.yaml +4 -4
- data/lib/metanorma/standoc/anchor.rb +1 -1
- data/lib/metanorma/standoc/base.rb +1 -1
- data/lib/metanorma/standoc/basicdoc.rng +9 -5
- data/lib/metanorma/standoc/blocks.rb +7 -4
- data/lib/metanorma/standoc/blocks_image.rb +2 -6
- data/lib/metanorma/standoc/blocks_notes.rb +2 -6
- data/lib/metanorma/standoc/cleanup_amend.rb +6 -8
- data/lib/metanorma/standoc/cleanup_asciibib.rb +17 -13
- data/lib/metanorma/standoc/cleanup_bibdata.rb +19 -13
- data/lib/metanorma/standoc/cleanup_bibitem.rb +9 -6
- data/lib/metanorma/standoc/cleanup_block.rb +6 -6
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +5 -4
- data/lib/metanorma/standoc/cleanup_footnotes.rb +2 -4
- data/lib/metanorma/standoc/cleanup_image.rb +3 -3
- data/lib/metanorma/standoc/cleanup_inline.rb +12 -38
- data/lib/metanorma/standoc/cleanup_review.rb +7 -5
- data/lib/metanorma/standoc/cleanup_section.rb +5 -2
- data/lib/metanorma/standoc/cleanup_table.rb +1 -2
- data/lib/metanorma/standoc/cleanup_terms.rb +1 -1
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +1 -1
- data/lib/metanorma/standoc/cleanup_toc.rb +1 -1
- data/lib/metanorma/standoc/cleanup_xref.rb +1 -1
- data/lib/metanorma/standoc/init.rb +15 -7
- data/lib/metanorma/standoc/inline.rb +7 -7
- data/lib/metanorma/standoc/isodoc.rng +132 -5
- data/lib/metanorma/standoc/localbib.rb +1 -2
- data/lib/metanorma/standoc/macros_form.rb +21 -3
- data/lib/metanorma/standoc/macros_link.rb +4 -5
- data/lib/metanorma/standoc/ref.rb +2 -2
- data/lib/metanorma/standoc/ref_sect.rb +1 -1
- data/lib/metanorma/standoc/ref_utility.rb +4 -3
- data/lib/metanorma/standoc/section.rb +5 -6
- data/lib/metanorma/standoc/table.rb +9 -13
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +26 -9
- data/lib/metanorma/standoc/terms.rb +1 -1
- data/lib/metanorma/standoc/utils.rb +4 -0
- data/lib/metanorma/standoc/validate.rb +50 -23
- data/lib/metanorma/standoc/validate_schema.rb +2 -0
- data/lib/metanorma/standoc/validate_term.rb +8 -7
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6effed725121e1f1924a44b86be0de3ebd4bcf5cc1349b07c3933a1b8666ffdf
|
4
|
+
data.tar.gz: 3def10482963835400c5f5e9c7f1283ba26311a1bd82da6319633ab6186ea561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39cd5c14eebf34d92214d6c76c9f8cd2aa72e4eed77d31998d629174096439dcab567326d565c7540e3ffe1aa7dfcd87c11f7f31148f6bc4a1895adad240dab6
|
7
|
+
data.tar.gz: f88823d2442c1ce9eadb24b34985cc5aba32a121531c01341a1da0483ce9273dc881a90f32ce22319018458028bffd0feb313584c11e39aa088badf298b3f4eb
|
@@ -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|
|
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
|
-
<
|
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
|
-
<
|
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
|
-
<
|
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
|
-
<
|
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
|
-
<
|
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
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
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
|
@@ -2,11 +2,7 @@ module Metanorma
|
|
2
2
|
module Standoc
|
3
3
|
module Blocks
|
4
4
|
def svgmap_attrs(node)
|
5
|
-
attr_code(
|
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(
|
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
|
-
|
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)
|
@@ -8,8 +8,8 @@ module Metanorma
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def create_amend(clause)
|
11
|
-
a = clause.add_child("<amend
|
12
|
-
|
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::*")
|
36
|
-
post = q.xpath("./following-sibling::*")
|
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
|
-
|
45
|
-
|
44
|
+
clause[e] or next
|
46
45
|
amend[e] = clause[e]
|
47
46
|
clause.delete(e)
|
48
47
|
end
|
49
|
-
|
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
|
-
|
12
|
-
bibitem = Nokogiri::XML(
|
13
|
-
bibitem.root
|
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["
|
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
|
-
|
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
|
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
|
86
|
-
|
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
|
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
|
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
|
-
|
71
|
+
id_map.has_key?(loc) and return
|
71
72
|
else
|
72
|
-
eref.document.at("//*[@
|
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
|
-
|
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
|
-
|
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["
|
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["
|
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[@
|
215
|
-
m[b["
|
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["
|
218
|
-
m[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"]
|
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
|
-
|
116
|
-
annotations[i]["
|
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//
|
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["
|
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"])
|
155
|
-
user_add["
|
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("//*[@
|
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("//*[@
|
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["
|
19
|
-
f["
|
20
|
-
s.delete("
|
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
|
@@ -33,7 +33,7 @@ module Metanorma
|
|
33
33
|
xmldoc.xpath("//bookmark").each do |b|
|
34
34
|
p = b
|
35
35
|
while !p.xml? && p = p.parent
|
36
|
-
p["
|
36
|
+
p["anchor"] == b["anchor"] or next
|
37
37
|
b.remove
|
38
38
|
break
|
39
39
|
end
|
@@ -43,6 +43,7 @@ module Metanorma
|
|
43
43
|
def bookmark_to_id(elem, bookmark)
|
44
44
|
parent = bookmark.parent
|
45
45
|
elem["id"] = bookmark.remove["id"]
|
46
|
+
elem["anchor"] = bookmark.remove["anchor"]
|
46
47
|
strip_initial_space(parent)
|
47
48
|
end
|
48
49
|
|
@@ -123,63 +124,34 @@ module Metanorma
|
|
123
124
|
end
|
124
125
|
|
125
126
|
def to_xreftarget(str)
|
126
|
-
return Metanorma::Utils::to_ncname(str)
|
127
|
-
|
127
|
+
/^[^#]+#.+$/.match?(str) or return Metanorma::Utils::to_ncname(str)
|
128
128
|
/^(?<pref>[^#]+)#(?<suff>.+)$/ =~ str
|
129
129
|
pref = pref.gsub(%r([#{Metanorma::Utils::NAMECHAR}])o, "_")
|
130
130
|
suff = suff.gsub(%r([#{Metanorma::Utils::NAMECHAR}])o, "_")
|
131
131
|
"#{pref}##{suff}"
|
132
132
|
end
|
133
133
|
|
134
|
-
IDREF = "//*/@id | //review/@from | //review/@to | " \
|
135
|
-
"//callout/@target | //citation/@bibitemid | " \
|
136
|
-
"//eref/@bibitemid".freeze
|
137
|
-
|
138
134
|
def anchor_cleanup(elem)
|
139
|
-
anchor_cleanup1(elem)
|
140
|
-
xreftarget_cleanup(elem)
|
141
135
|
contenthash_id_cleanup(elem)
|
142
136
|
end
|
143
137
|
|
144
|
-
def anchor_cleanup1(elem)
|
145
|
-
elem.xpath(IDREF).each do |s|
|
146
|
-
if (ret = Metanorma::Utils::to_ncname(s.value)) != (orig = s.value)
|
147
|
-
s.value = ret
|
148
|
-
@log.add("Anchors", s.parent,
|
149
|
-
"normalised identifier to #{ret} from #{orig}",
|
150
|
-
display: false)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def xreftarget_cleanup(elem)
|
156
|
-
elem.xpath("//xref/@target").each do |s|
|
157
|
-
if (ret = to_xreftarget(s.value)) != (orig = s.value)
|
158
|
-
s.value = ret
|
159
|
-
@log.add("Anchors", s.parent,
|
160
|
-
"normalised identifier to #{ret} from #{orig}",
|
161
|
-
display: false)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
138
|
def contenthash_id_cleanup(doc)
|
167
|
-
|
168
|
-
|
139
|
+
@contenthash_ids = contenthash_id_make(doc)
|
140
|
+
#contenthash_id_update_idrefs(doc, @contenthash_ids)
|
169
141
|
end
|
170
142
|
|
171
143
|
def contenthash_id_make(doc)
|
172
144
|
doc.xpath("//*[@id]").each_with_object({}) do |x, m|
|
173
|
-
|
174
|
-
|
145
|
+
# should always be true
|
146
|
+
Metanorma::Utils::guid_anchor?(x["id"]) or next
|
175
147
|
m[x["id"]] = contenthash(x)
|
148
|
+
x["anchor"] and m[x["anchor"]] = m[x["id"]]
|
176
149
|
x["id"] = m[x["id"]]
|
177
150
|
end
|
178
151
|
end
|
179
152
|
|
180
|
-
def
|
181
|
-
|
182
|
-
%w(citation bibitemid), %w(xref target), %w(xref to)].each do |a|
|
153
|
+
def contenthash_id_update_idrefs(doc, ids)
|
154
|
+
Metanorma::Utils::anchor_attributes.each do |a|
|
183
155
|
doc.xpath("//#{a[0]}").each do |x|
|
184
156
|
ids[x[a[1]]] and x[a[1]] = ids[x[a[1]]]
|
185
157
|
end
|
@@ -227,6 +199,8 @@ module Metanorma
|
|
227
199
|
def select_odd_chars(text)
|
228
200
|
text.gsub(/(?!&)([[:punct:]])\u200c/, "\\1")
|
229
201
|
end
|
202
|
+
|
203
|
+
include ::Metanorma::Standoc::Utils
|
230
204
|
end
|
231
205
|
end
|
232
206
|
end
|
@@ -11,14 +11,15 @@ module Metanorma
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def review_insert_bookmark(review
|
14
|
+
def review_insert_bookmark(review)
|
15
15
|
parent = review.parent
|
16
16
|
children = parent.children
|
17
17
|
index = children.index(review)
|
18
18
|
x = find_review_sibling(children, index, :previous) ||
|
19
19
|
find_review_sibling(children, index, :following)
|
20
20
|
ins = x || review.before("<p> </p>").previous.at(".//text()")
|
21
|
-
ins.previous = "<bookmark
|
21
|
+
ins.previous = "<bookmark/>"
|
22
|
+
ins.previous
|
22
23
|
end
|
23
24
|
|
24
25
|
# we know node is a block: dig for a place bookmark can go
|
@@ -65,9 +66,10 @@ module Metanorma
|
|
65
66
|
|
66
67
|
def review_set_location(review)
|
67
68
|
unless review["from"]
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
bookmark = review_insert_bookmark(review)
|
70
|
+
add_id(bookmark)
|
71
|
+
bookmark["anchor"] = bookmark["id"]
|
72
|
+
review["from"] = bookmark["id"]
|
71
73
|
end
|
72
74
|
review["to"] ||= review["from"]
|
73
75
|
end
|
@@ -46,7 +46,10 @@ module Metanorma
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def clean_abstract(dupabstract)
|
49
|
-
dupabstract.traverse
|
49
|
+
dupabstract.traverse do |n|
|
50
|
+
n.remove_attribute("id")
|
51
|
+
n.remove_attribute("anchor")
|
52
|
+
end
|
50
53
|
%w(language script unnumbered).each do |w|
|
51
54
|
dupabstract.remove_attribute(w)
|
52
55
|
end
|
@@ -96,7 +99,7 @@ module Metanorma
|
|
96
99
|
y.delete("annex")
|
97
100
|
y.name == "annex" || !y.ancestors("annex").empty? and next
|
98
101
|
y.wrap("<annex/>")
|
99
|
-
y.parent
|
102
|
+
add_id(y.parent)
|
100
103
|
%w(obligation language script).each { |w| y.parent[w] = y[w] }
|
101
104
|
end
|
102
105
|
end
|
@@ -56,10 +56,9 @@ module Metanorma
|
|
56
56
|
until nomatches
|
57
57
|
nomatches = true
|
58
58
|
xmldoc.xpath("//table/following-sibling::*[1]" \
|
59
|
-
"[self::
|
59
|
+
"[self::source]").each do |n|
|
60
60
|
n.previous_element << n.remove
|
61
61
|
nomatches = false
|
62
|
-
# will be renamed source from termsource later
|
63
62
|
end
|
64
63
|
end
|
65
64
|
end
|