metanorma-standoc 2.2.2.2 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/metanorma/standoc/validate.rb +33 -6
- data/lib/metanorma/standoc/version.rb +1 -1
- data/lib/metanorma-standoc.rb +1 -0
- data/metanorma-standoc.gemspec +0 -1
- data/spec/metanorma/validate_spec.rb +43 -24
- data/spec/vcr_cassettes/bsi16341.yml +54 -76
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +48 -48
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +10 -10
- data/spec/vcr_cassettes/hide_refs.yml +73 -73
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +23 -23
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +53 -53
- data/spec/vcr_cassettes/isobib_get_123_2.yml +25 -25
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +11 -11
- data/spec/vcr_cassettes/isobib_get_124.yml +11 -11
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +56 -20
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +55 -55
- data/spec/vcr_cassettes/std-link.yml +12 -12
- metadata +1 -16
- data/Gemfile.devel +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91681e7073cc074159e4aab0c10043fd86c8cffeba1c1fef9b1db85d11894a42
|
4
|
+
data.tar.gz: 0b6047784c5a7ba431ddf6ddbdfd6fb6042289b0947eaa15563a5c3d9e731fba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68dcf12b8ba888e074970b6cea1918ec8223dd9ae5297a3bac0f337bed63731a8bf1579028915dfa07ce0ec7924677c603c81427b3bccb99640b07f2e148da19
|
7
|
+
data.tar.gz: 89458b82d0111581cc81a9cb19ad1c6dcecbdf64916c958e729d4a59424ab61f5c4ab9b7ac73ecbcab242e1e41624e28335bf94edcd7dd50dc80a6f74fd1245e
|
@@ -5,7 +5,6 @@ require "nokogiri"
|
|
5
5
|
require "jing"
|
6
6
|
require "iev"
|
7
7
|
require "pngcheck"
|
8
|
-
require "png"
|
9
8
|
|
10
9
|
module Metanorma
|
11
10
|
module Standoc
|
@@ -160,18 +159,46 @@ module Metanorma
|
|
160
159
|
end
|
161
160
|
|
162
161
|
def image_validate(doc)
|
162
|
+
image_exists(doc)
|
163
|
+
png_validate(doc)
|
164
|
+
end
|
165
|
+
|
166
|
+
def image_exists(doc)
|
167
|
+
doc.xpath("//image").each do |i|
|
168
|
+
Metanorma::Utils::url?(i["src"]) and next
|
169
|
+
Metanorma::Utils::datauri?(i["src"]) and next
|
170
|
+
expand_path(i["src"]) and next
|
171
|
+
@log.add("Images", i.parent,
|
172
|
+
"Image not found: #{i['src']}")
|
173
|
+
@fatalerror << "Image not found: #{i['src']}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def expand_path(loc)
|
178
|
+
relative_path = File.join(@localdir, loc)
|
179
|
+
[loc, relative_path].detect do |p|
|
180
|
+
File.exist?(p) ? p : nil
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def png_validate(doc)
|
163
185
|
doc.xpath("//image[@mimetype = 'image/png']").each do |i|
|
164
|
-
|
165
|
-
|
166
|
-
|
186
|
+
Metanorma::Utils::url?(i["src"]) and next
|
187
|
+
decoded = if Metanorma::Utils::datauri?(i["src"])
|
188
|
+
Metanorma::Utils::decode_datauri(i["src"])[:data]
|
189
|
+
else
|
190
|
+
path = expand_path(i["src"]) or next
|
191
|
+
File.binread(path)
|
192
|
+
end
|
193
|
+
png_validate1(i, decoded)
|
167
194
|
end
|
168
195
|
end
|
169
196
|
|
170
197
|
def png_validate1(img, buffer)
|
171
198
|
PngCheck.check_buffer(buffer)
|
172
199
|
rescue PngCheck::CorruptPngError => e
|
173
|
-
@log.add("Images", img.parent,
|
174
|
-
|
200
|
+
@log.add("Images", img.parent,
|
201
|
+
"Corrupt PNG image detected: #{e.message}")
|
175
202
|
end
|
176
203
|
|
177
204
|
def validate(doc)
|
data/lib/metanorma-standoc.rb
CHANGED
data/metanorma-standoc.gemspec
CHANGED
@@ -38,7 +38,6 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_dependency "latexmath"
|
39
39
|
spec.add_dependency "mathml2asciimath"
|
40
40
|
spec.add_dependency "mn-requirements", "~> 0.1.3"
|
41
|
-
spec.add_dependency "png"
|
42
41
|
spec.add_dependency "pngcheck"
|
43
42
|
spec.add_dependency "relaton-cli", "~> 1.13.0"
|
44
43
|
spec.add_dependency "relaton-iev", "~> 1.1.0"
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "relaton_iec"
|
3
2
|
require "fileutils"
|
4
3
|
|
5
4
|
RSpec.describe Metanorma::Standoc do
|
@@ -783,34 +782,51 @@ RSpec.describe Metanorma::Standoc do
|
|
783
782
|
.not_to include "Symbol reference in `symbol[xyz]` missing:"
|
784
783
|
end
|
785
784
|
|
786
|
-
it "warns
|
785
|
+
it "warns if corrupt PNG" do
|
787
786
|
FileUtils.rm_f "test.xml"
|
788
787
|
FileUtils.rm_f "test.err"
|
789
|
-
begin
|
790
|
-
input = <<~INPUT
|
791
|
-
= Document title
|
792
|
-
Author
|
793
|
-
:docfile: test.adoc
|
794
|
-
:no-pdf:
|
795
788
|
|
796
|
-
|
797
|
-
|
789
|
+
input = <<~INPUT
|
790
|
+
= Document title
|
791
|
+
Author
|
792
|
+
:docfile: test.adoc
|
793
|
+
:no-pdf:
|
798
794
|
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
end
|
805
|
-
warn File.read("test.err")
|
795
|
+
== Clause
|
796
|
+
image::spec/assets/corrupt.png[]
|
797
|
+
|
798
|
+
INPUT
|
799
|
+
Asciidoctor.convert(input, *OPTIONS)
|
806
800
|
expect(File.read("test.err"))
|
807
801
|
.to include "Corrupt PNG image"
|
808
|
-
expect(File.exist?("test.xml")).to be
|
802
|
+
expect(File.exist?("test.xml")).to be true
|
803
|
+
end
|
804
|
+
|
805
|
+
it "does not warn if not corrupt PNG" do
|
806
|
+
FileUtils.rm_f "test.xml"
|
807
|
+
FileUtils.rm_f "test.err"
|
808
|
+
|
809
|
+
input = <<~INPUT
|
810
|
+
= Document title
|
811
|
+
Author
|
812
|
+
:docfile: test.adoc
|
813
|
+
:no-pdf:
|
814
|
+
|
815
|
+
== Clause
|
816
|
+
image::spec/assets/correct.png[]
|
817
|
+
|
818
|
+
INPUT
|
819
|
+
|
820
|
+
Asciidoctor.convert(input, *OPTIONS)
|
821
|
+
expect(File.read("test.err"))
|
822
|
+
.not_to include "Corrupt PNG image"
|
823
|
+
expect(File.exist?("test.xml")).to be true
|
809
824
|
end
|
810
825
|
|
811
|
-
it "
|
826
|
+
it "warns and aborts if images does not exist" do
|
812
827
|
FileUtils.rm_f "test.xml"
|
813
828
|
FileUtils.rm_f "test.err"
|
829
|
+
|
814
830
|
begin
|
815
831
|
input = <<~INPUT
|
816
832
|
= Document title
|
@@ -819,16 +835,19 @@ RSpec.describe Metanorma::Standoc do
|
|
819
835
|
:no-pdf:
|
820
836
|
|
821
837
|
== Clause
|
822
|
-
image::spec/assets/
|
838
|
+
image::spec/assets/nonexistent.png[]
|
823
839
|
|
824
840
|
INPUT
|
841
|
+
|
825
842
|
expect do
|
826
843
|
Asciidoctor.convert(input, *OPTIONS)
|
827
|
-
end.
|
828
|
-
rescue SystemExit
|
844
|
+
end.to raise_error(SystemExit)
|
845
|
+
rescue SystemExit
|
829
846
|
end
|
847
|
+
|
848
|
+
warn File.read("test.err")
|
830
849
|
expect(File.read("test.err"))
|
831
|
-
.
|
832
|
-
expect(File.exist?("test.xml")).to be
|
850
|
+
.to include "Image not found"
|
851
|
+
expect(File.exist?("test.xml")).to be false
|
833
852
|
end
|
834
853
|
end
|