metanorma-standoc 3.5.12 → 3.5.14
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/cleanup/block.rb +44 -0
- data/lib/metanorma/converter/init.rb +2 -7
- data/lib/metanorma/converter/log.rb +5 -0
- data/lib/metanorma/standoc/conform_profiles.rb +100 -0
- data/lib/metanorma/standoc/png_conform_profile/metanorma.yml +13 -0
- data/lib/metanorma/standoc/svg_conform_profile/metanorma.yml +227 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/lib/metanorma/validate/image.rb +65 -2
- data/lib/metanorma/validate/validate.rb +8 -0
- data/metanorma-standoc.gemspec +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3caf54010e6116c8d38d202cf3b9eb00440e094ec25faa04c056ea94f842c3da
|
|
4
|
+
data.tar.gz: 28d6080fc9081d4a63d474d0675d26147ed8cb196d16e94f28345301577070f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de213d71c0c0043e001ea1ee30f746a028241e2ec4a5cd1288aa99df7e5370bc5d8460cf40b4e1499c2e9f9916660090fc9f36ec848e8859264da0a177fa2fc7
|
|
7
|
+
data.tar.gz: b4a4913e12b87b8abff891fb40801a4bd1d1238c6fb2f373d76537f80ca0d5d48e9733a56bd1368d2cda2023b9d0a844ff4f9f6ab8f25fc6a2842ac01a9313d7
|
|
@@ -277,6 +277,50 @@ module Metanorma
|
|
|
277
277
|
x.delete("explicit-type")
|
|
278
278
|
@log.add("STANDOC_14", x, display: false)
|
|
279
279
|
end
|
|
280
|
+
merge_adjacent_lists(doc)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# A line comment or a conditional directive flanked by blank lines
|
|
284
|
+
# ends an AsciiDoc list: the comment is dropped, and the blank lines
|
|
285
|
+
# leave adjacent same-type lists with nothing between them. The
|
|
286
|
+
# rendered artifact restarts list numbering at the second fragment,
|
|
287
|
+
# and downstream clause checks (one list per clause, list preceded
|
|
288
|
+
# by colon or full stop) fire on the fragments. Merge the fragments:
|
|
289
|
+
# explicit restarts (start attributes), anchored lists and
|
|
290
|
+
# differently typed ordered lists are left alone.
|
|
291
|
+
def merge_adjacent_lists(doc)
|
|
292
|
+
loop do
|
|
293
|
+
merged = false
|
|
294
|
+
doc.xpath("//ol | //ul").each do |list|
|
|
295
|
+
nxt = list.next_element
|
|
296
|
+
next unless mergeable_lists?(list, nxt)
|
|
297
|
+
|
|
298
|
+
nxt.children.each { |c| list << c }
|
|
299
|
+
nxt.remove
|
|
300
|
+
@log.add("STANDOC_67", list, display: false)
|
|
301
|
+
merged = true
|
|
302
|
+
end
|
|
303
|
+
break unless merged
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def mergeable_lists?(list, nxt)
|
|
308
|
+
!list.parent.nil? && !nxt.nil? && nxt.name == list.name &&
|
|
309
|
+
mergeable_types?(list, nxt) && mergeable_attrs?(nxt)
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
def mergeable_types?(list, nxt)
|
|
313
|
+
list.name == "ul" ||
|
|
314
|
+
(list["type"] || "arabic") == (nxt["type"] || "arabic")
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# The first fragment keeps its identity through the merge. The
|
|
318
|
+
# second must not carry a restart (start) or a user anchor: every
|
|
319
|
+
# block gets a generated id (underscore-prefixed), those are fine
|
|
320
|
+
# to drop.
|
|
321
|
+
def mergeable_attrs?(list)
|
|
322
|
+
list["start"].nil? &&
|
|
323
|
+
(list["id"].nil? || list["id"].start_with?("_"))
|
|
280
324
|
end
|
|
281
325
|
|
|
282
326
|
def blocksource_cleanup(xmldoc)
|
|
@@ -108,13 +108,8 @@ module Metanorma
|
|
|
108
108
|
@datauriimage = node.attr("data-uri-image") != "false"
|
|
109
109
|
@datauriattachment = node.attr("data-uri-attachment") != "false"
|
|
110
110
|
@dataurimaxsize = node.attr("data-uri-maxsize")&.to_i || 13981013
|
|
111
|
-
@svg_conform_profile =
|
|
112
|
-
|
|
113
|
-
default_svg_conform_profile
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def default_svg_conform_profile
|
|
117
|
-
:metanorma
|
|
111
|
+
@svg_conform_profile = node.attr("svg-conform-profile")
|
|
112
|
+
@png_conform_profile = node.attr("png-conform-profile")
|
|
118
113
|
end
|
|
119
114
|
|
|
120
115
|
def init_reqt(node)
|
|
@@ -205,6 +205,11 @@ module Metanorma
|
|
|
205
205
|
error: "Could not fetch the authoritative logo for " \
|
|
206
206
|
"organization %s: %s",
|
|
207
207
|
severity: 2 },
|
|
208
|
+
STANDOC_67: { category: "AsciiDoc Input",
|
|
209
|
+
error: "Adjacent lists of the same type merged: a " \
|
|
210
|
+
"blank-line-flanked comment or conditional " \
|
|
211
|
+
"directive had ended the first list",
|
|
212
|
+
severity: 2 },
|
|
208
213
|
RELATON_1: { category: "Relaton",
|
|
209
214
|
error: "(Error from Relaton) %s",
|
|
210
215
|
severity: 0 },
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Metanorma
|
|
4
|
+
module Standoc
|
|
5
|
+
# The Metanorma conformance-profile registry — one resolution engine
|
|
6
|
+
# for every image-conformance type (svg_conform today, png_conform
|
|
7
|
+
# when it exposes profile selection on its service path, and any
|
|
8
|
+
# future engine).
|
|
9
|
+
#
|
|
10
|
+
# MECE partition:
|
|
11
|
+
# - Registry (here): resolution semantics only — reserved words
|
|
12
|
+
# (none/off/disabled), the owned "metanorma" default, scoped names
|
|
13
|
+
# (flavor dir, then standoc dir), the engine-prefix opt-in
|
|
14
|
+
# ("svg:<name>" / "png:<name>"), direct path loads, error messages.
|
|
15
|
+
# - Engine adapters (per-type methods on Standoc::Validate): loading
|
|
16
|
+
# through each engine's own API.
|
|
17
|
+
# - Flavors: their profile files — one directory per type
|
|
18
|
+
# (lib/metanorma/<flavor>/<type>_conform_profile/), addressable by
|
|
19
|
+
# bare name; flavors override +conform_profile_dir+.
|
|
20
|
+
# - Documents: selection via the <type>-conform-profile attribute.
|
|
21
|
+
module ConformProfiles
|
|
22
|
+
RESERVED_DISABLE = %w(none off disabled).freeze
|
|
23
|
+
RESERVED_DEFAULT = "metanorma"
|
|
24
|
+
|
|
25
|
+
class NotFound < StandardError; end
|
|
26
|
+
|
|
27
|
+
# A per-type registry bound to its directories and engine prefix.
|
|
28
|
+
class Registry
|
|
29
|
+
def initialize(type:, standoc_dir:, flavor_dir: nil)
|
|
30
|
+
@type = type.to_s
|
|
31
|
+
@standoc_dir = standoc_dir
|
|
32
|
+
@flavor_dir = flavor_dir
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [[:disabled], [:file, String], [:engine, String]]
|
|
36
|
+
def resolve(value)
|
|
37
|
+
value = value&.strip
|
|
38
|
+
return [[:file], default_file].flatten if value.nil? || value.empty?
|
|
39
|
+
return [:disabled] if disabled?(value)
|
|
40
|
+
return [:engine, engine_name(value)] if engine_qualified?(value)
|
|
41
|
+
|
|
42
|
+
file = named_file(@flavor_dir, value) ||
|
|
43
|
+
named_file(@standoc_dir, value) || path_file(value)
|
|
44
|
+
raise NotFound, unknown_message(value) unless file
|
|
45
|
+
|
|
46
|
+
[:file, file]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def default_file
|
|
50
|
+
file = named_file(@flavor_dir, RESERVED_DEFAULT) ||
|
|
51
|
+
named_file(@standoc_dir, RESERVED_DEFAULT)
|
|
52
|
+
raise NotFound, "the owned #{RESERVED_DEFAULT}.yml baseline " \
|
|
53
|
+
"is missing from #{@standoc_dir}" unless file
|
|
54
|
+
|
|
55
|
+
file
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def disabled?(value)
|
|
59
|
+
RESERVED_DISABLE.include?(value.downcase)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def engine_qualified?(value)
|
|
63
|
+
value.start_with?("#{@type}:")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def engine_name(value)
|
|
67
|
+
value.delete_prefix("#{@type}:")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def named_file(dir, name)
|
|
71
|
+
return nil if dir.nil?
|
|
72
|
+
|
|
73
|
+
path = File.join(dir, "#{name}.yml")
|
|
74
|
+
File.exist?(path) ? path : nil
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def path_file(value)
|
|
78
|
+
return nil unless value.end_with?(".yml") || value.include?("/")
|
|
79
|
+
|
|
80
|
+
File.exist?(value) ? value : nil
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def unknown_message(value)
|
|
84
|
+
"unknown #{@type}-conform-profile #{value.inspect}; available: " \
|
|
85
|
+
"#{RESERVED_DISABLE.join(', ')} (disable validation), " \
|
|
86
|
+
"#{available_names.join(', ')}, a .yml path, or " \
|
|
87
|
+
"'#{@type}:<name>' for a #{@type}_conform gem profile"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def available_names
|
|
91
|
+
[@flavor_dir, @standoc_dir].flat_map do |dir|
|
|
92
|
+
next [] if dir.nil?
|
|
93
|
+
|
|
94
|
+
Dir.glob(File.join(dir, "*.yml")).map { |f| File.basename(f, ".yml") }
|
|
95
|
+
end.uniq.sort
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# The Metanorma-owned baseline PNG validation profile. Owned here so
|
|
2
|
+
# png_conform's bundled samples never dictate document policy; the
|
|
3
|
+
# field shape mirrors png_conform's validation_profiles.yml (the engine
|
|
4
|
+
# honours this file once profile selection lands on the service path,
|
|
5
|
+
# claricle/png_conform#34).
|
|
6
|
+
name: "Metanorma baseline"
|
|
7
|
+
description: "PNG requirements for Metanorma documents"
|
|
8
|
+
required_chunks:
|
|
9
|
+
- IHDR
|
|
10
|
+
- IDAT
|
|
11
|
+
- IEND
|
|
12
|
+
optional_chunks: "*"
|
|
13
|
+
prohibited_chunks: []
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
name: "metanorma"
|
|
2
|
+
description: "Metanorma SVG Profile - SVG requirements for Metanorma technical documents with embedded resources"
|
|
3
|
+
|
|
4
|
+
requirements:
|
|
5
|
+
# ID Collection - must run first to build the ID manifest
|
|
6
|
+
- id: "id_collection"
|
|
7
|
+
type: "IdCollectionRequirement"
|
|
8
|
+
description: "Collects all ID definitions for reference validation"
|
|
9
|
+
|
|
10
|
+
# Based on RFC 7996 Section 2.1: Elements, Properties, and Attributes
|
|
11
|
+
- id: "allowed_elements"
|
|
12
|
+
type: "AllowedElementsRequirement"
|
|
13
|
+
description: "Validates allowed SVG elements and attributes"
|
|
14
|
+
skip_foreign_namespaces: true
|
|
15
|
+
allow_rdf_metadata: false
|
|
16
|
+
allowed_namespaces:
|
|
17
|
+
- "http://www.w3.org/2000/svg"
|
|
18
|
+
- "" # Default namespace (no prefix)
|
|
19
|
+
allowed_attribute_patterns:
|
|
20
|
+
- "on*" # Allow event handler attributes (onmouseover, onmouseout, etc.) per issue #57
|
|
21
|
+
element_configs:
|
|
22
|
+
# Direct encoding from svgcheck word_properties.py elements dictionary
|
|
23
|
+
- tag: "svg"
|
|
24
|
+
attributes: ["version", "baseProfile", "width", "viewBox", "preserveAspectRatio", "snapshotTime", "height", "id", "role", "break", "color-rendering", "fill-rule", "overflow", "data-name", "clip-path", "mask", "contentStyleType", "zoomAndPan"]
|
|
25
|
+
required_attributes: ["version", "baseProfile"]
|
|
26
|
+
attribute_values:
|
|
27
|
+
version: ["1.2"]
|
|
28
|
+
baseProfile: ["tiny"]
|
|
29
|
+
allowed_children: ["title", "path", "rect", "circle", "line", "ellipse", "polyline", "polygon", "solidColor", "textArea", "text", "g", "defs", "use", "a", "tspan", "desc", "image", "style"]
|
|
30
|
+
- tag: "desc"
|
|
31
|
+
attributes: ["id", "role", "shape-rendering", "text-rendering", "buffered-rendering", "visibility", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "fill-rule"]
|
|
32
|
+
allowed_children: ["text"]
|
|
33
|
+
- tag: "title"
|
|
34
|
+
attributes: ["id", "role", "shape-rendering", "text-rendering", "buffered-rendering", "visibility", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "fill-rule"]
|
|
35
|
+
allowed_children: ["text"]
|
|
36
|
+
- tag: "path"
|
|
37
|
+
attributes: ["d", "pathLength", "stroke-miterlimit", "id", "role", "fill", "style", "transform", "font-size", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
38
|
+
allowed_children: ["title", "desc"]
|
|
39
|
+
- tag: "rect"
|
|
40
|
+
attributes: ["x", "y", "width", "height", "rx", "ry", "stroke-miterlimit", "id", "role", "fill", "style", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
41
|
+
allowed_children: ["title", "desc"]
|
|
42
|
+
- tag: "circle"
|
|
43
|
+
attributes: ["cx", "cy", "r", "id", "role", "fill", "style", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
44
|
+
allowed_children: ["title", "desc"]
|
|
45
|
+
- tag: "line"
|
|
46
|
+
attributes: ["x1", "y1", "x2", "y2", "id", "role", "fill", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
47
|
+
allowed_children: ["title", "desc"]
|
|
48
|
+
- tag: "ellipse"
|
|
49
|
+
attributes: ["cx", "cy", "rx", "ry", "id", "role", "fill", "style", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
50
|
+
allowed_children: ["title", "desc"]
|
|
51
|
+
- tag: "polyline"
|
|
52
|
+
attributes: ["points", "id", "role", "fill", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
53
|
+
allowed_children: ["title", "desc"]
|
|
54
|
+
- tag: "polygon"
|
|
55
|
+
attributes: ["points", "id", "role", "fill", "style", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
56
|
+
allowed_children: ["title", "desc"]
|
|
57
|
+
- tag: "solidColor"
|
|
58
|
+
attributes: ["id", "role", "fill", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
59
|
+
allowed_children: ["title", "desc"]
|
|
60
|
+
- tag: "textArea"
|
|
61
|
+
attributes: ["x", "y", "width", "height", "auto", "id", "role", "fill", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
62
|
+
allowed_children: ["desc", "title", "tspan", "text", "a"]
|
|
63
|
+
- tag: "text"
|
|
64
|
+
attributes: ["x", "y", "rotate", "id", "role", "fill", "style", "transform", "font-size", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "font-stretch", "writing-mode", "text-decoration", "clip-path", "mask", "textLength", "lengthAdjust", "opacity"]
|
|
65
|
+
allowed_children: ["desc", "title", "tspan", "text", "a"]
|
|
66
|
+
- tag: "g"
|
|
67
|
+
attributes: ["label", "class", "id", "role", "fill", "style", "transform", "fill-rule", "visibility", "base", "lang", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "data-name", "clip-path", "clip-rule", "mask", "opacity"]
|
|
68
|
+
allowed_children: ["title", "path", "rect", "circle", "line", "ellipse", "polyline", "polygon", "solidColor", "textArea", "text", "g", "defs", "use", "a", "tspan", "desc", "image"]
|
|
69
|
+
- tag: "defs"
|
|
70
|
+
attributes: ["id", "role", "fill", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
71
|
+
allowed_children: ["title", "path", "rect", "circle", "line", "ellipse", "polyline", "polygon", "solidColor", "textArea", "text", "g", "defs", "use", "a", "tspan", "desc", "style", "clipPath", "linearGradient", "radialGradient", "pattern", "marker", "mask", "filter", "image"]
|
|
72
|
+
- tag: "clipPath"
|
|
73
|
+
attributes: ["id", "clipPathUnits", "class", "style"]
|
|
74
|
+
allowed_children: ["path", "rect", "circle", "ellipse", "line", "polyline", "polygon", "text", "use"]
|
|
75
|
+
- tag: "linearGradient"
|
|
76
|
+
attributes: ["id", "x1", "y1", "x2", "y2", "gradientUnits", "gradientTransform", "spreadMethod", "href", "xlink:href", "data-name"]
|
|
77
|
+
allowed_children: ["stop"]
|
|
78
|
+
- tag: "radialGradient"
|
|
79
|
+
attributes: ["id", "cx", "cy", "r", "fx", "fy", "fr", "gradientUnits", "gradientTransform", "spreadMethod", "href", "xlink:href", "data-name"]
|
|
80
|
+
allowed_children: ["stop"]
|
|
81
|
+
- tag: "stop"
|
|
82
|
+
attributes: ["offset", "stop-color", "stop-opacity", "style", "class", "id"]
|
|
83
|
+
allowed_children: []
|
|
84
|
+
- tag: "pattern"
|
|
85
|
+
attributes: ["id", "x", "y", "width", "height", "patternUnits", "patternContentUnits", "patternTransform", "viewBox", "preserveAspectRatio", "href", "xlink:href"]
|
|
86
|
+
allowed_children: ["path", "rect", "circle", "ellipse", "line", "polyline", "polygon", "text", "g", "use", "image"]
|
|
87
|
+
- tag: "marker"
|
|
88
|
+
attributes: ["id", "markerUnits", "refX", "refY", "markerWidth", "markerHeight", "orient", "preserveAspectRatio", "viewBox"]
|
|
89
|
+
allowed_children: ["path", "rect", "circle", "ellipse", "line", "polyline", "polygon", "text", "g"]
|
|
90
|
+
- tag: "mask"
|
|
91
|
+
attributes: ["id", "x", "y", "width", "height", "maskUnits", "maskContentUnits"]
|
|
92
|
+
allowed_children: ["path", "rect", "circle", "ellipse", "line", "polyline", "polygon", "text", "g", "use", "image"]
|
|
93
|
+
- tag: "filter"
|
|
94
|
+
attributes: ["id", "x", "y", "width", "height", "filterUnits", "primitiveUnits"]
|
|
95
|
+
allowed_children: []
|
|
96
|
+
- tag: "style"
|
|
97
|
+
attributes: ["type", "media", "title", "id", "class"]
|
|
98
|
+
allowed_children: []
|
|
99
|
+
- tag: "use"
|
|
100
|
+
attributes: ["x", "y", "href", "xlink:href", "id", "role", "fill", "transform", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "clip-path", "mask"]
|
|
101
|
+
allowed_children: ["title", "desc"]
|
|
102
|
+
- tag: "a"
|
|
103
|
+
attributes: ["id", "role", "fill", "transform", "fill-rule", "target", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "title", "clip-path", "mask"]
|
|
104
|
+
allowed_children: ["title", "path", "rect", "circle", "line", "ellipse", "polyline", "polygon", "solidColor", "textArea", "text", "g", "defs", "use", "a", "tspan", "desc"]
|
|
105
|
+
- tag: "tspan"
|
|
106
|
+
attributes: ["x", "y", "id", "role", "fill", "fill-rule", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space", "letter-spacing"]
|
|
107
|
+
allowed_children: ["desc", "title", "tspan", "text", "a", "tbreak"]
|
|
108
|
+
- tag: "tbreak"
|
|
109
|
+
attributes: ["id", "role", "base", "lang", "class", "rel", "rev", "typeof", "content", "datatype", "resource", "about", "property", "space"]
|
|
110
|
+
- tag: "image"
|
|
111
|
+
attributes: ["x", "y", "width", "height", "href", "xlink:href", "preserveAspectRatio", "id", "class", "style", "transform", "clip-path", "mask"]
|
|
112
|
+
allowed_children: ["title", "desc"]
|
|
113
|
+
check_attributes: true
|
|
114
|
+
check_invalid_attributes: true
|
|
115
|
+
check_parent_child: true
|
|
116
|
+
|
|
117
|
+
# Namespace restrictions - only SVG namespace allowed
|
|
118
|
+
- id: "namespace_validation"
|
|
119
|
+
type: "NamespaceRequirement"
|
|
120
|
+
description: "Only allows SVG namespace elements"
|
|
121
|
+
allow_rdf_metadata: false
|
|
122
|
+
allowed_namespaces:
|
|
123
|
+
- "http://www.w3.org/2000/svg"
|
|
124
|
+
- "" # Default namespace (no prefix)
|
|
125
|
+
|
|
126
|
+
# Namespace attribute restrictions - only SVG, XLink, and XML namespaces allowed
|
|
127
|
+
- id: "namespace_attributes"
|
|
128
|
+
type: "NamespaceAttributesRequirement"
|
|
129
|
+
description: "Only allows attributes from SVG, XLink, and XML namespaces"
|
|
130
|
+
allowed_namespaces:
|
|
131
|
+
- "http://www.w3.org/2000/svg"
|
|
132
|
+
- "http://www.w3.org/1999/xlink"
|
|
133
|
+
- "http://www.w3.org/XML/1998/namespace" # XML namespace (xml:space, xml:lang, etc.)
|
|
134
|
+
- "" # Default namespace (no prefix)
|
|
135
|
+
exempt_elements:
|
|
136
|
+
- "RDF"
|
|
137
|
+
- "Work"
|
|
138
|
+
- "format"
|
|
139
|
+
- "type"
|
|
140
|
+
- "title"
|
|
141
|
+
- "creator"
|
|
142
|
+
- "description"
|
|
143
|
+
|
|
144
|
+
# ViewBox required on root SVG element
|
|
145
|
+
- id: "viewbox_required"
|
|
146
|
+
type: "ViewboxRequiredRequirement"
|
|
147
|
+
description: "Requires viewBox attribute on root SVG element"
|
|
148
|
+
|
|
149
|
+
# Link validation - IRIs must be ASCII only
|
|
150
|
+
- id: "link_validation"
|
|
151
|
+
type: "LinkValidationRequirement"
|
|
152
|
+
description: "Validates links are ASCII-only"
|
|
153
|
+
error_context: "Metanorma requires ASCII-only IRIs"
|
|
154
|
+
|
|
155
|
+
# ID reference validation
|
|
156
|
+
- id: "id_references"
|
|
157
|
+
type: "IdReferenceRequirement"
|
|
158
|
+
description: "Validates ID references point to existing elements"
|
|
159
|
+
|
|
160
|
+
# Forbidden content - no multimedia, scripting, etc.
|
|
161
|
+
# Note: onmouseover, onmouseout, onfocus, onblur are intentionally allowed per issue #57
|
|
162
|
+
- id: "forbidden_content"
|
|
163
|
+
type: "ForbiddenContentRequirement"
|
|
164
|
+
description: "Prohibits multimedia, scripting content"
|
|
165
|
+
forbidden_elements: ["script", "audio", "video", "set"]
|
|
166
|
+
forbidden_attributes: ["onload", "onclick", "onkeydown", "onkeyup", "onkeypress"]
|
|
167
|
+
|
|
168
|
+
# NEW: No external CSS - reject without remediation
|
|
169
|
+
- id: "no_external_css"
|
|
170
|
+
type: "NoExternalCssRequirement"
|
|
171
|
+
description: "Prohibits external CSS references - all styles must be embedded"
|
|
172
|
+
check_style_elements: true
|
|
173
|
+
check_style_attributes: true
|
|
174
|
+
check_link_elements: true
|
|
175
|
+
|
|
176
|
+
# NEW: No external fonts - detect and require embedding
|
|
177
|
+
- id: "no_external_fonts"
|
|
178
|
+
type: "NoExternalFontsRequirement"
|
|
179
|
+
description: "Prohibits external font references - all fonts must be embedded"
|
|
180
|
+
check_font_face: true
|
|
181
|
+
check_style_fonts: true
|
|
182
|
+
|
|
183
|
+
# NEW: No external images - detect and require embedding
|
|
184
|
+
- id: "no_external_images"
|
|
185
|
+
type: "NoExternalImagesRequirement"
|
|
186
|
+
description: "Prohibits external image references - all images must be embedded"
|
|
187
|
+
check_image_elements: true
|
|
188
|
+
check_style_images: true
|
|
189
|
+
|
|
190
|
+
# Text-as-path detection - warns when text is rendered as outlined paths
|
|
191
|
+
- id: "text_as_path"
|
|
192
|
+
type: "TextAsPathRequirement"
|
|
193
|
+
description: "Detects text rendered as outlined paths instead of native <text> elements"
|
|
194
|
+
min_d_length: 500
|
|
195
|
+
min_bezier: 5
|
|
196
|
+
|
|
197
|
+
remediations:
|
|
198
|
+
# ViewBox auto-generation
|
|
199
|
+
- id: "viewbox_generation"
|
|
200
|
+
type: "ViewboxRemediation"
|
|
201
|
+
description: "Auto-generate viewBox from width/height"
|
|
202
|
+
targets: ["viewbox_required"]
|
|
203
|
+
|
|
204
|
+
# Namespace cleanup - removes foreign elements, attributes, and declarations
|
|
205
|
+
- id: "namespace_cleanup"
|
|
206
|
+
type: "NamespaceRemediation"
|
|
207
|
+
description: "Remove foreign namespace elements (Inkscape, Sodipodi, etc.), attributes, and declarations"
|
|
208
|
+
targets: ["namespace_validation", "namespace_attributes"]
|
|
209
|
+
allowed_namespaces:
|
|
210
|
+
- "http://www.w3.org/2000/svg"
|
|
211
|
+
- "http://www.w3.org/1999/xlink"
|
|
212
|
+
- "http://www.w3.org/XML/1998/namespace"
|
|
213
|
+
remove_elements: true
|
|
214
|
+
remove_attributes: true
|
|
215
|
+
remove_declarations: true
|
|
216
|
+
|
|
217
|
+
# NEW: Font embedding remediation
|
|
218
|
+
- id: "font_embedding"
|
|
219
|
+
type: "FontEmbeddingRemediation"
|
|
220
|
+
description: "Convert external font references to embedded fonts"
|
|
221
|
+
targets: ["no_external_fonts"]
|
|
222
|
+
|
|
223
|
+
# NEW: Image embedding remediation
|
|
224
|
+
- id: "image_embedding"
|
|
225
|
+
type: "ImageEmbeddingRemediation"
|
|
226
|
+
description: "Convert external image references to embedded images"
|
|
227
|
+
targets: ["no_external_images"]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "svg_conform"
|
|
2
2
|
require "png_conform"
|
|
3
|
+
require "metanorma/standoc/conform_profiles"
|
|
3
4
|
|
|
4
5
|
module Metanorma
|
|
5
6
|
module Standoc
|
|
@@ -30,14 +31,75 @@ module Metanorma
|
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
|
|
34
|
+
# Metanorma owns the operative profiles; the engines' bundled
|
|
35
|
+
# samples are reachable only through the explicit "svg:"/"png:"
|
|
36
|
+
# prefix (see ConformProfiles). Resolution: the
|
|
37
|
+
# <type>-conform-profile document attribute, then the flavor's
|
|
38
|
+
# shipped profile directory (conform_profile_dir, overridable per
|
|
39
|
+
# flavor), then the standoc default; "none" disables that type's
|
|
40
|
+
# validation for the document.
|
|
41
|
+
def svg_conform_profile
|
|
42
|
+
kind, value = conform_profile_resolution(:svg)
|
|
43
|
+
case kind
|
|
44
|
+
when :disabled then nil
|
|
45
|
+
when :engine then SvgConform::Profiles.get(value)
|
|
46
|
+
when :file then SvgConform::Profile.load_from_file(value)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The PNG mirror: returns :disabled (validation skipped), or a
|
|
51
|
+
# descriptor passed to the engine through the service options.
|
|
52
|
+
# png_conform 0.1.5 does not yet read profile selection from
|
|
53
|
+
# options (claricle/png_conform#34); the descriptor is inert
|
|
54
|
+
# until it does.
|
|
55
|
+
def png_conform_profile
|
|
56
|
+
kind, value = conform_profile_resolution(:png)
|
|
57
|
+
case kind
|
|
58
|
+
when :disabled then :disabled
|
|
59
|
+
when :engine then { engine_profile: value }
|
|
60
|
+
else { profile_file: value }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def conform_profile_resolution(type)
|
|
65
|
+
registry = ConformProfiles::Registry.new(
|
|
66
|
+
type: type,
|
|
67
|
+
standoc_dir: conform_profile_dir(type, own: false),
|
|
68
|
+
flavor_dir: conform_profile_dir(type, own: true),
|
|
69
|
+
)
|
|
70
|
+
registry.resolve(
|
|
71
|
+
instance_variable_get("@#{type}_conform_profile")
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# The flavor seam: flavors define their own requirements
|
|
76
|
+
# collections by shipping a directory per type
|
|
77
|
+
# (lib/metanorma/<flavor>/<type>_conform_profile/) — overridable
|
|
78
|
+
# per type for nonstandard locations.
|
|
79
|
+
def conform_profile_dir(type, own: true)
|
|
80
|
+
if own
|
|
81
|
+
base = Gem::Specification.find_by_name(
|
|
82
|
+
"metanorma-#{validation_flavor}"
|
|
83
|
+
)
|
|
84
|
+
return File.join(base.gem_dir, "lib", "metanorma",
|
|
85
|
+
validation_flavor, "#{type}_conform_profile")
|
|
86
|
+
end
|
|
87
|
+
File.expand_path("../standoc/#{type}_conform_profile", __dir__)
|
|
88
|
+
rescue Gem::LoadError
|
|
89
|
+
File.expand_path("../standoc/#{type}_conform_profile", __dir__)
|
|
90
|
+
end
|
|
91
|
+
|
|
33
92
|
def png_validate(doc)
|
|
93
|
+
return if png_conform_profile == :disabled
|
|
34
94
|
doc.xpath("//image[@mimetype = 'image/png'][@src]").each do |i|
|
|
35
95
|
Vectory::Utils::url?(i["src"]) and next
|
|
36
96
|
uri = Vectory::Utils::datauri?(i["src"])
|
|
37
97
|
path = uri ? save_dataimage(i["src"]) : expand_path(i["src"])
|
|
38
98
|
path or next
|
|
39
99
|
PngConform::Readers::StreamingReader.open(path) do |reader|
|
|
40
|
-
v = PngConform::Services::ValidationService.new(
|
|
100
|
+
v = PngConform::Services::ValidationService.new(
|
|
101
|
+
reader, path, { profile: @png_conform_profile }
|
|
102
|
+
)
|
|
41
103
|
png_validate1(i, path, v)
|
|
42
104
|
end
|
|
43
105
|
end
|
|
@@ -63,7 +125,8 @@ module Metanorma
|
|
|
63
125
|
|
|
64
126
|
# Use SAX for fast validation
|
|
65
127
|
def svg_validate(doc)
|
|
66
|
-
profile =
|
|
128
|
+
profile = svg_conform_profile
|
|
129
|
+
profile.nil? and return
|
|
67
130
|
validator = SvgConform::Validator.new(mode: :sax)
|
|
68
131
|
engine = SvgConform::RemediationEngine.new(profile)
|
|
69
132
|
@svg_remediation_cache = {}
|
|
@@ -12,6 +12,14 @@ module Metanorma
|
|
|
12
12
|
class Validate
|
|
13
13
|
extend Forwardable
|
|
14
14
|
|
|
15
|
+
# The flavor identity of this validator; flavors override
|
|
16
|
+
# (metanorma-iso "iso", metanorma-bsi "bsi"). Names the flavor's
|
|
17
|
+
# profile directories and the metanorma-<flavor> gem for the
|
|
18
|
+
# profile registry.
|
|
19
|
+
def validation_flavor
|
|
20
|
+
"standoc"
|
|
21
|
+
end
|
|
22
|
+
|
|
15
23
|
include Image
|
|
16
24
|
include Section
|
|
17
25
|
include Table
|
data/metanorma-standoc.gemspec
CHANGED
|
@@ -56,7 +56,7 @@ Gem::Specification.new do |spec|
|
|
|
56
56
|
# the corrected text-as-path severity live in the 0.2.6 line; the open
|
|
57
57
|
# ~> 0.2 floor let bundles keep 0.2.0 and reject valid SVGs
|
|
58
58
|
# (metanorma-pdfa#106).
|
|
59
|
-
spec.add_dependency "svg_conform", "~> 0.2.
|
|
59
|
+
spec.add_dependency "svg_conform", "~> 0.2.7"
|
|
60
60
|
|
|
61
61
|
# Bundled-gem successors required directly by lib code: inline.rb uses
|
|
62
62
|
# base64, macros_terms.rb and macros.rb use csv, blocks.rb uses uri.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-standoc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.5.
|
|
4
|
+
version: 3.5.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: addressable
|
|
@@ -274,14 +274,14 @@ dependencies:
|
|
|
274
274
|
requirements:
|
|
275
275
|
- - "~>"
|
|
276
276
|
- !ruby/object:Gem::Version
|
|
277
|
-
version: 0.2.
|
|
277
|
+
version: 0.2.7
|
|
278
278
|
type: :runtime
|
|
279
279
|
prerelease: false
|
|
280
280
|
version_requirements: !ruby/object:Gem::Requirement
|
|
281
281
|
requirements:
|
|
282
282
|
- - "~>"
|
|
283
283
|
- !ruby/object:Gem::Version
|
|
284
|
-
version: 0.2.
|
|
284
|
+
version: 0.2.7
|
|
285
285
|
- !ruby/object:Gem::Dependency
|
|
286
286
|
name: base64
|
|
287
287
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -613,6 +613,7 @@ files:
|
|
|
613
613
|
- lib/metanorma/converter/terms.rb
|
|
614
614
|
- lib/metanorma/converter/utils.rb
|
|
615
615
|
- lib/metanorma/standoc.rb
|
|
616
|
+
- lib/metanorma/standoc/conform_profiles.rb
|
|
616
617
|
- lib/metanorma/standoc/document.rb
|
|
617
618
|
- lib/metanorma/standoc/document/annotation_container.rb
|
|
618
619
|
- lib/metanorma/standoc/document/block_attributes.rb
|
|
@@ -772,6 +773,8 @@ files:
|
|
|
772
773
|
- lib/metanorma/standoc/document/terms/term_source_type.rb
|
|
773
774
|
- lib/metanorma/standoc/document/terms/verbal_expression.rb
|
|
774
775
|
- lib/metanorma/standoc/mirror_seed.rb
|
|
776
|
+
- lib/metanorma/standoc/png_conform_profile/metanorma.yml
|
|
777
|
+
- lib/metanorma/standoc/svg_conform_profile/metanorma.yml
|
|
775
778
|
- lib/metanorma/standoc/version.rb
|
|
776
779
|
- lib/metanorma/validate/basicdoc.rng
|
|
777
780
|
- lib/metanorma/validate/biblio-standoc.rng
|