metanorma-standoc 2.0.1 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/metanorma/standoc/base.rb +61 -22
- data/lib/metanorma/standoc/basicdoc.rng +5 -3
- data/lib/metanorma/standoc/biblio.rng +7 -5
- data/lib/metanorma/standoc/blocks.rb +3 -3
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +3 -3
- data/lib/metanorma/standoc/cleanup_image.rb +117 -3
- data/lib/metanorma/standoc/cleanup_ref.rb +32 -3
- data/lib/metanorma/standoc/cleanup_ref_dl.rb +20 -16
- data/lib/metanorma/standoc/cleanup_section.rb +2 -2
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +4 -2
- data/lib/metanorma/standoc/cleanup_text.rb +0 -22
- data/lib/metanorma/standoc/cleanup_xref.rb +82 -13
- data/lib/metanorma/standoc/converter.rb +2 -0
- data/lib/metanorma/standoc/inline.rb +21 -12
- data/lib/metanorma/standoc/isodoc.rng +142 -4
- data/lib/metanorma/standoc/macros.rb +14 -1
- data/lib/metanorma/standoc/macros_embed.rb +72 -0
- data/lib/metanorma/standoc/ref.rb +11 -7
- data/lib/metanorma/standoc/ref_utility.rb +2 -1
- data/lib/metanorma/standoc/render.rb +7 -3
- data/lib/metanorma/standoc/table.rb +8 -10
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +9 -6
- data/lib/metanorma/standoc/terms.rb +10 -7
- data/lib/metanorma/standoc/utils.rb +3 -1
- data/lib/metanorma/standoc/validate.rb +7 -2
- data/lib/metanorma/standoc/version.rb +1 -1
- data/spec/assets/a1.adoc +8 -0
- data/spec/assets/a2.adoc +8 -0
- data/spec/assets/a3.adoc +9 -0
- data/spec/assets/a4.adoc +4 -0
- data/spec/metanorma/base_spec.rb +1 -1
- data/spec/metanorma/cleanup_blocks_spec.rb +136 -0
- data/spec/metanorma/cleanup_spec.rb +13 -13
- data/spec/metanorma/cleanup_terms_spec.rb +1 -1
- data/spec/metanorma/inline_spec.rb +31 -0
- data/spec/metanorma/isobib_cache_spec.rb +2 -2
- data/spec/metanorma/macros_plantuml_spec.rb +41 -42
- data/spec/metanorma/macros_spec.rb +288 -2
- data/spec/metanorma/processor_spec.rb +17 -13
- data/spec/metanorma/refs_spec.rb +633 -461
- data/spec/metanorma/section_spec.rb +1 -1
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +48 -48
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +13 -13
- data/spec/vcr_cassettes/hide_refs.yml +100 -100
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +35 -35
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +11 -11
- data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +18 -18
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +86 -66
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48ca241528c217b9b563a2d3f6f2e13b52f2fa24e679ca2de431ebde8d10fb98
|
4
|
+
data.tar.gz: f6b70cd60a959376474a35ef4d364f69f9e15fd6582a53571a71cec995d90a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f175a4b49b2aa24d8c8b566a6929401f1a61fb217cf2ee03b506d93482a086afb7b09c85e7c6d88c93d1ef57d41e5a79dc6122bf41624842118dfa75759823b4
|
7
|
+
data.tar.gz: c395e93a7f1d3c03c63f1063f1689beb3e1725b81d26b2b38769038d491e8fade8462ab1b2f3b6324eede90c7e03b1473ce40873b903fd3859852436d69e7a9a
|
@@ -31,48 +31,65 @@ module Metanorma
|
|
31
31
|
@refids = Set.new
|
32
32
|
@anchors = {}
|
33
33
|
@internal_eref_namespaces = []
|
34
|
+
@seen_headers = []
|
34
35
|
@draft = node.attributes.has_key?("draft")
|
35
36
|
@novalid = node.attr("novalid")
|
36
37
|
@smartquotes = node.attr("smartquotes") != "false"
|
37
38
|
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
38
39
|
node.attr("mn-keep-asciimath") != "false"
|
39
|
-
@fontheader = default_fonts(node)
|
40
|
-
@files_to_delete = []
|
41
|
-
@filename = if node.attr("docfile")
|
42
|
-
File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
|
43
|
-
else ""
|
44
|
-
end
|
45
|
-
@localdir = Metanorma::Utils::localdir(node)
|
46
|
-
@output_dir = outputdir node
|
47
|
-
@no_isobib_cache = node.attr("no-isobib-cache")
|
48
|
-
@no_isobib = node.attr("no-isobib")
|
49
40
|
@index_terms = node.attr("index-terms")
|
50
41
|
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
51
42
|
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
52
|
-
@bibdb = nil
|
53
|
-
@seen_headers = []
|
54
43
|
@datauriimage = node.attr("data-uri-image") != "false"
|
55
44
|
@boilerplateauthority = node.attr("boilerplate-authority")
|
56
45
|
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
57
46
|
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
47
|
+
init_toc(node)
|
48
|
+
init_output(node)
|
49
|
+
init_i18n(node)
|
50
|
+
init_biblio(node)
|
51
|
+
@metadata_attrs = metadata_attrs(node)
|
52
|
+
end
|
53
|
+
|
54
|
+
def init_toc(node)
|
55
|
+
@htmltoclevels = node.attr("htmltoclevels")
|
56
|
+
@doctoclevels = node.attr("doctoclevels")
|
57
|
+
@toclevels = node.attr("toclevels")
|
58
|
+
@tocfigures = node.attr("toc-figures")
|
59
|
+
@toctables = node.attr("toc-tables")
|
60
|
+
@tocrecommendations = node.attr("toc-recommendations")
|
61
|
+
end
|
62
|
+
|
63
|
+
def init_output(node)
|
64
|
+
@fontheader = default_fonts(node)
|
58
65
|
@log = Metanorma::Utils::Log.new
|
59
|
-
|
60
|
-
|
66
|
+
@files_to_delete = []
|
67
|
+
@filename = if node.attr("docfile")
|
68
|
+
File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
|
69
|
+
else ""
|
70
|
+
end
|
71
|
+
@localdir = Metanorma::Utils::localdir(node)
|
72
|
+
@output_dir = outputdir node
|
73
|
+
end
|
74
|
+
|
75
|
+
def init_i18n(node)
|
61
76
|
@lang = (node.attr("language") || "en")
|
62
77
|
@script = (node.attr("script") ||
|
63
78
|
Metanorma::Utils.default_script(node.attr("language")))
|
64
79
|
@isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
|
65
80
|
@i18n = @isodoc.i18n
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@
|
81
|
+
end
|
82
|
+
|
83
|
+
def init_biblio(node)
|
84
|
+
@no_isobib_cache = node.attr("no-isobib-cache")
|
85
|
+
@no_isobib = node.attr("no-isobib")
|
86
|
+
@bibdb = nil
|
87
|
+
init_bib_caches(node)
|
88
|
+
init_iev_caches(node)
|
70
89
|
end
|
71
90
|
|
72
91
|
def document(node)
|
73
|
-
|
74
|
-
ret = makexml(node).to_xml(encoding: "US-ASCII", indent: 2)
|
75
|
-
outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
|
92
|
+
ret = document1(node)
|
76
93
|
clean_exit
|
77
94
|
ret
|
78
95
|
rescue StandardError => e
|
@@ -81,6 +98,28 @@ module Metanorma
|
|
81
98
|
raise e
|
82
99
|
end
|
83
100
|
|
101
|
+
def document1(node)
|
102
|
+
init(node)
|
103
|
+
ret = makexml(node)
|
104
|
+
.to_xml(encoding: "UTF-8", indent: 2,
|
105
|
+
save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
|
106
|
+
outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
|
107
|
+
ret
|
108
|
+
end
|
109
|
+
|
110
|
+
def insert_xml_cr(doc)
|
111
|
+
doc
|
112
|
+
.gsub(%r{(</(clause|table|figure|p|bibitem|ul|ol|dl|dt|dd|li|example|
|
113
|
+
sourcecode|formula|quote|references|annex|appendix|title|
|
114
|
+
name|note|thead|tbody|tfoot|th|td|form|requirement|
|
115
|
+
recommendation|permission|imagemap|svgmap|preferred|
|
116
|
+
admitted|related|deprecates|letter-symbol|domain|
|
117
|
+
graphical-symbol|expression|abbreviation-type|subject|
|
118
|
+
pronunciation|grammar|term|terms|termnote|termexample|
|
119
|
+
termsource|origin|termref|modification)>)}x, "\\1\n")
|
120
|
+
.gsub(%r{(<(title|name))}x, "\n\\1")
|
121
|
+
end
|
122
|
+
|
84
123
|
def version
|
85
124
|
flavour = self.class.name.sub(/::Converter$/, "").sub(/^.+::/, "")
|
86
125
|
Metanorma.versioned(Metanorma, flavour)[-1]::VERSION
|
@@ -110,7 +149,7 @@ module Metanorma
|
|
110
149
|
|
111
150
|
def makexml(node)
|
112
151
|
result = makexml1(node)
|
113
|
-
ret1 = cleanup(Nokogiri::XML(result))
|
152
|
+
ret1 = cleanup(Nokogiri::XML(insert_xml_cr(result)))
|
114
153
|
ret1.root.add_namespace(nil, xml_namespace)
|
115
154
|
validate(ret1) unless @novalid
|
116
155
|
ret1
|
@@ -173,9 +173,11 @@
|
|
173
173
|
<data type="dateTime"/>
|
174
174
|
</attribute>
|
175
175
|
</optional>
|
176
|
-
<
|
177
|
-
<
|
178
|
-
|
176
|
+
<optional>
|
177
|
+
<attribute name="from">
|
178
|
+
<data type="IDREF"/>
|
179
|
+
</attribute>
|
180
|
+
</optional>
|
179
181
|
<optional>
|
180
182
|
<attribute name="to">
|
181
183
|
<data type="IDREF"/>
|
@@ -209,9 +209,6 @@
|
|
209
209
|
<zeroOrMore>
|
210
210
|
<ref name="contact"/>
|
211
211
|
</zeroOrMore>
|
212
|
-
<zeroOrMore>
|
213
|
-
<ref name="uri"/>
|
214
|
-
</zeroOrMore>
|
215
212
|
</element>
|
216
213
|
</define>
|
217
214
|
<define name="fullname">
|
@@ -401,9 +398,9 @@
|
|
401
398
|
<choice>
|
402
399
|
<!-- iso191606 TODO -->
|
403
400
|
<group>
|
404
|
-
<
|
401
|
+
<zeroOrMore>
|
405
402
|
<ref name="street"/>
|
406
|
-
</
|
403
|
+
</zeroOrMore>
|
407
404
|
<ref name="city"/>
|
408
405
|
<optional>
|
409
406
|
<ref name="state"/>
|
@@ -828,6 +825,11 @@
|
|
828
825
|
<optional>
|
829
826
|
<attribute name="scope"/>
|
830
827
|
</optional>
|
828
|
+
<optional>
|
829
|
+
<attribute name="primary">
|
830
|
+
<data type="boolean"/>
|
831
|
+
</attribute>
|
832
|
+
</optional>
|
831
833
|
<text/>
|
832
834
|
</element>
|
833
835
|
</define>
|
@@ -174,11 +174,11 @@ module Metanorma
|
|
174
174
|
def paragraph(node)
|
175
175
|
return termsource(node) if node.role == "source"
|
176
176
|
|
177
|
-
noko do |xml|
|
177
|
+
ret = noko do |xml|
|
178
178
|
xml.p **para_attrs(node) do |xml_t|
|
179
179
|
xml_t << node.content
|
180
180
|
end
|
181
|
-
end.join
|
181
|
+
end.join
|
182
182
|
end
|
183
183
|
|
184
184
|
def quote_attrs(node)
|
@@ -203,7 +203,7 @@ module Metanorma
|
|
203
203
|
quote_attribution(node, q)
|
204
204
|
wrap_in_para(node, q)
|
205
205
|
end
|
206
|
-
end.join
|
206
|
+
end.join
|
207
207
|
end
|
208
208
|
|
209
209
|
def listing_attrs(node)
|
@@ -56,9 +56,9 @@ module Metanorma
|
|
56
56
|
TERM_CLAUSE = "//sections/terms | "\
|
57
57
|
"//sections/clause[descendant::terms]".freeze
|
58
58
|
|
59
|
-
NORM_REF =
|
60
|
-
|
61
|
-
.freeze
|
59
|
+
NORM_REF =
|
60
|
+
"//bibliography/references[@normative = 'true'][not(@hidden)] | "\
|
61
|
+
"//bibliography/clause[.//references[@normative = 'true']]".freeze
|
62
62
|
|
63
63
|
def boilerplate_isodoc(xmldoc)
|
64
64
|
x = xmldoc.dup
|
@@ -2,6 +2,7 @@ module Metanorma
|
|
2
2
|
module Standoc
|
3
3
|
module Cleanup
|
4
4
|
def svgmap_cleanup(xmldoc)
|
5
|
+
svg_uniqueids(xmldoc)
|
5
6
|
svgmap_moveattrs(xmldoc)
|
6
7
|
svgmap_populate(xmldoc)
|
7
8
|
Metanorma::Utils::svgmap_rewrite(xmldoc, @localdir)
|
@@ -59,12 +60,125 @@ module Metanorma
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def img_cleanup(xmldoc)
|
62
|
-
|
63
|
+
if @datauriimage
|
64
|
+
xmldoc.xpath("//image").each do |i|
|
65
|
+
# do not datauri encode SVG, we need to deduplicate its IDs
|
66
|
+
unless read_in_if_svg(i, @localdir)
|
67
|
+
i["src"] = Metanorma::Utils::datauri(i["src"], @localdir)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
svg_uniqueids(xmldoc)
|
72
|
+
xmldoc
|
73
|
+
end
|
74
|
+
|
75
|
+
def read_in_if_svg(img, localdir)
|
76
|
+
return false unless img["src"]
|
77
|
+
|
78
|
+
path = Metanorma::Utils::svgmap_rewrite0_path(img["src"], localdir)
|
79
|
+
File.file?(path) or return false
|
80
|
+
types = MIME::Types.type_for(path) or return false
|
81
|
+
types.first == "image/svg+xml" or return false
|
82
|
+
svg = File.read(path, encoding: "utf-8") or return false
|
83
|
+
img.replace(Nokogiri::XML(svg).root.to_xml)
|
84
|
+
true
|
85
|
+
end
|
86
|
+
|
87
|
+
IRI_TAG_PROPERTIES_MAP = {
|
88
|
+
clipPath: ["clip-path"],
|
89
|
+
"color-profile": nil,
|
90
|
+
cursor: nil,
|
91
|
+
filter: nil,
|
92
|
+
linearGradient: ["fill", "stroke"],
|
93
|
+
marker: ["marker", "marker-end", "marker-mid", "marker-start"],
|
94
|
+
mask: nil,
|
95
|
+
pattern: ["fill", "stroke"],
|
96
|
+
radialGradient: ["fill", "stroke"],
|
97
|
+
}.freeze
|
98
|
+
|
99
|
+
SVG_NS = "http://www.w3.org/2000/svg".freeze
|
100
|
+
|
101
|
+
def svg_uniqueids(xmldoc)
|
102
|
+
# only keep non-unique identifiers
|
103
|
+
ids = xmldoc.xpath("//m:svg//*/@id | //svg/@id", "m" => SVG_NS)
|
104
|
+
.map(&:text).group_by(&:itself).transform_values(&:count)
|
105
|
+
.delete_if { |_, v| v < 2 }
|
106
|
+
xmldoc.xpath("//m:svg", "m" => SVG_NS).each_with_index do |s, i|
|
107
|
+
ids = svg_uniqueids1(s, i, ids)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def svg_iri_properties(id_elems)
|
112
|
+
iri_tag_names = id_elems.each_with_object([]) do |e, m|
|
113
|
+
IRI_TAG_PROPERTIES_MAP.key?(e.name.to_sym) and m = m << e.name
|
114
|
+
end.uniq
|
115
|
+
iri_properties = iri_tag_names.each_with_object([]) do |t, m|
|
116
|
+
(IRI_TAG_PROPERTIES_MAP[t.to_sym] || [t]).each { |t1| m = m << t1 }
|
117
|
+
end.uniq
|
118
|
+
return [] if iri_properties.empty?
|
119
|
+
|
120
|
+
iri_properties << "style"
|
121
|
+
end
|
63
122
|
|
64
|
-
|
65
|
-
|
123
|
+
def svg_uniqueids1(svg, idx, ids)
|
124
|
+
id_elems = svg.xpath(".//*[@id] | ./@id/..")
|
125
|
+
iri_properties = svg_iri_properties(id_elems)
|
126
|
+
svg_uniqueids2(svg, iri_properties, idx, ids)
|
127
|
+
new_ids = id_elems.map { |x| x["id"] }
|
128
|
+
.map { |x| x + (ids[x] ? "_inject_#{idx}" : "") }
|
129
|
+
ids.merge(new_ids.each.map { |value| [value, true] }.to_h)
|
130
|
+
end
|
131
|
+
|
132
|
+
def svg_uniqueids2(svg, iri_properties, idx, ids)
|
133
|
+
svg.traverse do |e|
|
134
|
+
next unless e.element?
|
135
|
+
|
136
|
+
if e.name == "style"
|
137
|
+
svg_styleupdate(e, idx, ids)
|
138
|
+
elsif !e.attributes.empty?
|
139
|
+
svg_attrupdate(e, iri_properties, idx, ids)
|
140
|
+
end
|
141
|
+
svg_linkupdate(e, idx, ids)
|
142
|
+
svg_idupdate(e, idx, ids)
|
66
143
|
end
|
67
144
|
end
|
145
|
+
|
146
|
+
def svg_update_url(text, idx, ids)
|
147
|
+
text.gsub(/url\("?#([a-zA-Z][\w:.-]*)"?\)/) do |x|
|
148
|
+
if ids[$1] then "url(##{$1}_inject_#{idx})"
|
149
|
+
else x
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def svg_styleupdate(elem, idx, ids)
|
155
|
+
elem.children = svg_update_url(elem.text, idx, ids)
|
156
|
+
end
|
157
|
+
|
158
|
+
def svg_attrupdate(elem, iri_properties, idx, ids)
|
159
|
+
iri_properties.each do |p|
|
160
|
+
next unless elem[p]
|
161
|
+
|
162
|
+
elem[p] = svg_update_url(elem[p], idx, ids)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def svg_linkupdate(elem, idx, ids)
|
167
|
+
%w(xlink:href href).each do |ref|
|
168
|
+
iri = elem[ref]&.strip
|
169
|
+
next unless /^#/.match?(iri)
|
170
|
+
next unless ids[iri.sub(/^#/, "")]
|
171
|
+
|
172
|
+
elem[ref] += "_inject_#{idx}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def svg_idupdate(elem, idx, ids)
|
177
|
+
return unless elem["id"]
|
178
|
+
return unless ids[elem["id"]]
|
179
|
+
|
180
|
+
elem["id"] += "_inject_#{idx}"
|
181
|
+
end
|
68
182
|
end
|
69
183
|
end
|
70
184
|
end
|
@@ -16,7 +16,7 @@ module Metanorma
|
|
16
16
|
insert = refs&.at("./bibitem")&.previous_element
|
17
17
|
refs.xpath("./bibitem").each(&:remove)
|
18
18
|
bib.reverse.each do |b|
|
19
|
-
insert and insert.next = b.to_xml or
|
19
|
+
(insert and insert.next = b.to_xml) or
|
20
20
|
refs.children.first.add_previous_sibling b.to_xml
|
21
21
|
end
|
22
22
|
extract_notes_from_biblio(refs)
|
@@ -84,9 +84,39 @@ module Metanorma
|
|
84
84
|
biblio_reorder(xmldoc)
|
85
85
|
biblio_nested(xmldoc)
|
86
86
|
biblio_renumber(xmldoc)
|
87
|
+
biblio_linkonly(xmldoc)
|
88
|
+
biblio_hidden_inherit(xmldoc)
|
87
89
|
biblio_no_ext(xmldoc)
|
88
90
|
end
|
89
91
|
|
92
|
+
def biblio_hidden_inherit(xmldoc)
|
93
|
+
xmldoc.xpath("//references[@hidden = 'true']").each do |r|
|
94
|
+
r.xpath("./bibitem").each do |b|
|
95
|
+
b["hidden"] = true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def biblio_linkonly(xmldoc)
|
101
|
+
return unless xmldoc.at("//xref[@hidden]")
|
102
|
+
|
103
|
+
ins = xmldoc.at("//bibliography")
|
104
|
+
.add_child("<references hidden='true' normative='true'/>").first
|
105
|
+
refs = xmldoc.xpath("//xref[@hidden]").each_with_object([]) do |x, m|
|
106
|
+
@refids << x["target"]
|
107
|
+
m << { id: x["target"], ref: x["hidden"] }
|
108
|
+
x.delete("hidden")
|
109
|
+
end
|
110
|
+
ins << insert_hidden_bibitems(refs)
|
111
|
+
end
|
112
|
+
|
113
|
+
def insert_hidden_bibitems(bib)
|
114
|
+
refs = bib.each_with_object([]) do |b, m|
|
115
|
+
m << reference1code(%(<ref id="#{b[:id]}">[#{b[:ref]}]</ref>), nil)
|
116
|
+
end
|
117
|
+
reference_populate(refs)
|
118
|
+
end
|
119
|
+
|
90
120
|
def biblio_no_ext(xmldoc)
|
91
121
|
xmldoc.xpath("//bibitem/ext").each(&:remove)
|
92
122
|
end
|
@@ -114,10 +144,9 @@ module Metanorma
|
|
114
144
|
|
115
145
|
def reference_names(xmldoc)
|
116
146
|
xmldoc.xpath("//bibitem[not(ancestor::bibitem)]").each do |ref|
|
117
|
-
# isopub = ref.at(ISO_PUBLISHER_XPATH)
|
118
147
|
docid = ref.at("./docidentifier[@type = 'metanorma']") ||
|
119
148
|
ref.at("./docidentifier[not(@type = 'DOI')]") or next
|
120
|
-
reference = format_ref(docid.
|
149
|
+
reference = format_ref(docid.children.to_xml, docid["type"])
|
121
150
|
@anchors[ref["id"]] = { xref: reference }
|
122
151
|
end
|
123
152
|
end
|
@@ -15,19 +15,20 @@ module Metanorma
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def validate_ref_dl(bib,
|
18
|
+
def validate_ref_dl(bib, clause)
|
19
19
|
id = bib["id"]
|
20
|
-
|
20
|
+
# do not accept implicit id
|
21
|
+
id ||= clause["id"] unless /^_/.match?(clause["id"])
|
21
22
|
unless id
|
22
|
-
@log.add("Anchors",
|
23
|
-
"The following reference is missing an anchor:\n
|
23
|
+
@log.add("Anchors", clause,
|
24
|
+
"The following reference is missing an anchor:\n#{clause.to_xml}")
|
24
25
|
return
|
25
26
|
end
|
26
27
|
@refids << id
|
27
28
|
bib["title"] or
|
28
|
-
@log.add("Bibliography",
|
29
|
+
@log.add("Bibliography", clause, "Reference #{id} is missing a title")
|
29
30
|
bib["docid"] or
|
30
|
-
@log.add("Bibliography",
|
31
|
+
@log.add("Bibliography", clause,
|
31
32
|
"Reference #{id} is missing a document identifier (docid)")
|
32
33
|
end
|
33
34
|
|
@@ -76,27 +77,30 @@ module Metanorma
|
|
76
77
|
end
|
77
78
|
|
78
79
|
# definition list, with at most one level of unordered lists
|
79
|
-
def dl_bib_extract(
|
80
|
-
dl =
|
80
|
+
def dl_bib_extract(clause, nested = false)
|
81
|
+
dl = clause.at("./dl") or return
|
81
82
|
bib = {}
|
82
83
|
key = ""
|
83
84
|
dl.xpath("./dt | ./dd").each do |dtd|
|
84
85
|
(dtd.name == "dt" and key = dtd.text.sub(/:+$/, "")) or
|
85
86
|
add_to_hash(bib, key, dd_bib_extract(dtd))
|
86
87
|
end
|
87
|
-
|
88
|
+
clause.xpath("./clause").each do |c1|
|
88
89
|
key = c1&.at("./title")&.text&.downcase&.strip
|
89
90
|
next unless %w(contributor relation series).include? key
|
90
91
|
|
91
92
|
add_to_hash(bib, key, dl_bib_extract(c1, true))
|
92
93
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
dl_bib_extract_title(bib, clause, nested)
|
95
|
+
end
|
96
|
+
|
97
|
+
def dl_bib_extract_title(bib, clause, nested)
|
98
|
+
(!nested && clause.at("./title")) or return bib
|
99
|
+
title = clause.at("./title").remove.children.to_xml
|
100
|
+
bib["title"] = [bib["title"]] if bib["title"].is_a?(Hash) ||
|
101
|
+
bib["title"].is_a?(String)
|
102
|
+
bib["title"] = [] unless bib["title"]
|
103
|
+
bib["title"] << title if !title.empty?
|
100
104
|
bib
|
101
105
|
end
|
102
106
|
end
|
@@ -54,7 +54,7 @@ module Metanorma
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def make_bibliography(xml, sect)
|
57
|
-
if xml.at("//sections/references")
|
57
|
+
if xml.at("//sections/references | //xref[@hidden]")
|
58
58
|
biblio = sect.add_next_sibling("<bibliography/>").first
|
59
59
|
xml.xpath("//sections/references").each do |r|
|
60
60
|
biblio.add_child r.remove
|
@@ -193,7 +193,7 @@ module Metanorma
|
|
193
193
|
next unless t.next_element.nil?
|
194
194
|
next if %w(sections annex preface).include? t.parent.name
|
195
195
|
|
196
|
-
t.parent.
|
196
|
+
t.parent.next = t
|
197
197
|
found = true
|
198
198
|
end
|
199
199
|
break unless found
|
@@ -182,10 +182,12 @@ module Metanorma
|
|
182
182
|
|
183
183
|
def term_designation_reorder(xmldoc)
|
184
184
|
xmldoc.xpath("//term").each do |t|
|
185
|
-
%w(preferred admitted deprecates related)
|
185
|
+
des = %w(preferred admitted deprecates related)
|
186
186
|
.each_with_object([]) do |tag, m|
|
187
187
|
t.xpath("./#{tag}").each { |x| m << x.remove }
|
188
|
-
end.reverse
|
188
|
+
end.reverse
|
189
|
+
t << " "
|
190
|
+
des.each do |x|
|
189
191
|
t.children.first.previous = x
|
190
192
|
end
|
191
193
|
end
|
@@ -28,28 +28,6 @@ module Metanorma
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# "abc<tag/>", def => "abc",<tag/> def
|
31
|
-
=begin
|
32
|
-
def uninterrupt_quotes_around_xml(xmldoc)
|
33
|
-
xmldoc.xpath("//*[following::text()[1]"\
|
34
|
-
"[starts-with(., '\"') or starts-with(., \"'\")]]")
|
35
|
-
.each do |x|
|
36
|
-
next if !x.ancestors("pre, tt, sourcecode, stem, figure").empty?
|
37
|
-
|
38
|
-
uninterrupt_quotes_around_xml1(x)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
=end
|
42
|
-
=begin
|
43
|
-
def uninterrupt_quotes_around_xml(xmldoc)
|
44
|
-
xmldoc.traverse do |n|
|
45
|
-
next unless n.element? && n&.next&.text? &&
|
46
|
-
n.ancestors("pre, tt, sourcecode, stem, figure").empty?
|
47
|
-
next unless /^['"]/.match?(n.next.text)
|
48
|
-
|
49
|
-
uninterrupt_quotes_around_xml1(n)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
=end
|
53
31
|
def uninterrupt_quotes_around_xml(xmldoc)
|
54
32
|
xmldoc.traverse do |n|
|
55
33
|
next unless n.text? && n&.previous&.element?
|