svg_conform 0.1.4 → 0.1.5
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/.rubocop_todo.yml +182 -21
- data/README.adoc +391 -989
- data/config/profiles/metanorma.yml +5 -0
- data/docs/api_reference.adoc +1355 -0
- data/docs/cli_guide.adoc +846 -0
- data/docs/reference_manifest.adoc +370 -0
- data/docs/requirements.adoc +68 -1
- data/examples/document_input_demo.rb +102 -0
- data/lib/svg_conform/document.rb +40 -1
- data/lib/svg_conform/profile.rb +15 -9
- data/lib/svg_conform/references/base_reference.rb +130 -0
- data/lib/svg_conform/references/id_definition.rb +38 -0
- data/lib/svg_conform/references/reference_classifier.rb +45 -0
- data/lib/svg_conform/references/reference_manifest.rb +129 -0
- data/lib/svg_conform/references.rb +11 -0
- data/lib/svg_conform/remediations/namespace_attribute_remediation.rb +34 -43
- data/lib/svg_conform/requirements/id_collection_requirement.rb +38 -0
- data/lib/svg_conform/requirements/id_reference_requirement.rb +11 -0
- data/lib/svg_conform/requirements/invalid_id_references_requirement.rb +3 -0
- data/lib/svg_conform/requirements/link_validation_requirement.rb +114 -31
- data/lib/svg_conform/requirements/no_external_css_requirement.rb +5 -2
- data/lib/svg_conform/requirements.rb +11 -9
- data/lib/svg_conform/sax_validation_handler.rb +16 -1
- data/lib/svg_conform/validation_context.rb +67 -1
- data/lib/svg_conform/validation_result.rb +43 -2
- data/lib/svg_conform/validator.rb +56 -16
- data/lib/svg_conform/version.rb +1 -1
- data/lib/svg_conform.rb +11 -2
- data/spec/svg_conform/commands/svgcheck_compare_command_spec.rb +1 -0
- data/spec/svg_conform/commands/svgcheck_compatibility_command_spec.rb +1 -0
- data/spec/svg_conform/commands/svgcheck_generate_command_spec.rb +1 -0
- data/spec/svg_conform/references/integration_spec.rb +206 -0
- data/spec/svg_conform/references/reference_classifier_spec.rb +142 -0
- data/spec/svg_conform/references/reference_manifest_spec.rb +307 -0
- data/spec/svg_conform/requirements/id_reference_state_spec.rb +93 -0
- data/spec/svg_conform/validator_input_types_spec.rb +172 -0
- metadata +17 -2
data/docs/cli_guide.adoc
ADDED
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
= SvgConform CLI Guide
|
|
2
|
+
:toc: left
|
|
3
|
+
:toclevels: 3
|
|
4
|
+
:sectlinks:
|
|
5
|
+
:sectanchors:
|
|
6
|
+
:source-highlighter: rouge
|
|
7
|
+
|
|
8
|
+
== Purpose
|
|
9
|
+
|
|
10
|
+
This guide provides comprehensive documentation for the `svg_conform` command-line interface.
|
|
11
|
+
|
|
12
|
+
The CLI provides tools for:
|
|
13
|
+
|
|
14
|
+
* Validating SVG files against conformance profiles
|
|
15
|
+
* Automatically remediating common SVG issues
|
|
16
|
+
* Batch processing directories of SVG files
|
|
17
|
+
* Generating validation reports
|
|
18
|
+
* Managing file remediation workflows
|
|
19
|
+
|
|
20
|
+
== Installation
|
|
21
|
+
|
|
22
|
+
Install the gem:
|
|
23
|
+
|
|
24
|
+
[source,bash]
|
|
25
|
+
----
|
|
26
|
+
$ gem install svg_conform
|
|
27
|
+
----
|
|
28
|
+
|
|
29
|
+
Or add to your Gemfile:
|
|
30
|
+
|
|
31
|
+
[source,ruby]
|
|
32
|
+
----
|
|
33
|
+
gem 'svg_conform'
|
|
34
|
+
----
|
|
35
|
+
|
|
36
|
+
Verify installation:
|
|
37
|
+
|
|
38
|
+
[source,bash]
|
|
39
|
+
----
|
|
40
|
+
$ svg_conform version
|
|
41
|
+
SvgConform 0.2.0
|
|
42
|
+
----
|
|
43
|
+
|
|
44
|
+
== Command overview
|
|
45
|
+
|
|
46
|
+
The `svg_conform` CLI provides the following commands:
|
|
47
|
+
|
|
48
|
+
* `check` - Validate and optionally remediate SVG files
|
|
49
|
+
* `profiles` - List available validation profiles
|
|
50
|
+
* `version` - Show version information
|
|
51
|
+
* `svgcheck` - SVGCheck compatibility commands (advanced)
|
|
52
|
+
|
|
53
|
+
== Command: check
|
|
54
|
+
|
|
55
|
+
The `check` command validates SVG files against a profile and optionally applies automatic remediations.
|
|
56
|
+
|
|
57
|
+
=== Basic usage
|
|
58
|
+
|
|
59
|
+
==== Single file validation
|
|
60
|
+
|
|
61
|
+
[source,bash]
|
|
62
|
+
----
|
|
63
|
+
$ svg_conform check file.svg --profile=metanorma
|
|
64
|
+
----
|
|
65
|
+
|
|
66
|
+
Output example:
|
|
67
|
+
|
|
68
|
+
[source,text]
|
|
69
|
+
----
|
|
70
|
+
SVG Validation Report
|
|
71
|
+
==================================================
|
|
72
|
+
File: file.svg
|
|
73
|
+
Profile: metanorma
|
|
74
|
+
Valid: ✗
|
|
75
|
+
Total Errors: 2
|
|
76
|
+
|
|
77
|
+
Validation Errors:
|
|
78
|
+
|
|
79
|
+
• Viewbox is required
|
|
80
|
+
at svg
|
|
81
|
+
|
|
82
|
+
• External images are not allowed
|
|
83
|
+
at image
|
|
84
|
+
... and 1 more
|
|
85
|
+
----
|
|
86
|
+
|
|
87
|
+
==== Multiple file validation
|
|
88
|
+
|
|
89
|
+
[source,bash]
|
|
90
|
+
----
|
|
91
|
+
$ svg_conform check file1.svg file2.svg file3.svg -p metanorma
|
|
92
|
+
----
|
|
93
|
+
|
|
94
|
+
==== Directory validation
|
|
95
|
+
|
|
96
|
+
Recursively validate all SVG files in a directory:
|
|
97
|
+
|
|
98
|
+
[source,bash]
|
|
99
|
+
----
|
|
100
|
+
$ svg_conform check --directory=images/ --profile=metanorma
|
|
101
|
+
----
|
|
102
|
+
|
|
103
|
+
Output shows a summary table and statistics.
|
|
104
|
+
|
|
105
|
+
=== Options reference
|
|
106
|
+
|
|
107
|
+
==== Input selection
|
|
108
|
+
|
|
109
|
+
`*FILES`::
|
|
110
|
+
One or more SVG files to process
|
|
111
|
+
|
|
112
|
+
`--directory=PATH` or `-d`::
|
|
113
|
+
Directory to scan recursively for SVG files
|
|
114
|
+
|
|
115
|
+
==== Profile selection
|
|
116
|
+
|
|
117
|
+
`--profile=PROFILE` or `-p`::
|
|
118
|
+
Profile to validate against (default: `svg_1_2_rfc`)
|
|
119
|
+
+
|
|
120
|
+
Available profiles:
|
|
121
|
+
+
|
|
122
|
+
* `base` - Minimal SVG validation
|
|
123
|
+
* `svg_1_2_rfc` - RFC 7996 compliance
|
|
124
|
+
* `svg_1_2_rfc_with_rdf` - RFC 7996 with RDF support
|
|
125
|
+
* `metanorma` - Metanorma requirements
|
|
126
|
+
* `lucid` - Lucid profile
|
|
127
|
+
* `no_external_css` - No external CSS
|
|
128
|
+
|
|
129
|
+
==== Output format (single file)
|
|
130
|
+
|
|
131
|
+
`--format=FORMAT`::
|
|
132
|
+
Output format for single file mode (default: `table`)
|
|
133
|
+
+
|
|
134
|
+
Options:
|
|
135
|
+
+
|
|
136
|
+
* `table` - Human-readable table (default)
|
|
137
|
+
* `json` - JSON format
|
|
138
|
+
* `yaml` - YAML format
|
|
139
|
+
|
|
140
|
+
`--output=FILE` or `-o`::
|
|
141
|
+
Save report to file instead of stdout
|
|
142
|
+
|
|
143
|
+
Examples:
|
|
144
|
+
|
|
145
|
+
[source,bash]
|
|
146
|
+
----
|
|
147
|
+
# JSON output to stdout
|
|
148
|
+
$ svg_conform check file.svg -p metanorma --format=json
|
|
149
|
+
|
|
150
|
+
# JSON output to file
|
|
151
|
+
$ svg_conform check file.svg -p metanorma --format=json -o report.json
|
|
152
|
+
|
|
153
|
+
# YAML output to file
|
|
154
|
+
$ svg_conform check file.svg -p metanorma --format=yaml -o report.yaml
|
|
155
|
+
----
|
|
156
|
+
|
|
157
|
+
==== Remediation options
|
|
158
|
+
|
|
159
|
+
`--fix` or `-f`::
|
|
160
|
+
Enable automatic remediation
|
|
161
|
+
|
|
162
|
+
`--fix-output=FILE`::
|
|
163
|
+
Output file for remediated SVG (single file mode)
|
|
164
|
+
+
|
|
165
|
+
Default: `FILE.fixed.svg`
|
|
166
|
+
|
|
167
|
+
`--output-dir=PATH`::
|
|
168
|
+
Output directory for remediated files (multi-file/directory mode)
|
|
169
|
+
+
|
|
170
|
+
Required when using `--fix` with multiple files or `--directory`
|
|
171
|
+
|
|
172
|
+
`--in-place`::
|
|
173
|
+
Replace original files with remediated versions
|
|
174
|
+
+
|
|
175
|
+
**Warning**: This is destructive. Requires `--force` flag.
|
|
176
|
+
|
|
177
|
+
`--force`::
|
|
178
|
+
Confirm destructive operations (required for `--in-place`)
|
|
179
|
+
|
|
180
|
+
Examples:
|
|
181
|
+
|
|
182
|
+
[source,bash]
|
|
183
|
+
----
|
|
184
|
+
# Single file with custom output
|
|
185
|
+
$ svg_conform check file.svg -p metanorma --fix --fix-output=cleaned.svg
|
|
186
|
+
|
|
187
|
+
# Multiple files to output directory
|
|
188
|
+
$ svg_conform check *.svg -p metanorma --fix --output-dir=fixed/
|
|
189
|
+
|
|
190
|
+
# Directory with in-place replacement (destructive!)
|
|
191
|
+
$ svg_conform check -d images/ -p metanorma --fix --in-place --force
|
|
192
|
+
----
|
|
193
|
+
|
|
194
|
+
==== Batch processing options
|
|
195
|
+
|
|
196
|
+
`--quiet` or `-q`::
|
|
197
|
+
Suppress per-file output, show summary only
|
|
198
|
+
|
|
199
|
+
`--verbose` or `-v`::
|
|
200
|
+
Show detailed progress information
|
|
201
|
+
|
|
202
|
+
`--report-format=FORMAT`::
|
|
203
|
+
Generate detailed batch report
|
|
204
|
+
+
|
|
205
|
+
Options: `json`, `yaml`
|
|
206
|
+
|
|
207
|
+
`--report-output=FILE`::
|
|
208
|
+
Save detailed batch report to file
|
|
209
|
+
|
|
210
|
+
`--manifest=FILE`::
|
|
211
|
+
Generate manifest file mapping original to remediated files
|
|
212
|
+
+
|
|
213
|
+
Default: `manifest.json` when using `--fix`
|
|
214
|
+
|
|
215
|
+
Examples:
|
|
216
|
+
|
|
217
|
+
[source,bash]
|
|
218
|
+
----
|
|
219
|
+
# Quiet mode - summary only
|
|
220
|
+
$ svg_conform check -d images/ -p metanorma -q
|
|
221
|
+
|
|
222
|
+
# Generate detailed JSON report
|
|
223
|
+
$ svg_conform check -d images/ -p metanorma \
|
|
224
|
+
--report-format=json --report-output=full-report.json
|
|
225
|
+
|
|
226
|
+
# Full workflow with manifest
|
|
227
|
+
$ svg_conform check -d images/ -p metanorma --fix --output-dir=fixed/ \
|
|
228
|
+
--manifest=file-mapping.json --report-format=json --report-output=report.json
|
|
229
|
+
----
|
|
230
|
+
|
|
231
|
+
=== Usage modes
|
|
232
|
+
|
|
233
|
+
==== Mode 1: Single file
|
|
234
|
+
|
|
235
|
+
Process one SVG file:
|
|
236
|
+
|
|
237
|
+
[source,bash]
|
|
238
|
+
----
|
|
239
|
+
$ svg_conform check file.svg -p metanorma
|
|
240
|
+
----
|
|
241
|
+
|
|
242
|
+
Features:
|
|
243
|
+
|
|
244
|
+
* Table output by default
|
|
245
|
+
* Can specify JSON/YAML format
|
|
246
|
+
* Simple validation or remediation
|
|
247
|
+
* Output to stdout or file
|
|
248
|
+
|
|
249
|
+
==== Mode 2: Multiple files
|
|
250
|
+
|
|
251
|
+
Process multiple specified files:
|
|
252
|
+
|
|
253
|
+
[source,bash]
|
|
254
|
+
----
|
|
255
|
+
$ svg_conform check file1.svg file2.svg file3.svg -p metanorma
|
|
256
|
+
----
|
|
257
|
+
|
|
258
|
+
Features:
|
|
259
|
+
|
|
260
|
+
* Batch report with statistics
|
|
261
|
+
* Requires `--output-dir` for remediation
|
|
262
|
+
* Per-file and summary output
|
|
263
|
+
|
|
264
|
+
==== Mode 3: Directory
|
|
265
|
+
|
|
266
|
+
Recursively process all SVG files in a directory:
|
|
267
|
+
|
|
268
|
+
[source,bash]
|
|
269
|
+
----
|
|
270
|
+
$ svg_conform check --directory=images/ -p metanorma
|
|
271
|
+
----
|
|
272
|
+
|
|
273
|
+
Features:
|
|
274
|
+
|
|
275
|
+
* Recursive directory scanning
|
|
276
|
+
* Batch report with statistics
|
|
277
|
+
* Optional manifest generation
|
|
278
|
+
* Supports `--in-place` remediation
|
|
279
|
+
|
|
280
|
+
=== Common workflows
|
|
281
|
+
|
|
282
|
+
==== Workflow 1: Quality control
|
|
283
|
+
|
|
284
|
+
Validate all SVGs before deployment:
|
|
285
|
+
|
|
286
|
+
[source,bash]
|
|
287
|
+
----
|
|
288
|
+
$ svg_conform check -d assets/images/ -p metanorma --quiet
|
|
289
|
+
|
|
290
|
+
# Exit code 0 = all valid
|
|
291
|
+
# Exit code 1 = validation failures
|
|
292
|
+
----
|
|
293
|
+
|
|
294
|
+
Use in CI/CD:
|
|
295
|
+
|
|
296
|
+
[source,bash]
|
|
297
|
+
----
|
|
298
|
+
#!/bin/bash
|
|
299
|
+
if svg_conform check -d docs/images/ -p metanorma -q; then
|
|
300
|
+
echo "All SVGs valid"
|
|
301
|
+
else
|
|
302
|
+
echo "SVG validation failed"
|
|
303
|
+
exit 1
|
|
304
|
+
fi
|
|
305
|
+
----
|
|
306
|
+
|
|
307
|
+
==== Workflow 2: Interactive remediation
|
|
308
|
+
|
|
309
|
+
Fix issues with review:
|
|
310
|
+
|
|
311
|
+
[source,bash]
|
|
312
|
+
----
|
|
313
|
+
# 1. Validate and see issues
|
|
314
|
+
$ svg_conform check file.svg -p metanorma
|
|
315
|
+
|
|
316
|
+
# 2. Apply fixes to new file
|
|
317
|
+
$ svg_conform check file.svg -p metanorma --fix --fix-output=file-fixed.svg
|
|
318
|
+
|
|
319
|
+
# 3. Review the fixed file
|
|
320
|
+
$ diff file.svg file-fixed.svg
|
|
321
|
+
|
|
322
|
+
# 4. Replace original if satisfied
|
|
323
|
+
$ mv file-fixed.svg file.svg
|
|
324
|
+
----
|
|
325
|
+
|
|
326
|
+
==== Workflow 3: Batch remediation
|
|
327
|
+
|
|
328
|
+
Fix all non-conforming files in a directory:
|
|
329
|
+
|
|
330
|
+
[source,bash]
|
|
331
|
+
----
|
|
332
|
+
# 1. Create backup
|
|
333
|
+
$ cp -r images/ images-backup/
|
|
334
|
+
|
|
335
|
+
# 2. Generate pre-fix report
|
|
336
|
+
$ svg_conform check -d images/ -p metanorma \
|
|
337
|
+
--report-format=json --report-output=before.json
|
|
338
|
+
|
|
339
|
+
# 3. Apply fixes to new directory
|
|
340
|
+
$ svg_conform check -d images/ -p metanorma \
|
|
341
|
+
--fix --output-dir=images-fixed/ --manifest=manifest.json
|
|
342
|
+
|
|
343
|
+
# 4. Verify fixes
|
|
344
|
+
$ svg_conform check -d images-fixed/ -p metanorma -q
|
|
345
|
+
|
|
346
|
+
# 5. If satisfied, replace originals
|
|
347
|
+
$ rm -rf images/
|
|
348
|
+
$ mv images-fixed/ images/
|
|
349
|
+
----
|
|
350
|
+
|
|
351
|
+
==== Workflow 4: In-place batch fix
|
|
352
|
+
|
|
353
|
+
Fix files in place (destructive):
|
|
354
|
+
|
|
355
|
+
[source,bash]
|
|
356
|
+
----
|
|
357
|
+
# IMPORTANT: Back up first!
|
|
358
|
+
$ cp -r images/ images-backup/
|
|
359
|
+
|
|
360
|
+
# Fix all files in place
|
|
361
|
+
$ svg_conform check -d images/ -p metanorma --fix --in-place --force
|
|
362
|
+
|
|
363
|
+
# Verify
|
|
364
|
+
$ svg_conform check -d images/ -p metanorma -q
|
|
365
|
+
----
|
|
366
|
+
|
|
367
|
+
==== Workflow 5: Selective remediation
|
|
368
|
+
|
|
369
|
+
Fix only specific files:
|
|
370
|
+
|
|
371
|
+
[source,bash]
|
|
372
|
+
----
|
|
373
|
+
# Find invalid files
|
|
374
|
+
$ svg_conform check -d images/ -p metanorma -q > results.txt
|
|
375
|
+
|
|
376
|
+
# Manually identify problematic files
|
|
377
|
+
# Then fix them individually
|
|
378
|
+
$ svg_conform check images/problematic1.svg -p metanorma -f
|
|
379
|
+
$ svg_conform check images/problematic2.svg -p metanorma -f
|
|
380
|
+
----
|
|
381
|
+
|
|
382
|
+
=== Exit codes
|
|
383
|
+
|
|
384
|
+
`0`::
|
|
385
|
+
Success - All files valid or successfully remediated
|
|
386
|
+
|
|
387
|
+
`1`::
|
|
388
|
+
Failure - Validation errors found or remediation failed
|
|
389
|
+
|
|
390
|
+
Use exit codes in scripts:
|
|
391
|
+
|
|
392
|
+
[source,bash]
|
|
393
|
+
----
|
|
394
|
+
if svg_conform check file.svg -p metanorma; then
|
|
395
|
+
echo "Valid!"
|
|
396
|
+
else
|
|
397
|
+
echo "Invalid - see errors above"
|
|
398
|
+
exit 1
|
|
399
|
+
fi
|
|
400
|
+
----
|
|
401
|
+
|
|
402
|
+
=== Output formats
|
|
403
|
+
|
|
404
|
+
==== Table format (default)
|
|
405
|
+
|
|
406
|
+
Human-readable table with error summary:
|
|
407
|
+
|
|
408
|
+
[source,text]
|
|
409
|
+
----
|
|
410
|
+
SVG Validation Report
|
|
411
|
+
==================================================
|
|
412
|
+
File: file.svg
|
|
413
|
+
Profile: metanorma
|
|
414
|
+
Valid: ✗
|
|
415
|
+
Total Errors: 2
|
|
416
|
+
|
|
417
|
+
Validation Errors:
|
|
418
|
+
|
|
419
|
+
• Viewbox is required
|
|
420
|
+
at svg
|
|
421
|
+
|
|
422
|
+
• External images are not allowed
|
|
423
|
+
at image
|
|
424
|
+
----
|
|
425
|
+
|
|
426
|
+
==== JSON format
|
|
427
|
+
|
|
428
|
+
Machine-readable JSON using lutaml-model:
|
|
429
|
+
|
|
430
|
+
[source,json]
|
|
431
|
+
----
|
|
432
|
+
{
|
|
433
|
+
"filename": "file.svg",
|
|
434
|
+
"profile": "metanorma",
|
|
435
|
+
"valid": false,
|
|
436
|
+
"errors": {
|
|
437
|
+
"total_count": 2,
|
|
438
|
+
"issues": [
|
|
439
|
+
{
|
|
440
|
+
"requirement_id": "viewbox_required",
|
|
441
|
+
"message": "Viewbox is required",
|
|
442
|
+
"element": "svg",
|
|
443
|
+
"line_number": 1
|
|
444
|
+
}
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
----
|
|
449
|
+
|
|
450
|
+
==== YAML format
|
|
451
|
+
|
|
452
|
+
Machine-readable YAML using lutaml-model:
|
|
453
|
+
|
|
454
|
+
[source,yaml]
|
|
455
|
+
----
|
|
456
|
+
filename: file.svg
|
|
457
|
+
profile: metanorma
|
|
458
|
+
valid: false
|
|
459
|
+
errors:
|
|
460
|
+
total_count: 2
|
|
461
|
+
issues:
|
|
462
|
+
- requirement_id: viewbox_required
|
|
463
|
+
message: Viewbox is required
|
|
464
|
+
element: svg
|
|
465
|
+
line_number: 1
|
|
466
|
+
----
|
|
467
|
+
|
|
468
|
+
==== Batch report format
|
|
469
|
+
|
|
470
|
+
For multiple files or directories:
|
|
471
|
+
|
|
472
|
+
[source,text]
|
|
473
|
+
----
|
|
474
|
+
================================================================================
|
|
475
|
+
BATCH VALIDATION SUMMARY
|
|
476
|
+
================================================================================
|
|
477
|
+
Directory: images/
|
|
478
|
+
Profile: metanorma
|
|
479
|
+
Files processed: 15
|
|
480
|
+
Valid before: 8
|
|
481
|
+
Remediated: 5
|
|
482
|
+
Valid after: 13
|
|
483
|
+
Failed: 2
|
|
484
|
+
Success rate: 86%
|
|
485
|
+
================================================================================
|
|
486
|
+
----
|
|
487
|
+
|
|
488
|
+
== Command: profiles
|
|
489
|
+
|
|
490
|
+
List available validation profiles with their descriptions.
|
|
491
|
+
|
|
492
|
+
=== Basic usage
|
|
493
|
+
|
|
494
|
+
[source,bash]
|
|
495
|
+
----
|
|
496
|
+
$ svg_conform profiles
|
|
497
|
+
----
|
|
498
|
+
|
|
499
|
+
Output:
|
|
500
|
+
|
|
501
|
+
[source,text]
|
|
502
|
+
----
|
|
503
|
+
Available SVG Profiles
|
|
504
|
+
========================================
|
|
505
|
+
|
|
506
|
+
Profile Description
|
|
507
|
+
------- -----------
|
|
508
|
+
base Minimal SVG validation
|
|
509
|
+
metanorma Metanorma document requirements
|
|
510
|
+
svg_1_2_rfc RFC 7996 compliance
|
|
511
|
+
...
|
|
512
|
+
|
|
513
|
+
Use --verbose for detailed information about each profile
|
|
514
|
+
----
|
|
515
|
+
|
|
516
|
+
=== Verbose mode
|
|
517
|
+
|
|
518
|
+
Show detailed information about profiles:
|
|
519
|
+
|
|
520
|
+
[source,bash]
|
|
521
|
+
----
|
|
522
|
+
$ svg_conform profiles --verbose
|
|
523
|
+
----
|
|
524
|
+
|
|
525
|
+
Output includes:
|
|
526
|
+
|
|
527
|
+
* Profile description
|
|
528
|
+
* Number of requirements
|
|
529
|
+
* Number of remediations
|
|
530
|
+
* List of all requirements with descriptions
|
|
531
|
+
* List of all remediations with descriptions
|
|
532
|
+
|
|
533
|
+
Example output:
|
|
534
|
+
|
|
535
|
+
[source,text]
|
|
536
|
+
----
|
|
537
|
+
Detailed SVG Validation Profiles
|
|
538
|
+
==================================================
|
|
539
|
+
|
|
540
|
+
Profile: metanorma
|
|
541
|
+
------------------------------
|
|
542
|
+
Description: Metanorma document requirements
|
|
543
|
+
Requirements: 12
|
|
544
|
+
Remediations: 8
|
|
545
|
+
Requirement Details:
|
|
546
|
+
• ViewboxRequiredRequirement
|
|
547
|
+
SVG must have a viewBox attribute
|
|
548
|
+
• NoExternalImagesRequirement
|
|
549
|
+
External images must be embedded
|
|
550
|
+
...
|
|
551
|
+
Remediation Details:
|
|
552
|
+
• ViewboxRemediation
|
|
553
|
+
Add missing viewBox attribute
|
|
554
|
+
• ImageEmbeddingRemediation
|
|
555
|
+
Embed external images as data URIs
|
|
556
|
+
...
|
|
557
|
+
----
|
|
558
|
+
|
|
559
|
+
== Command: version
|
|
560
|
+
|
|
561
|
+
Display version information:
|
|
562
|
+
|
|
563
|
+
[source,bash]
|
|
564
|
+
----
|
|
565
|
+
$ svg_conform version
|
|
566
|
+
SvgConform 0.2.0
|
|
567
|
+
----
|
|
568
|
+
|
|
569
|
+
== Troubleshooting
|
|
570
|
+
|
|
571
|
+
=== Common issues
|
|
572
|
+
|
|
573
|
+
==== "No SVG files found"
|
|
574
|
+
|
|
575
|
+
**Problem**: No files to process
|
|
576
|
+
|
|
577
|
+
**Solutions**:
|
|
578
|
+
|
|
579
|
+
[source,bash]
|
|
580
|
+
----
|
|
581
|
+
# Verify directory exists
|
|
582
|
+
$ ls -la images/
|
|
583
|
+
|
|
584
|
+
# Check for SVG files
|
|
585
|
+
$ find images/ -name "*.svg"
|
|
586
|
+
|
|
587
|
+
# Use absolute path
|
|
588
|
+
$ svg_conform check --directory=/absolute/path/to/images/
|
|
589
|
+
----
|
|
590
|
+
|
|
591
|
+
==== "Output directory required"
|
|
592
|
+
|
|
593
|
+
**Problem**: Using `--fix` with multiple files without `--output-dir`
|
|
594
|
+
|
|
595
|
+
**Solution**:
|
|
596
|
+
|
|
597
|
+
[source,bash]
|
|
598
|
+
----
|
|
599
|
+
# Specify output directory
|
|
600
|
+
$ svg_conform check *.svg -p metanorma --fix --output-dir=fixed/
|
|
601
|
+
----
|
|
602
|
+
|
|
603
|
+
==== "--in-place requires --force"
|
|
604
|
+
|
|
605
|
+
**Problem**: Safety check for destructive operation
|
|
606
|
+
|
|
607
|
+
**Solution**:
|
|
608
|
+
|
|
609
|
+
[source,bash]
|
|
610
|
+
----
|
|
611
|
+
# Add --force flag
|
|
612
|
+
$ svg_conform check -d images/ -p metanorma --fix --in-place --force
|
|
613
|
+
----
|
|
614
|
+
|
|
615
|
+
==== "Profile not found"
|
|
616
|
+
|
|
617
|
+
**Problem**: Invalid profile name
|
|
618
|
+
|
|
619
|
+
**Solution**:
|
|
620
|
+
|
|
621
|
+
[source,bash]
|
|
622
|
+
----
|
|
623
|
+
# List available profiles
|
|
624
|
+
$ svg_conform profiles
|
|
625
|
+
|
|
626
|
+
# Use correct profile name
|
|
627
|
+
$ svg_conform check file.svg -p metanorma
|
|
628
|
+
----
|
|
629
|
+
|
|
630
|
+
==== Exit code 1 with valid files
|
|
631
|
+
|
|
632
|
+
**Problem**: Some profiles have strict requirements
|
|
633
|
+
|
|
634
|
+
**Solution**:
|
|
635
|
+
|
|
636
|
+
* Review the error messages
|
|
637
|
+
* Use appropriate profile for your use case
|
|
638
|
+
* Consider custom profile if needed
|
|
639
|
+
|
|
640
|
+
=== Performance tips
|
|
641
|
+
|
|
642
|
+
==== Processing large directories
|
|
643
|
+
|
|
644
|
+
For directories with many files:
|
|
645
|
+
|
|
646
|
+
[source,bash]
|
|
647
|
+
----
|
|
648
|
+
# Use quiet mode
|
|
649
|
+
$ svg_conform check -d large-dir/ -p metanorma -q
|
|
650
|
+
|
|
651
|
+
# Process in batches
|
|
652
|
+
$ find images/ -name "*.svg" -print0 | \
|
|
653
|
+
xargs -0 -n 50 svg_conform check -p metanorma
|
|
654
|
+
----
|
|
655
|
+
|
|
656
|
+
==== Large SVG files
|
|
657
|
+
|
|
658
|
+
SvgConform uses SAX parsing for memory safety:
|
|
659
|
+
|
|
660
|
+
* No file size limits
|
|
661
|
+
* Constant memory usage
|
|
662
|
+
* Safe for files >100MB
|
|
663
|
+
|
|
664
|
+
=== Getting help
|
|
665
|
+
|
|
666
|
+
Display command help:
|
|
667
|
+
|
|
668
|
+
[source,bash]
|
|
669
|
+
----
|
|
670
|
+
# General help
|
|
671
|
+
$ svg_conform help
|
|
672
|
+
|
|
673
|
+
# Command-specific help
|
|
674
|
+
$ svg_conform help check
|
|
675
|
+
$ svg_conform help profiles
|
|
676
|
+
----
|
|
677
|
+
|
|
678
|
+
== Advanced usage
|
|
679
|
+
|
|
680
|
+
=== Custom profiles
|
|
681
|
+
|
|
682
|
+
Create a custom profile YAML file:
|
|
683
|
+
|
|
684
|
+
[source,yaml]
|
|
685
|
+
----
|
|
686
|
+
# my-profile.yml
|
|
687
|
+
name: my_custom_profile
|
|
688
|
+
description: Custom validation rules
|
|
689
|
+
|
|
690
|
+
requirements:
|
|
691
|
+
- type: viewbox_required
|
|
692
|
+
- type: no_external_images
|
|
693
|
+
- type: font_family
|
|
694
|
+
config:
|
|
695
|
+
allowed_families:
|
|
696
|
+
- Arial
|
|
697
|
+
- Helvetica
|
|
698
|
+
|
|
699
|
+
remediations:
|
|
700
|
+
- type: viewbox
|
|
701
|
+
- type: image_embedding
|
|
702
|
+
----
|
|
703
|
+
|
|
704
|
+
Use the custom profile:
|
|
705
|
+
|
|
706
|
+
[source,bash]
|
|
707
|
+
----
|
|
708
|
+
# Not yet supported via CLI - use Ruby API
|
|
709
|
+
$ ruby -e "require 'svg_conform'; \
|
|
710
|
+
profile = SvgConform::Profile.load_from_file('my-profile.yml'); \
|
|
711
|
+
validator = SvgConform::Validator.new; \
|
|
712
|
+
result = validator.validate_file('file.svg', profile: profile); \
|
|
713
|
+
puts result.valid?"
|
|
714
|
+
----
|
|
715
|
+
|
|
716
|
+
=== Integration examples
|
|
717
|
+
|
|
718
|
+
==== Git pre-commit hook
|
|
719
|
+
|
|
720
|
+
`.git/hooks/pre-commit`:
|
|
721
|
+
|
|
722
|
+
[source,bash]
|
|
723
|
+
----
|
|
724
|
+
#!/bin/bash
|
|
725
|
+
# Validate SVGs before commit
|
|
726
|
+
|
|
727
|
+
changed_svgs=$(git diff --cached --name-only --diff-filter=ACM | grep '\.svg$')
|
|
728
|
+
|
|
729
|
+
if [ -n "$changed_svgs" ]; then
|
|
730
|
+
echo "Validating SVG files..."
|
|
731
|
+
echo "$changed_svgs" | xargs svg_conform check -p metanorma -q
|
|
732
|
+
if [ $? -ne 0 ]; then
|
|
733
|
+
echo "SVG validation failed. Commit aborted."
|
|
734
|
+
exit 1
|
|
735
|
+
fi
|
|
736
|
+
fi
|
|
737
|
+
----
|
|
738
|
+
|
|
739
|
+
==== CI/CD integration (GitHub Actions)
|
|
740
|
+
|
|
741
|
+
`.github/workflows/svg-validation.yml`:
|
|
742
|
+
|
|
743
|
+
[source,yaml]
|
|
744
|
+
----
|
|
745
|
+
name: SVG Validation
|
|
746
|
+
on: [push, pull_request]
|
|
747
|
+
|
|
748
|
+
jobs:
|
|
749
|
+
validate:
|
|
750
|
+
runs-on: ubuntu-latest
|
|
751
|
+
steps:
|
|
752
|
+
- uses: actions/checkout@v2
|
|
753
|
+
- uses: ruby/setup-ruby@v1
|
|
754
|
+
with:
|
|
755
|
+
ruby-version: 3.0
|
|
756
|
+
- run: gem install svg_conform
|
|
757
|
+
- run: svg_conform check -d docs/images/ -p metanorma --quiet
|
|
758
|
+
----
|
|
759
|
+
|
|
760
|
+
==== Makefile integration
|
|
761
|
+
|
|
762
|
+
`Makefile`:
|
|
763
|
+
|
|
764
|
+
[source,makefile]
|
|
765
|
+
----
|
|
766
|
+
.PHONY: validate-svg fix-svg
|
|
767
|
+
|
|
768
|
+
validate-svg:
|
|
769
|
+
svg_conform check -d images/ -p metanorma --quiet
|
|
770
|
+
|
|
771
|
+
fix-svg:
|
|
772
|
+
svg_conform check -d images/ -p metanorma \
|
|
773
|
+
--fix --output-dir=images-fixed/ \
|
|
774
|
+
--manifest=manifest.json
|
|
775
|
+
@echo "Review images-fixed/ before replacing images/"
|
|
776
|
+
----
|
|
777
|
+
|
|
778
|
+
== Reference
|
|
779
|
+
|
|
780
|
+
=== All CLI options
|
|
781
|
+
|
|
782
|
+
[source,text]
|
|
783
|
+
----
|
|
784
|
+
GLOBAL OPTIONS:
|
|
785
|
+
--help, -h Show help
|
|
786
|
+
--version Show version
|
|
787
|
+
|
|
788
|
+
CHECK COMMAND:
|
|
789
|
+
FILES One or more SVG files
|
|
790
|
+
--directory, -d Directory to scan recursively
|
|
791
|
+
--profile, -p Profile name (default: svg_1_2_rfc)
|
|
792
|
+
--format Output format: table, json, yaml (default: table)
|
|
793
|
+
--output, -o Output file
|
|
794
|
+
--fix, -f Enable remediation
|
|
795
|
+
--fix-output Remediated file output (default: FILE.fixed.svg)
|
|
796
|
+
--output-dir Output directory for batch remediation
|
|
797
|
+
--in-place Replace original files (requires --force)
|
|
798
|
+
--force Confirm destructive operations
|
|
799
|
+
--report-format Batch report format: json, yaml
|
|
800
|
+
--report-output Batch report output file
|
|
801
|
+
--manifest Manifest file path (default: manifest.json)
|
|
802
|
+
--quiet, -q Suppress per-file output
|
|
803
|
+
--verbose, -v Show detailed progress
|
|
804
|
+
|
|
805
|
+
PROFILES COMMAND:
|
|
806
|
+
--verbose, -v Show detailed profile information
|
|
807
|
+
----
|
|
808
|
+
|
|
809
|
+
=== Profile compatibility
|
|
810
|
+
|
|
811
|
+
[cols="1,3"]
|
|
812
|
+
|===
|
|
813
|
+
| Profile | Use Case
|
|
814
|
+
|
|
815
|
+
| `base`
|
|
816
|
+
| Minimal SVG validation
|
|
817
|
+
|
|
818
|
+
| `svg_1_2_rfc`
|
|
819
|
+
| IETF RFC 7996 documents (strict)
|
|
820
|
+
|
|
821
|
+
| `svg_1_2_rfc_with_rdf`
|
|
822
|
+
| IETF RFC 7996 with RDF metadata
|
|
823
|
+
|
|
824
|
+
| `metanorma`
|
|
825
|
+
| Metanorma document generation
|
|
826
|
+
|
|
827
|
+
| `lucid`
|
|
828
|
+
| Lucid chart exports
|
|
829
|
+
|
|
830
|
+
| `no_external_css`
|
|
831
|
+
| Embedded CSS only
|
|
832
|
+
|===
|
|
833
|
+
|
|
834
|
+
=== Related documentation
|
|
835
|
+
|
|
836
|
+
* link:../README.adoc[Main README]
|
|
837
|
+
* link:api_reference.adoc[Ruby API Reference]
|
|
838
|
+
* link:profiles.adoc[Profile Documentation]
|
|
839
|
+
* link:requirements.adoc[Requirements Reference]
|
|
840
|
+
* link:remediation.adoc[Remediation Reference]
|
|
841
|
+
|
|
842
|
+
== Conclusion
|
|
843
|
+
|
|
844
|
+
The `svg_conform` CLI provides powerful tools for SVG validation and remediation. For more advanced usage, see the link:api_reference.adoc[Ruby API Reference].
|
|
845
|
+
|
|
846
|
+
For issues or questions, visit: https://github.com/metanorma/svg_conform
|