metanorma-standoc 3.2.0 → 3.2.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.
- checksums.yaml +4 -4
- data/lib/metanorma/standoc/anchor.rb +3 -2
- data/lib/metanorma/standoc/biblio.rng +4 -4
- data/lib/metanorma/standoc/blocks.rb +3 -6
- data/lib/metanorma/standoc/cleanup.rb +27 -57
- data/lib/metanorma/standoc/cleanup_bibdata.rb +23 -4
- data/lib/metanorma/standoc/cleanup_inline.rb +43 -2
- data/lib/metanorma/standoc/cleanup_section_names.rb +1 -0
- data/lib/metanorma/standoc/cleanup_xref.rb +11 -3
- data/lib/metanorma/standoc/front.rb +27 -25
- data/lib/metanorma/standoc/front_committee.rb +5 -5
- data/lib/metanorma/standoc/front_contributor.rb +14 -14
- data/lib/metanorma/standoc/front_ext.rb +7 -5
- data/lib/metanorma/standoc/front_organisation.rb +16 -21
- data/lib/metanorma/standoc/init.rb +31 -5
- data/lib/metanorma/standoc/inline.rb +30 -9
- data/lib/metanorma/standoc/isodoc.rng +27 -10
- data/lib/metanorma/standoc/lists.rb +1 -1
- data/lib/metanorma/standoc/log.rb +12 -0
- data/lib/metanorma/standoc/macros_terms.rb +2 -0
- data/lib/metanorma/standoc/ref.rb +11 -11
- data/lib/metanorma/standoc/ref_utility.rb +2 -6
- data/lib/metanorma/standoc/section.rb +3 -9
- data/lib/metanorma/standoc/table.rb +1 -1
- data/lib/metanorma/standoc/terms.rb +1 -1
- data/lib/metanorma/standoc/utils.rb +27 -2
- data/lib/metanorma/standoc/validate.rb +2 -0
- data/lib/metanorma/standoc/validate_image.rb +49 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +4 -3
- metadata +46 -32
|
@@ -3,11 +3,11 @@ module Metanorma
|
|
|
3
3
|
module Front
|
|
4
4
|
def organization(org, orgname, node = nil, default_org = nil, attrs = {})
|
|
5
5
|
orgname, abbr = org_name_and_abbrev(attrs, orgname)
|
|
6
|
-
org
|
|
6
|
+
add_noko_elem(org, "name", orgname)
|
|
7
7
|
default_org && (a = node&.attr("subdivision")) && !attrs[:subdiv] and
|
|
8
8
|
subdivision(a, node&.attr("subdivision-abbr"), org)
|
|
9
9
|
a = attrs[:subdiv] and subdivision(a, nil, org)
|
|
10
|
-
|
|
10
|
+
add_noko_elem(org, "abbreviation", abbr)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def org_name_and_abbrev(org, orgname)
|
|
@@ -45,32 +45,30 @@ module Metanorma
|
|
|
45
45
|
def subdiv_build(list, org)
|
|
46
46
|
list.empty? and return
|
|
47
47
|
org.subdivision **attr_code(type: list[0][:type]) do |s|
|
|
48
|
-
s
|
|
48
|
+
add_noko_elem(s, "name", list[0][:value])
|
|
49
49
|
subdiv_build(list[1..], s)
|
|
50
|
-
|
|
50
|
+
add_noko_elem(s, "abbreviation", list[0][:abbr])
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def org_address(org, xml)
|
|
55
55
|
p = org[:address] and xml.address do |ad|
|
|
56
|
-
ad
|
|
57
|
-
f << p.gsub(/ \+\n/, "<br/>")
|
|
58
|
-
end
|
|
56
|
+
add_noko_elem(ad, "formattedAddress", p.gsub(/ \+\n/, "<br/>"))
|
|
59
57
|
end
|
|
60
58
|
org_contact(org, xml)
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
def org_contact(org, xml)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
add_noko_elem(xml, "phone", org[:phone])
|
|
63
|
+
add_noko_elem(xml, "phone", org[:fax], type: "fax")
|
|
64
|
+
add_noko_elem(xml, "email", org[:email])
|
|
65
|
+
add_noko_elem(xml, "uri", org[:uri])
|
|
68
66
|
end
|
|
69
67
|
|
|
70
68
|
def person_organization(node, suffix, xml)
|
|
71
|
-
xml
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
add_noko_elem(xml, "name", node.attr("affiliation#{suffix}"))
|
|
70
|
+
add_noko_elem(xml, "abbreviation",
|
|
71
|
+
node.attr("affiliation_abbrev#{suffix}"))
|
|
74
72
|
a = node.attr("affiliation_subdiv#{suffix}") and
|
|
75
73
|
subdivision(a, nil, xml)
|
|
76
74
|
person_address(node, suffix, xml)
|
|
@@ -80,9 +78,8 @@ module Metanorma
|
|
|
80
78
|
def person_address(node, suffix, xml)
|
|
81
79
|
if node.attr("address#{suffix}")
|
|
82
80
|
xml.address do |ad|
|
|
83
|
-
ad
|
|
84
|
-
|
|
85
|
-
end
|
|
81
|
+
add_noko_elem(ad, "formattedAddress",
|
|
82
|
+
node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>"))
|
|
86
83
|
end
|
|
87
84
|
elsif node.attr("country#{suffix}") || node.attr("city#{suffix}")
|
|
88
85
|
person_address_components(node, suffix, xml)
|
|
@@ -92,7 +89,7 @@ module Metanorma
|
|
|
92
89
|
def person_address_components(node, suffix, xml)
|
|
93
90
|
xml.address do |ad|
|
|
94
91
|
%w(street city state country postcode).each do |k|
|
|
95
|
-
|
|
92
|
+
add_noko_elem(ad, k, node.attr("#{k}#{suffix}"))
|
|
96
93
|
end
|
|
97
94
|
end
|
|
98
95
|
end
|
|
@@ -128,9 +125,7 @@ module Metanorma
|
|
|
128
125
|
|
|
129
126
|
def org_contributor_role(xml, org)
|
|
130
127
|
xml.role type: org[:role] do |r|
|
|
131
|
-
org[:desc]
|
|
132
|
-
d << org[:desc]
|
|
133
|
-
end
|
|
128
|
+
add_noko_elem(r, "description", org[:desc])
|
|
134
129
|
end
|
|
135
130
|
end
|
|
136
131
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require_relative "utils"
|
|
2
2
|
require_relative "regex"
|
|
3
|
+
require "json"
|
|
3
4
|
|
|
4
5
|
module Metanorma
|
|
5
6
|
module Standoc
|
|
@@ -41,6 +42,7 @@ module Metanorma
|
|
|
41
42
|
@embed_id = node.attr("embed_id")
|
|
42
43
|
@document_scheme = document_scheme(node)
|
|
43
44
|
@source_linenums = node.attr("source-linenums-option") == "true"
|
|
45
|
+
# feeds log
|
|
44
46
|
@semantic_headless = node.attr("semantic-metadata-headless") == "true"
|
|
45
47
|
@default_doctype = "standard"
|
|
46
48
|
end
|
|
@@ -53,22 +55,46 @@ module Metanorma
|
|
|
53
55
|
@smartquotes = node.attr("smartquotes") != "false"
|
|
54
56
|
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
|
55
57
|
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
|
56
|
-
@blockunnumbered = (node.attr("block-unnumbered")
|
|
57
|
-
.map(&:strip)
|
|
58
|
+
@blockunnumbered = csv_split(node.attr("block-unnumbered"), ",")
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
def init_log(node)
|
|
61
62
|
@log or return
|
|
63
|
+
@semantic_headless and return
|
|
62
64
|
severity = node.attr("log-filter-severity")&.to_i || 4
|
|
63
|
-
category = node.attr("log-filter-category")
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
category = csv_split(node.attr("log-filter-category"), ",")
|
|
66
|
+
error_ids = csv_split(node.attr("log-filter-error-ids"), ",")
|
|
67
|
+
locations = cleanup_log_filter_error_log(
|
|
68
|
+
extract_log_filter_error_loc(node),
|
|
69
|
+
)
|
|
70
|
+
@log.suppress_log = { severity:, category:, error_ids:, locations: }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def extract_log_filter_error_loc(node)
|
|
74
|
+
locations = JSON.parse(node.attr("log-filter-error-loc") || "[]")
|
|
75
|
+
locations = [locations] unless locations.is_a?(Array)
|
|
76
|
+
locations.map { |loc| loc.transform_keys(&:to_sym) }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def cleanup_log_filter_error_log(locations)
|
|
80
|
+
locations.each do |loc|
|
|
81
|
+
loc[:to] ||= loc[:from]
|
|
82
|
+
loc[:error_ids] ||= []
|
|
83
|
+
loc[:error_ids] &&= Array(loc[:error_ids])
|
|
84
|
+
end
|
|
66
85
|
end
|
|
67
86
|
|
|
68
87
|
def init_image(node)
|
|
69
88
|
@datauriimage = node.attr("data-uri-image") != "false"
|
|
70
89
|
@datauriattachment = node.attr("data-uri-attachment") != "false"
|
|
71
90
|
@dataurimaxsize = node.attr("data-uri-maxsize")&.to_i || 13981013
|
|
91
|
+
@svg_conform_profile =
|
|
92
|
+
node.attr("svg-conform-profile")&.sub(/^:/, "") ||
|
|
93
|
+
default_svg_conform_profile
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def default_svg_conform_profile
|
|
97
|
+
:metanorma
|
|
72
98
|
end
|
|
73
99
|
|
|
74
100
|
def init_reqt(node)
|
|
@@ -49,7 +49,8 @@ module Metanorma
|
|
|
49
49
|
end
|
|
50
50
|
elsif style == :latexmath then latex_parse(text, xml, attrs)
|
|
51
51
|
else
|
|
52
|
-
xml.stem text&.gsub("&#", "&#")
|
|
52
|
+
xml.stem text&.gsub("&#", "&#") || "",
|
|
53
|
+
**attrs.merge(type: "AsciiMath")
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
56
|
|
|
@@ -79,9 +80,7 @@ module Metanorma
|
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
def highlight_parse(text, xml)
|
|
82
|
-
xml
|
|
83
|
-
s << text
|
|
84
|
-
end
|
|
83
|
+
add_noko_elem(xml, "span", text, class: "fmt-hi")
|
|
85
84
|
end
|
|
86
85
|
|
|
87
86
|
def inline_quoted(node)
|
|
@@ -179,16 +178,38 @@ module Metanorma
|
|
|
179
178
|
def inline_indexterm(node)
|
|
180
179
|
noko do |xml|
|
|
181
180
|
node.type == :visible and xml << node.text
|
|
182
|
-
terms = (node
|
|
183
|
-
inline_indexterm1(xml, terms)
|
|
181
|
+
terms, see, also = inline_indexterm_extract(node)
|
|
182
|
+
(see || also) or inline_indexterm1(xml, terms)
|
|
183
|
+
also and
|
|
184
|
+
inline_indexterm_see(xml, terms, also, true)
|
|
185
|
+
see and
|
|
186
|
+
inline_indexterm_see(xml, terms, [see], false)
|
|
184
187
|
end
|
|
185
188
|
end
|
|
186
189
|
|
|
190
|
+
def inline_indexterm_extract(node)
|
|
191
|
+
terms = (node.attr("terms") || [node.text]).map { |x| xml_encode(x) }
|
|
192
|
+
see = node.attr("see")
|
|
193
|
+
also = node.attr("see-also")
|
|
194
|
+
[terms, see, also]
|
|
195
|
+
end
|
|
196
|
+
|
|
187
197
|
def inline_indexterm1(xml, terms)
|
|
188
198
|
xml.index do |i|
|
|
189
|
-
i
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
add_noko_elem(i, "primary", terms[0])
|
|
200
|
+
add_noko_elem(i, "secondary", terms[1])
|
|
201
|
+
add_noko_elem(i, "tertiary", terms[2])
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def inline_indexterm_see(xml, terms, ref, also)
|
|
206
|
+
ref.each do |r|
|
|
207
|
+
xml.index_xref also: also do |i|
|
|
208
|
+
add_noko_elem(i, "primary", terms[0])
|
|
209
|
+
add_noko_elem(i, "secondary", terms[1])
|
|
210
|
+
add_noko_elem(i, "tertiary", terms[2])
|
|
211
|
+
add_noko_elem(i, "target", r)
|
|
212
|
+
end
|
|
192
213
|
end
|
|
193
214
|
end
|
|
194
215
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
|
3
|
-
<!-- VERSION v2.1.
|
|
3
|
+
<!-- VERSION v2.1.4 -->
|
|
4
4
|
|
|
5
5
|
<!--
|
|
6
6
|
ALERT: cannot have root comments, because of https://github.com/metanorma/metanorma/issues/437
|
|
@@ -905,15 +905,32 @@ titlecase, or lowercase</a:documentation>
|
|
|
905
905
|
</element>
|
|
906
906
|
</define>
|
|
907
907
|
<define name="image" combine="choice">
|
|
908
|
-
<
|
|
909
|
-
<
|
|
910
|
-
|
|
911
|
-
<
|
|
912
|
-
|
|
913
|
-
<
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
908
|
+
<choice>
|
|
909
|
+
<element name="image">
|
|
910
|
+
<ref name="RequiredId"/>
|
|
911
|
+
<ref name="ImageAttributes"/>
|
|
912
|
+
<optional>
|
|
913
|
+
<element name="svg">
|
|
914
|
+
<a:documentation>Allow svg in image/svg, for consistency</a:documentation>
|
|
915
|
+
<oneOrMore>
|
|
916
|
+
<choice>
|
|
917
|
+
<text/>
|
|
918
|
+
<ref name="AnyElement"/>
|
|
919
|
+
</choice>
|
|
920
|
+
</oneOrMore>
|
|
921
|
+
</element>
|
|
922
|
+
</optional>
|
|
923
|
+
</element>
|
|
924
|
+
<element name="svg">
|
|
925
|
+
<a:documentation>Add svg mark up to image</a:documentation>
|
|
926
|
+
<oneOrMore>
|
|
927
|
+
<choice>
|
|
928
|
+
<text/>
|
|
929
|
+
<ref name="AnyElement"/>
|
|
930
|
+
</choice>
|
|
931
|
+
</oneOrMore>
|
|
932
|
+
</element>
|
|
933
|
+
</choice>
|
|
917
934
|
</define>
|
|
918
935
|
<define name="ParagraphFnBody" combine="interleave">
|
|
919
936
|
<ref name="BlockSource">
|
|
@@ -168,6 +168,18 @@ module Metanorma
|
|
|
168
168
|
"STANDOC_54": { category: "Bibliography",
|
|
169
169
|
error: "Cannot process file %s for local Relaton data source %s",
|
|
170
170
|
severity: 0 },
|
|
171
|
+
"STANDOC_55": { category: "Images",
|
|
172
|
+
error: "Corrupt SVG image detected, error found: %s %s%s%s",
|
|
173
|
+
severity: 2 },
|
|
174
|
+
"STANDOC_56": { category: "Images",
|
|
175
|
+
error: "Corrupt SVG image detected, could not be fixed: %s %s%s%s",
|
|
176
|
+
severity: 1 },
|
|
177
|
+
"STANDOC_57": { category: "Images",
|
|
178
|
+
error: "SVG image warning: %s %s%s%s",
|
|
179
|
+
severity: 3 },
|
|
180
|
+
"STANDOC_58": { category: "Images",
|
|
181
|
+
error: "Corrupt SVG image detected, fix attempted: %s %s: %s %s, Node: %s",
|
|
182
|
+
severity: 2 },
|
|
171
183
|
"RELATON_1": { category: "Relaton",
|
|
172
184
|
error: "(Error from Relaton) %s",
|
|
173
185
|
severity: 0 },
|
|
@@ -71,6 +71,7 @@ module Metanorma
|
|
|
71
71
|
named :term
|
|
72
72
|
name_positional_attributes "name", "termxref"
|
|
73
73
|
using_format :short
|
|
74
|
+
match /\\?(?<!\w)term:(){0}\[(|[^\]\\]*(?:\\.[^\]\\]*)*)\]/
|
|
74
75
|
|
|
75
76
|
def process(_parent, _target, attrs)
|
|
76
77
|
termref = attrs["termxref"] || attrs["name"]
|
|
@@ -84,6 +85,7 @@ module Metanorma
|
|
|
84
85
|
named :symbol
|
|
85
86
|
name_positional_attributes "name", "termxref"
|
|
86
87
|
using_format :short
|
|
88
|
+
match /\\?(?<!\w)symbol:(){0}\[(|[^\]\\]*(?:\\.[^\]\\]*)*)\]/
|
|
87
89
|
|
|
88
90
|
def process(_parent, _target, attrs)
|
|
89
91
|
termref = attrs["termxref"] || attrs["name"]
|
|
@@ -60,9 +60,8 @@ module Metanorma
|
|
|
60
60
|
|
|
61
61
|
def ref_fn(match, xml)
|
|
62
62
|
if match.names.include?("fn") && match[:fn]
|
|
63
|
-
xml
|
|
64
|
-
|
|
65
|
-
end
|
|
63
|
+
add_noko_elem(xml, "note", match[:fn].to_s,
|
|
64
|
+
**plaintxt.merge(type: "Unpublished-Status"))
|
|
66
65
|
end
|
|
67
66
|
end
|
|
68
67
|
|
|
@@ -115,17 +114,19 @@ module Metanorma
|
|
|
115
114
|
i = code[:id] and
|
|
116
115
|
docid(bib, /^\d+$/.match?(i) ? "[#{i}]" : i, code[:type])
|
|
117
116
|
code[:type] == "repo" and
|
|
118
|
-
bib
|
|
117
|
+
add_noko_elem(bib, "docidentifier", code[:key], type: "repository")
|
|
119
118
|
end
|
|
120
119
|
|
|
121
120
|
def refitem_uri(code, bib)
|
|
122
121
|
if code[:type] == "path"
|
|
123
|
-
bib
|
|
124
|
-
|
|
122
|
+
add_noko_elem(bib, "uri", code[:key].sub(/\.[a-zA-Z0-9]+$/, ""),
|
|
123
|
+
type: "URI")
|
|
124
|
+
add_noko_elem(bib, "uri", code[:key].sub(/\.[a-zA-Z0-9]+$/, ""),
|
|
125
|
+
type: "citation")
|
|
125
126
|
end
|
|
126
127
|
if code[:type] == "attachment"
|
|
127
|
-
bib
|
|
128
|
-
bib
|
|
128
|
+
add_noko_elem(bib, "uri", code[:key], type: "attachment")
|
|
129
|
+
add_noko_elem(bib, "uri", code[:key], type: "citation")
|
|
129
130
|
end
|
|
130
131
|
end
|
|
131
132
|
|
|
@@ -149,9 +150,8 @@ module Metanorma
|
|
|
149
150
|
|
|
150
151
|
def refitem_render_formattedref(bibitem, title)
|
|
151
152
|
(title.nil? || title.empty?) and title = @i18n.no_information_available
|
|
152
|
-
bibitem
|
|
153
|
-
|
|
154
|
-
end
|
|
153
|
+
add_noko_elem(bibitem, "formattedref", ref_normalise_no_format(title),
|
|
154
|
+
format: "application/x-isodoc+xml")
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
# TODO: alternative where only title is available
|
|
@@ -49,16 +49,12 @@ module Metanorma
|
|
|
49
49
|
else @bibdb&.docid_type(code) || [nil, code]
|
|
50
50
|
end
|
|
51
51
|
code1.sub!(/^nofetch\((.+)\)$/, "\\1")
|
|
52
|
-
bib
|
|
53
|
-
d << code1
|
|
54
|
-
end
|
|
52
|
+
add_noko_elem(bib, "docidentifier", code1, type: type)
|
|
55
53
|
end
|
|
56
54
|
|
|
57
55
|
def docnumber(bib, code)
|
|
58
56
|
code or return
|
|
59
|
-
bib
|
|
60
|
-
d << @c.decode(code).sub(/^[^\d]*/, "")
|
|
61
|
-
end
|
|
57
|
+
add_noko_elem(bib, "docnumber", @c.decode(code).sub(/^[^\d]*/, ""))
|
|
62
58
|
end
|
|
63
59
|
|
|
64
60
|
def mn_code(code)
|
|
@@ -87,9 +87,7 @@ module Metanorma
|
|
|
87
87
|
|
|
88
88
|
def section_title(xml, title)
|
|
89
89
|
title.nil? and return
|
|
90
|
-
xml
|
|
91
|
-
t << title
|
|
92
|
-
end
|
|
90
|
+
add_noko_elem(xml, "title", title, id_attr(nil))
|
|
93
91
|
end
|
|
94
92
|
|
|
95
93
|
def preamble(node)
|
|
@@ -102,9 +100,7 @@ module Metanorma
|
|
|
102
100
|
end
|
|
103
101
|
|
|
104
102
|
def metanorma_extension_parse(_attrs, xml, node)
|
|
105
|
-
xml
|
|
106
|
-
xml_section << node.content
|
|
107
|
-
end
|
|
103
|
+
add_noko_elem(xml, "metanorma-extension-clause", node.content)
|
|
108
104
|
end
|
|
109
105
|
|
|
110
106
|
def indexsect_parse(attrs, xml, node)
|
|
@@ -115,9 +111,7 @@ module Metanorma
|
|
|
115
111
|
end
|
|
116
112
|
|
|
117
113
|
def abstract_parse(attrs, xml, node)
|
|
118
|
-
xml
|
|
119
|
-
xml_section << node.content
|
|
120
|
-
end
|
|
114
|
+
add_noko_elem(xml, "abstract", node.content, **attr_code(attrs))
|
|
121
115
|
end
|
|
122
116
|
|
|
123
117
|
def scope_parse(attrs, xml, node)
|
|
@@ -5,6 +5,22 @@ require "json"
|
|
|
5
5
|
require "pathname"
|
|
6
6
|
require "uuidtools"
|
|
7
7
|
|
|
8
|
+
module Nokogiri
|
|
9
|
+
module XML
|
|
10
|
+
class Builder
|
|
11
|
+
class NodeBuilder
|
|
12
|
+
def add_noko_elem(name, val, attrs = {})
|
|
13
|
+
val and !val.empty? or return
|
|
14
|
+
# require "debug"; binding.b
|
|
15
|
+
send name, **Metanorma::Utils::attr_code(attrs) do |n|
|
|
16
|
+
n << val
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
8
24
|
module Metanorma
|
|
9
25
|
module Standoc
|
|
10
26
|
module Utils
|
|
@@ -44,9 +60,10 @@ module Metanorma
|
|
|
44
60
|
end
|
|
45
61
|
|
|
46
62
|
def csv_split(text, delim = ";", encode: true)
|
|
63
|
+
text ||= ""
|
|
47
64
|
ret = Metanorma::Utils::csv_split(@c.decode(text), delim)
|
|
48
65
|
encode and
|
|
49
|
-
ret.map! { |x| @c.encode(x, :basic, :hexadecimal) }
|
|
66
|
+
ret.map! { |x| @c.encode(x.strip, :basic, :hexadecimal) }
|
|
50
67
|
ret
|
|
51
68
|
end
|
|
52
69
|
|
|
@@ -155,7 +172,8 @@ module Metanorma
|
|
|
155
172
|
|
|
156
173
|
#{text}
|
|
157
174
|
ADOC
|
|
158
|
-
c = isolated_asciidoctor_convert(doc, backend: flavour,
|
|
175
|
+
c = isolated_asciidoctor_convert(doc, backend: flavour,
|
|
176
|
+
header_footer: true)
|
|
159
177
|
ret = Nokogiri::XML(c).at("//xmlns:sections")
|
|
160
178
|
separate_numbering_footnotes(ret)
|
|
161
179
|
end
|
|
@@ -192,6 +210,13 @@ module Metanorma
|
|
|
192
210
|
@refids.include? ref
|
|
193
211
|
end
|
|
194
212
|
|
|
213
|
+
def add_noko_elem(node, name, val, attrs = {})
|
|
214
|
+
val and !val.empty? or return
|
|
215
|
+
node.send name, **attr_code(attrs) do |n|
|
|
216
|
+
n << val
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
195
220
|
module_function :adoc2xml
|
|
196
221
|
|
|
197
222
|
class EmptyAttr
|
|
@@ -94,6 +94,7 @@ module Metanorma
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
def validate(doc)
|
|
97
|
+
@log.add_error_ranges(doc)
|
|
97
98
|
content_validate(doc)
|
|
98
99
|
schema_validate(formattedstr_strip(doc.dup), schema_location)
|
|
99
100
|
end
|
|
@@ -212,6 +213,7 @@ module Metanorma
|
|
|
212
213
|
end
|
|
213
214
|
|
|
214
215
|
def empty_block?(block)
|
|
216
|
+
block.nil? and return
|
|
215
217
|
content = block.children.reject { |n| n.name == "name" }
|
|
216
218
|
content.map do |n|
|
|
217
219
|
%w(image xref eref).include?(n.name) ? n.name : n
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "pngcheck"
|
|
2
|
+
require "svg_conform"
|
|
2
3
|
|
|
3
4
|
module Metanorma
|
|
4
5
|
module Standoc
|
|
@@ -7,6 +8,7 @@ module Metanorma
|
|
|
7
8
|
image_exists(doc)
|
|
8
9
|
image_toobig(doc)
|
|
9
10
|
png_validate(doc)
|
|
11
|
+
svg_validate(doc)
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
def image_exists(doc)
|
|
@@ -51,6 +53,53 @@ module Metanorma
|
|
|
51
53
|
@log.add("STANDOC_46", i.parent)
|
|
52
54
|
end
|
|
53
55
|
end
|
|
56
|
+
|
|
57
|
+
def svg_validate(doc)
|
|
58
|
+
profile = SvgConform::Profiles.get(@svg_conform_profile)
|
|
59
|
+
remediatable = profile.remediation_count.positive?
|
|
60
|
+
engine = SvgConform::RemediationEngine.new(profile)
|
|
61
|
+
doc.xpath("//m:svg", "m" => SVG_NS).each do |s|
|
|
62
|
+
d, result = svg_validate1(profile, s)
|
|
63
|
+
remediatable && !result.valid? and
|
|
64
|
+
svg_validate_fix(profile, engine, d, s, result)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def svg_validate1(profile, svg)
|
|
69
|
+
d = SvgConform::Document.from_content(svg.to_xml)
|
|
70
|
+
r = profile.validate(d)
|
|
71
|
+
svg_error("STANDOC_55", svg, r.errors)
|
|
72
|
+
svg_error("STANDOC_57", svg, r.warnings)
|
|
73
|
+
[d, r]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def svg_validate_fix(profile, engine, doc, svg, result)
|
|
77
|
+
remeds = engine.apply_remediations(doc, result)
|
|
78
|
+
svg_remed_log(remeds, svg)
|
|
79
|
+
result = profile.validate(doc)
|
|
80
|
+
svg_error("STANDOC_56", svg, result.errors) # we still have errors
|
|
81
|
+
svg.replace(doc.to_xml)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def svg_remed_log(remeds, svg)
|
|
85
|
+
remeds.each do |e|
|
|
86
|
+
e.changes_made.each do |c|
|
|
87
|
+
@log.add("STANDOC_58", svg,
|
|
88
|
+
params: [e.remediation_id, e.message,
|
|
89
|
+
c[:type], c[:message], c[:node]])
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def svg_error(id, svg, errors)
|
|
95
|
+
errors.each do |err|
|
|
96
|
+
err.respond_to?(:element) && err.element and
|
|
97
|
+
elem = " Element: #{err.element}"
|
|
98
|
+
err.respond_to?(:location) && err.location and
|
|
99
|
+
loc = " Location: #{err.location}"
|
|
100
|
+
@log.add(id, svg, params: [err.rule&.id, err.message, elem, loc])
|
|
101
|
+
end
|
|
102
|
+
end
|
|
54
103
|
end
|
|
55
104
|
end
|
|
56
105
|
end
|
data/metanorma-standoc.gemspec
CHANGED
|
@@ -37,18 +37,21 @@ Gem::Specification.new do |spec|
|
|
|
37
37
|
spec.add_dependency "metanorma-plugin-glossarist", "~> 0.2.3"
|
|
38
38
|
spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7.31"
|
|
39
39
|
spec.add_dependency "metanorma-plugin-plantuml", "~> 1.0.0"
|
|
40
|
-
spec.add_dependency "metanorma-utils", "~> 2.0.
|
|
40
|
+
spec.add_dependency "metanorma-utils", "~> 2.0.1"
|
|
41
41
|
spec.add_dependency "ruby-jing"
|
|
42
42
|
# relaton-cli not just relaton, to avoid circular reference in metanorma
|
|
43
43
|
spec.add_dependency "concurrent-ruby"
|
|
44
44
|
spec.add_dependency "pngcheck"
|
|
45
45
|
spec.add_dependency "relaton-cli", "~> 1.20.0"
|
|
46
46
|
spec.add_dependency "relaton-iev", "~> 1.2.0"
|
|
47
|
+
spec.add_dependency "svg_conform", "~> 0.1.0"
|
|
47
48
|
|
|
49
|
+
spec.add_development_dependency "canon", "= 0.1.3"
|
|
48
50
|
spec.add_development_dependency "debug"
|
|
49
51
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
|
50
52
|
spec.add_development_dependency "guard", "~> 2.14"
|
|
51
53
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
|
54
|
+
spec.add_development_dependency "openssl"
|
|
52
55
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
53
56
|
spec.add_development_dependency "rspec", "~> 3.6"
|
|
54
57
|
spec.add_development_dependency "rubocop", "~> 1"
|
|
@@ -58,7 +61,5 @@ Gem::Specification.new do |spec|
|
|
|
58
61
|
spec.add_development_dependency "timecop", "~> 0.9"
|
|
59
62
|
spec.add_development_dependency "vcr", "~> 6.1.0"
|
|
60
63
|
spec.add_development_dependency "webmock"
|
|
61
|
-
spec.add_development_dependency "openssl"
|
|
62
|
-
spec.add_development_dependency "canon", "= 0.1.3"
|
|
63
64
|
# spec.metadata["rubygems_mfa_required"] = "true"
|
|
64
65
|
end
|