metanorma-standoc 1.4.4 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +4 -9
- data/.github/workflows/ubuntu.yml +1 -5
- data/.github/workflows/windows.yml +2 -12
- data/.rubocop.yml +1 -1
- data/lib/asciidoctor/standoc/base.rb +11 -5
- data/lib/asciidoctor/standoc/base_structured_text_preprocessor.rb +123 -0
- data/lib/asciidoctor/standoc/basicdoc.rng +23 -0
- data/lib/asciidoctor/standoc/cleanup.rb +32 -12
- data/lib/asciidoctor/standoc/cleanup_amend.rb +54 -0
- data/lib/asciidoctor/standoc/cleanup_block.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +11 -24
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -3
- data/lib/asciidoctor/standoc/cleanup_inline.rb +62 -1
- data/lib/asciidoctor/standoc/cleanup_ref.rb +10 -7
- data/lib/asciidoctor/standoc/cleanup_section.rb +91 -8
- data/lib/asciidoctor/standoc/cleanup_terms.rb +12 -2
- data/lib/asciidoctor/standoc/converter.rb +3 -3
- data/lib/asciidoctor/standoc/front.rb +0 -12
- data/lib/asciidoctor/standoc/front_contributor.rb +51 -10
- data/lib/asciidoctor/standoc/inline.rb +21 -31
- data/lib/asciidoctor/standoc/isodoc.rng +137 -21
- data/lib/asciidoctor/standoc/json2_text_preprocessor.rb +44 -0
- data/lib/asciidoctor/standoc/log.rb +10 -1
- data/lib/asciidoctor/standoc/macros.rb +45 -33
- data/lib/asciidoctor/standoc/ref.rb +45 -45
- data/lib/asciidoctor/standoc/section.rb +39 -30
- data/lib/asciidoctor/standoc/table.rb +3 -2
- data/lib/asciidoctor/standoc/utils.rb +18 -1
- data/lib/asciidoctor/standoc/validate.rb +30 -18
- data/lib/asciidoctor/standoc/validate_section.rb +1 -1
- data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +10 -10
- data/lib/asciidoctor/standoc/yaml2_text_preprocessor.rb +46 -0
- data/lib/liquid/custom_blocks/key_iterator.rb +21 -0
- data/lib/liquid/custom_filters/values.rb +7 -0
- data/lib/metanorma/standoc.rb +0 -5
- data/lib/metanorma/standoc/version.rb +20 -1
- data/metanorma-standoc.gemspec +4 -5
- data/spec/asciidoctor-standoc/base_spec.rb +140 -7
- data/spec/asciidoctor-standoc/blocks_spec.rb +275 -149
- data/spec/asciidoctor-standoc/cleanup_spec.rb +1372 -56
- data/spec/asciidoctor-standoc/inline_spec.rb +133 -6
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +9 -7
- data/spec/asciidoctor-standoc/macros_json2text_spec.rb +10 -0
- data/spec/asciidoctor-standoc/macros_spec.rb +43 -23
- data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +5 -560
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +9 -7
- data/spec/asciidoctor-standoc/refs_spec.rb +43 -34
- data/spec/asciidoctor-standoc/section_spec.rb +42 -39
- data/spec/asciidoctor-standoc/table_spec.rb +119 -113
- data/spec/asciidoctor-standoc/validate_spec.rb +45 -1
- data/spec/assets/i18n.yaml +17 -2
- data/spec/examples/codes_table.html +1365 -1365
- data/spec/fixtures/macros_datamodel/address_class_profile.xml +46 -46
- data/spec/fixtures/macros_datamodel/address_component_profile.xml +21 -21
- data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +21 -21
- data/spec/metanorma/processor_spec.rb +1 -2
- data/spec/spec_helper.rb +110 -109
- data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +629 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +71 -71
- data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
- data/spec/vcr_cassettes/isobib_get_123_1.yml +36 -36
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +16 -16
- data/spec/vcr_cassettes/isobib_get_124.yml +17 -17
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +39 -37
- metadata +29 -14
- data/lib/asciidoctor-yaml/i18n-en.yaml +0 -20
- data/lib/asciidoctor-yaml/i18n-fr.yaml +0 -13
- data/lib/asciidoctor-yaml/i18n-zh-Hans.yaml +0 -15
- data/lib/asciidoctor/standoc/i18n.rb +0 -39
- data/lib/asciidoctor/standoc/macros_yaml2text.rb +0 -165
- data/lib/metanorma/standoc/latexml_requirement.rb +0 -62
- data/lib/metanorma/standoc/requirement.rb +0 -13
@@ -42,8 +42,7 @@ module Asciidoctor
|
|
42
42
|
|
43
43
|
def docid(t, code)
|
44
44
|
type, code1 = /^\[\d+\]$|^\([^)]+\).*$/.match(code) ?
|
45
|
-
["metanorma", mn_code(code)] :
|
46
|
-
@bibdb&.docid_type(code) || [nil, code]
|
45
|
+
["metanorma", mn_code(code)] : @bibdb&.docid_type(code) || [nil, code]
|
47
46
|
code1.sub!(/^nofetch\((.+)\)$/, "\\1")
|
48
47
|
t.docidentifier **attr_code(type: type) do |d|
|
49
48
|
d << code1
|
@@ -61,10 +60,10 @@ module Asciidoctor
|
|
61
60
|
end
|
62
61
|
|
63
62
|
def isorefrender1(t, m, yr, allp = "")
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
|
64
|
+
docid(t, m[:usrlbl]) if m[:usrlbl]
|
65
|
+
docid(t, id_and_year(m[:code], yr) + allp)
|
66
|
+
docnumber(t, m[:code])
|
68
67
|
end
|
69
68
|
|
70
69
|
def isorefmatches(xml, m)
|
@@ -84,6 +83,10 @@ module Asciidoctor
|
|
84
83
|
ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn],
|
85
84
|
title: m[:text], usrlbl: m[:usrlbl]
|
86
85
|
return use_my_anchor(ref, m[:anchor]) if ref
|
86
|
+
isorefmatches2_1(xml, m)
|
87
|
+
end
|
88
|
+
|
89
|
+
def isorefmatches2_1(xml, m)
|
87
90
|
xml.bibitem **attr_code(ref_attributes(m)) do |t|
|
88
91
|
isorefrender1(t, m, "--")
|
89
92
|
t.date **{ type: "published" } do |d|
|
@@ -106,15 +109,17 @@ module Asciidoctor
|
|
106
109
|
|
107
110
|
def isorefmatches3(xml, m)
|
108
111
|
yr = norm_year(m[:year])
|
109
|
-
hasyr =
|
110
|
-
|
111
|
-
|
112
|
-
all_parts: true, no_year: noyr, text: m[:text], usrlbl: m[:usrlbl]
|
112
|
+
hasyr = !yr.nil? && yr != "--"
|
113
|
+
ref = fetch_ref xml, m[:code], hasyr ? yr : nil, all_parts: true,
|
114
|
+
no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl]
|
113
115
|
return use_my_anchor(ref, m[:anchor]) if ref
|
116
|
+
isorefmatches3_1(xml, m, yr, hasyr, ref)
|
117
|
+
end
|
114
118
|
|
119
|
+
def isorefmatches3_1(xml, m, yr, hasyr, ref)
|
115
120
|
xml.bibitem(**attr_code(ref_attributes(m))) do |t|
|
116
121
|
isorefrender1(t, m, yr, " (all parts)")
|
117
|
-
conditional_date(t, m,
|
122
|
+
conditional_date(t, m, yr == "--")
|
118
123
|
iso_publisher(t, m[:code])
|
119
124
|
m.names.include?("fn") && m[:fn] and
|
120
125
|
t.note(**plaintxt.merge(type: "ISO DATE")) { |p| p << "#{m[:fn]}" }
|
@@ -146,43 +151,32 @@ module Asciidoctor
|
|
146
151
|
end
|
147
152
|
|
148
153
|
MALFORMED_REF = "no anchor on reference, markup may be malformed: see "\
|
149
|
-
"https://www.metanorma.com/author/topics/document-format/
|
150
|
-
"https://www.metanorma.com/author/iso/topics/markup
|
154
|
+
"https://www.metanorma.com/author/topics/document-format/"\
|
155
|
+
"bibliography/ , https://www.metanorma.com/author/iso/topics/markup/"\
|
156
|
+
"#bibliographies".freeze
|
151
157
|
|
152
158
|
def analyse_ref_nofetch(ret)
|
153
|
-
|
154
|
-
|
155
|
-
ret[:nofetch] = true
|
156
|
-
end
|
157
|
-
ret
|
159
|
+
return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
|
160
|
+
ret.merge(id: m[:id], nofetch: true)
|
158
161
|
end
|
159
|
-
|
162
|
+
|
160
163
|
def analyse_ref_repo_path(ret)
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
ret[:key] = m[:key]
|
165
|
-
ret[:nofetch] = true
|
166
|
-
end
|
167
|
-
ret
|
164
|
+
return ret unless m =
|
165
|
+
/^(?<type>repo|path):\((?<key>[^,]+),(?<id>.+)\)$/.match(ret[:id])
|
166
|
+
ret.merge(id: m[:id], type: m[:type], key: m[:key], nofetch: true)
|
168
167
|
end
|
169
168
|
|
170
169
|
def analyse_ref_numeric(ret)
|
171
|
-
|
172
|
-
|
173
|
-
end
|
174
|
-
ret
|
170
|
+
return ret unless /^\d+$/.match(ret[:id])
|
171
|
+
ret.merge(numeric: true)
|
175
172
|
end
|
176
173
|
|
177
174
|
# ref id = (usrlbl)code[:-]year
|
178
|
-
# code = nofetch(code) | (repo|path):(key,code) | \[? number \]? |
|
175
|
+
# code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
|
179
176
|
def analyse_ref_code(code)
|
180
177
|
ret = {id: code}
|
181
178
|
return ret if code.nil? || code.empty?
|
182
|
-
|
183
|
-
ret = analyse_ref_repo_path(ret)
|
184
|
-
ret = analyse_ref_numeric(ret)
|
185
|
-
ret
|
179
|
+
analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
|
186
180
|
end
|
187
181
|
|
188
182
|
# TODO: alternative where only title is available
|
@@ -191,6 +185,10 @@ module Asciidoctor
|
|
191
185
|
@log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
|
192
186
|
return
|
193
187
|
end
|
188
|
+
refitem1(xml, item, m)
|
189
|
+
end
|
190
|
+
|
191
|
+
def refitem1(xml, item, m)
|
194
192
|
code = analyse_ref_code(m[:code])
|
195
193
|
unless code[:id] && code[:numeric] || code[:nofetch]
|
196
194
|
ref = fetch_ref xml, code[:id],
|
@@ -215,23 +213,25 @@ module Asciidoctor
|
|
215
213
|
(?<text>.*)$}xm
|
216
214
|
|
217
215
|
ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
|
218
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
|
216
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
|
217
|
+
(--|\&\#821[12]\;)\]</ref>,?\s*
|
219
218
|
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
|
220
219
|
|
221
220
|
ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
|
222
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
|
221
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
|
222
|
+
(:(?<year>--|\&\#821[12]\;|[0-9][0-9-]+))?\s
|
223
223
|
\(all\sparts\)\]</ref>,?\s*
|
224
224
|
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
|
225
225
|
|
226
226
|
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
227
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
227
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
|
228
|
+
([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s*(?<text>.*)$}xm
|
229
|
+
|
230
|
+
def reference1_matches(item)
|
231
|
+
matched = ISO_REF.match item
|
232
|
+
matched2 = ISO_REF_NO_YEAR.match item
|
233
|
+
matched3 = ISO_REF_ALL_PARTS.match item
|
234
|
+
[matched, matched2, matched3]
|
235
235
|
end
|
236
236
|
|
237
237
|
def reference1(node, item, xml)
|
@@ -13,9 +13,13 @@ module Asciidoctor
|
|
13
13
|
@term_def
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def sectiontype1(node)
|
17
|
+
node&.attr("heading")&.downcase ||
|
18
18
|
node.title.gsub(/<[^>]+>/, "").downcase
|
19
|
+
end
|
20
|
+
|
21
|
+
def sectiontype(node, level = true)
|
22
|
+
ret = sectiontype1(node)
|
19
23
|
ret1 = sectiontype_streamline(ret)
|
20
24
|
return ret1 if "symbols and abbreviated terms" == ret1
|
21
25
|
return nil unless !level || node.level == 1
|
@@ -42,7 +46,7 @@ module Asciidoctor
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def section_attributes(node)
|
45
|
-
{ id: Utils::anchor_or_uuid(node),
|
49
|
+
ret = { id: Utils::anchor_or_uuid(node),
|
46
50
|
language: node.attributes["language"],
|
47
51
|
script: node.attributes["script"],
|
48
52
|
annex: (
|
@@ -51,8 +55,13 @@ module Asciidoctor
|
|
51
55
|
),
|
52
56
|
preface: (
|
53
57
|
(node.role == "preface" || node.attr("style") == "preface") ?
|
54
|
-
true : nil)
|
55
|
-
|
58
|
+
true : nil) }
|
59
|
+
return ret unless node.attributes["change"]
|
60
|
+
ret.merge(change: node.attributes["change"],
|
61
|
+
path: node.attributes["path"],
|
62
|
+
path_end: node.attributes["path_end"],
|
63
|
+
title: node.attributes["title"],
|
64
|
+
)
|
56
65
|
end
|
57
66
|
|
58
67
|
def section(node)
|
@@ -61,16 +70,18 @@ module Asciidoctor
|
|
61
70
|
case sectiontype(node)
|
62
71
|
when "introduction" then introduction_parse(a, xml, node)
|
63
72
|
when "foreword" then foreword_parse(a, xml, node)
|
73
|
+
when "scope" then scope_parse(a, xml, node)
|
64
74
|
when "normative references" then norm_ref_parse(a, xml, node)
|
65
75
|
when "terms and definitions"
|
66
76
|
@term_def = true
|
67
77
|
term_def_parse(a, xml, node, true)
|
68
78
|
@term_def = false
|
69
79
|
when "symbols and abbreviated terms"
|
70
|
-
symbols_parse(a, xml, node)
|
80
|
+
symbols_parse(symbols_attrs(node, a), xml, node)
|
71
81
|
when "acknowledgements"
|
72
82
|
acknowledgements_parse(a, xml, node)
|
73
|
-
when "bibliography"
|
83
|
+
when "bibliography"
|
84
|
+
bibliography_parse(a, xml, node)
|
74
85
|
else
|
75
86
|
if @term_def then term_def_subclause_parse(a, xml, node)
|
76
87
|
elsif @definitions then symbols_parse(a, xml, node)
|
@@ -106,7 +117,7 @@ module Asciidoctor
|
|
106
117
|
def preamble(node)
|
107
118
|
noko do |xml|
|
108
119
|
xml.foreword **attr_code(section_attributes(node)) do |xml_abstract|
|
109
|
-
xml_abstract.title { |t| t << (node.blocks[0].title ||
|
120
|
+
xml_abstract.title { |t| t << (node.blocks[0].title || @i18n.foreword) }
|
110
121
|
content = node.content
|
111
122
|
xml_abstract << content
|
112
123
|
end
|
@@ -119,6 +130,10 @@ module Asciidoctor
|
|
119
130
|
end
|
120
131
|
end
|
121
132
|
|
133
|
+
def scope_parse(attrs, xml, node)
|
134
|
+
clause_parse(attrs.merge(type: "scope"), xml, node)
|
135
|
+
end
|
136
|
+
|
122
137
|
def clause_parse(attrs, xml, node)
|
123
138
|
attrs["inline-header".to_sym] = node.option? "inline-header"
|
124
139
|
attrs[:bibitem] = true if node.option? "bibitem"
|
@@ -140,9 +155,19 @@ module Asciidoctor
|
|
140
155
|
end
|
141
156
|
|
142
157
|
def nonterm_symbols_parse(attrs, xml, node)
|
158
|
+
defs = @definitions
|
143
159
|
@definitions = false
|
144
160
|
clause_parse(attrs, xml, node)
|
145
|
-
@definitions =
|
161
|
+
@definitions = defs
|
162
|
+
end
|
163
|
+
|
164
|
+
def symbols_attrs(node, a)
|
165
|
+
case sectiontype1(node)
|
166
|
+
when "symbols" then a.merge(type: "symbols")
|
167
|
+
when "abbreviated terms", "abbreviations" then a.merge(type: "abbreviated_terms")
|
168
|
+
else
|
169
|
+
a
|
170
|
+
end
|
146
171
|
end
|
147
172
|
|
148
173
|
def symbols_parse(attr, xml, node)
|
@@ -159,13 +184,11 @@ module Asciidoctor
|
|
159
184
|
end
|
160
185
|
end
|
161
186
|
|
162
|
-
SYMBOLS_TITLES = ["symbols and abbreviated terms", "symbols",
|
163
|
-
"abbreviated terms"].freeze
|
164
|
-
|
165
187
|
def nonterm_term_def_subclause_parse(attrs, xml, node)
|
188
|
+
defs = @term_def
|
166
189
|
@term_def = false
|
167
190
|
clause_parse(attrs, xml, node)
|
168
|
-
@term_def =
|
191
|
+
@term_def = defs
|
169
192
|
end
|
170
193
|
|
171
194
|
# subclause contains subclauses
|
@@ -190,23 +213,9 @@ module Asciidoctor
|
|
190
213
|
end
|
191
214
|
end
|
192
215
|
|
193
|
-
def term_def_title(toplevel, node)
|
194
|
-
return node.title unless toplevel
|
195
|
-
sub = node.find_by(context: :section) do |s|
|
196
|
-
SYMBOLS_TITLES.include? s.title.downcase
|
197
|
-
end
|
198
|
-
return "Terms and definitions" if sub.empty?
|
199
|
-
sym = /symbol/i.match(node.title)
|
200
|
-
abbrev = /abbreviat/i.match(node.title)
|
201
|
-
sym && abbrev and return "Terms, definitions, symbols and abbreviated terms"
|
202
|
-
sym and return "Terms, definitions and symbols"
|
203
|
-
abbrev and return "Terms, definitions and abbreviated terms"
|
204
|
-
"Terms, definitions, symbols and abbreviated terms"
|
205
|
-
end
|
206
|
-
|
207
216
|
def term_def_parse(attrs, xml, node, toplevel)
|
208
217
|
xml.terms **attr_code(attrs) do |section|
|
209
|
-
section.title { |t| t <<
|
218
|
+
section.title { |t| t << node.title }
|
210
219
|
(s = node.attr("source")) && s.split(/,/).each do |s1|
|
211
220
|
section.termdocsource(nil, **attr_code(bibitemid: s1))
|
212
221
|
end
|
@@ -216,7 +225,7 @@ module Asciidoctor
|
|
216
225
|
|
217
226
|
def introduction_parse(attrs, xml, node)
|
218
227
|
xml.introduction **attr_code(attrs) do |xml_section|
|
219
|
-
xml_section.title { |t| t <<
|
228
|
+
xml_section.title { |t| t << @i18n.introduction }
|
220
229
|
content = node.content
|
221
230
|
xml_section << content
|
222
231
|
end
|
@@ -232,7 +241,7 @@ module Asciidoctor
|
|
232
241
|
|
233
242
|
def acknowledgements_parse(attrs, xml, node)
|
234
243
|
xml.acknowledgements **attr_code(attrs) do |xml_section|
|
235
|
-
xml_section.title { |t| t << node.title ||
|
244
|
+
xml_section.title { |t| t << node.title || @i18n.acknowledgements }
|
236
245
|
content = node.content
|
237
246
|
xml_section << content
|
238
247
|
end
|
@@ -45,8 +45,9 @@ module Asciidoctor
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def table_cell(c, xml_tr, tblsec)
|
48
|
-
cell_attributes =
|
49
|
-
|
48
|
+
cell_attributes =
|
49
|
+
{ id: c.id, colspan: c.colspan, valign: c.attr("valign"),
|
50
|
+
rowspan: c.rowspan, align: c.attr("halign") }
|
50
51
|
cell_tag = "td"
|
51
52
|
cell_tag = "th" if tblsec == :head || c.style == :header
|
52
53
|
xml_tr.send cell_tag, **attr_code(cell_attributes) do |thd|
|
@@ -128,7 +128,8 @@ module Asciidoctor
|
|
128
128
|
::Nokogiri::XML::Builder.with fragment, &block
|
129
129
|
fragment.to_xml(encoding: "US-ASCII", indent: 0).lines.map do |l|
|
130
130
|
l.gsub(/>\n$/, ">").gsub(/\s*\n$/m, " ").gsub("–", "\u0096").
|
131
|
-
gsub("—", "\u0097")
|
131
|
+
gsub("—", "\u0097").gsub("–", "\u0096").
|
132
|
+
gsub("—", "\u0097")
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
@@ -173,6 +174,22 @@ module Asciidoctor
|
|
173
174
|
|
174
175
|
SUBCLAUSE_XPATH = "//clause[not(parent::sections)]"\
|
175
176
|
"[not(ancestor::boilerplate)]".freeze
|
177
|
+
|
178
|
+
def isodoc(lang, script, i18nyaml = nil)
|
179
|
+
conv = html_converter(EmptyAttr.new)
|
180
|
+
i18n = conv.i18n_init(lang, script, i18nyaml)
|
181
|
+
conv.metadata_init(lang, script, i18n)
|
182
|
+
conv
|
183
|
+
end
|
184
|
+
|
185
|
+
class EmptyAttr
|
186
|
+
def attr(_x)
|
187
|
+
nil
|
188
|
+
end
|
189
|
+
def attributes
|
190
|
+
{}
|
191
|
+
end
|
192
|
+
end
|
176
193
|
end
|
177
194
|
end
|
178
195
|
end
|
@@ -8,7 +8,8 @@ module Asciidoctor
|
|
8
8
|
module Standoc
|
9
9
|
module Validate
|
10
10
|
|
11
|
-
SOURCELOCALITY = "./termsource/origin//locality[@type = 'clause']/
|
11
|
+
SOURCELOCALITY = "./termsource/origin//locality[@type = 'clause']/"\
|
12
|
+
"referenceFrom".freeze
|
12
13
|
|
13
14
|
def init_iev
|
14
15
|
return nil if @no_isobib
|
@@ -19,13 +20,16 @@ module Asciidoctor
|
|
19
20
|
|
20
21
|
def iev_validate(xmldoc)
|
21
22
|
xmldoc.xpath("//term").each do |t|
|
22
|
-
/^IEC 60050-/.match(t&.at("./termsource/origin/@citeas")&.text)
|
23
|
-
|
24
|
-
locality = t.xpath(SOURCELOCALITY)&.text or next
|
23
|
+
/^IEC 60050-/.match(t&.at("./termsource/origin/@citeas")&.text) &&
|
24
|
+
loc = t.xpath(SOURCELOCALITY)&.text or next
|
25
25
|
@iev = init_iev or return
|
26
|
-
iev = @iev.fetch(
|
26
|
+
iev = @iev.fetch(loc, xmldoc&.at("//language")&.text || "en") or next
|
27
|
+
pref = t.xpath("./preferred").inject([]) do |m, x|
|
28
|
+
m << x&.text&.downcase
|
29
|
+
end
|
27
30
|
pref.include?(iev.downcase) or
|
28
|
-
|
31
|
+
@log.add("Bibliography", t, %(Term "#{pref[0]}" does not match ) +
|
32
|
+
%(IEV #{loc} "#{iev}"))
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
@@ -35,20 +39,26 @@ module Asciidoctor
|
|
35
39
|
iev_validate(doc.root)
|
36
40
|
end
|
37
41
|
|
42
|
+
def repeat_id_validate1(ids, x)
|
43
|
+
if ids[x["id"]]
|
44
|
+
@log.add("Anchors", x, "Anchor #{x['id']} has already been used "\
|
45
|
+
"at line #{ids[x['id']]}")
|
46
|
+
raise StandardError.new "Error: multiple instances of same ID"
|
47
|
+
else
|
48
|
+
ids[x["id"]] = x.line
|
49
|
+
end
|
50
|
+
ids
|
51
|
+
end
|
52
|
+
|
38
53
|
def repeat_id_validate(doc)
|
39
54
|
ids = {}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@log.add("Anchors", x, "Anchor #{x['id']} has already been used at line #{ids[x['id']]}")
|
44
|
-
crash = true
|
45
|
-
else
|
46
|
-
ids[x["id"]] = x.line
|
55
|
+
begin
|
56
|
+
doc.xpath("//*[@id]").each do |x|
|
57
|
+
ids = repeat_id_validate1(ids, x)
|
47
58
|
end
|
48
|
-
|
49
|
-
if crash
|
59
|
+
rescue StandardError => e
|
50
60
|
clean_exit
|
51
|
-
abort(
|
61
|
+
abort(e.message)
|
52
62
|
end
|
53
63
|
end
|
54
64
|
|
@@ -59,8 +69,10 @@ module Asciidoctor
|
|
59
69
|
f.close
|
60
70
|
errors = Jing.new(schema).validate(f.path)
|
61
71
|
warn "Syntax Valid!" if errors.none?
|
62
|
-
errors.each do |
|
63
|
-
@log.add("
|
72
|
+
errors.each do |e|
|
73
|
+
@log.add("Metanorma XML Syntax",
|
74
|
+
"XML Line #{"%06d" % e[:line]}:#{e[:column]}",
|
75
|
+
e[:message])
|
64
76
|
end
|
65
77
|
rescue Jing::Error => e
|
66
78
|
clean_exit
|