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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99fc70f6e9b8781722b3deed8143fabbadf28dfdda77f88e4ae9f7bfc3b83faf
4
- data.tar.gz: 51305f5baa732cbb3b9df0ed6640413df408930365ef3ce8f84c16cad3337288
3
+ metadata.gz: 91681e7073cc074159e4aab0c10043fd86c8cffeba1c1fef9b1db85d11894a42
4
+ data.tar.gz: 0b6047784c5a7ba431ddf6ddbdfd6fb6042289b0947eaa15563a5c3d9e731fba
5
5
  SHA512:
6
- metadata.gz: b757363df3d4c399b067478880534eb0fad2b8cd166e4e0d0e33c138bb599f8f7ac8d017bbbe7500d59ee5f161ff6e43b0205362a6fcb0ba6d0dfa7444dbf7bd
7
- data.tar.gz: add6f5d5626ee90828655bdf4feeb47091e362982dfe39372d0c85ff33efa21482b0f79ee4613b19ab438aae260c334bb3e15a3f3bf3eff2f80ed5486e888345
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
- d = Metanorma::Utils::datauri(i["src"], @localdir)
165
- # d.chars.to_a.each_slice(80).to_a.map { |s| s.join }.each { |s| warn s }
166
- png_validate1(i, Base64.strict_decode64(d.sub(/^.+?base64,/, "")))
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, "Corrupt PNG image")
174
- @fatalerror << "Exception #{e.message}"
200
+ @log.add("Images", img.parent,
201
+ "Corrupt PNG image detected: #{e.message}")
175
202
  end
176
203
 
177
204
  def validate(doc)
@@ -19,6 +19,6 @@ module Metanorma
19
19
  end
20
20
 
21
21
  module Standoc
22
- VERSION = "2.2.2.2".freeze
22
+ VERSION = "2.2.3".freeze
23
23
  end
24
24
  end
@@ -3,6 +3,7 @@ require_relative "isodoc/pdf_convert"
3
3
  require_relative "metanorma/standoc/converter"
4
4
  require_relative "metanorma/standoc/version"
5
5
  require "asciidoctor/extensions"
6
+ require "metanorma"
6
7
 
7
8
  if defined? Metanorma::Registry
8
9
  require_relative "metanorma/standoc"
@@ -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 and aborts if corrupt PNG" do
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
- == Clause
797
- image::spec/assets/corrupt.png[]
789
+ input = <<~INPUT
790
+ = Document title
791
+ Author
792
+ :docfile: test.adoc
793
+ :no-pdf:
798
794
 
799
- INPUT
800
- expect do
801
- Asciidoctor.convert(input, *OPTIONS)
802
- end.to raise_error(SystemExit)
803
- rescue SystemExit, RuntimeError
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 false
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 "does not warn and abort if not corrupt PNG" do
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/correct.png[]
838
+ image::spec/assets/nonexistent.png[]
823
839
 
824
840
  INPUT
841
+
825
842
  expect do
826
843
  Asciidoctor.convert(input, *OPTIONS)
827
- end.not_to raise_error
828
- rescue SystemExit, RuntimeError
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
- .not_to include "Corrupt PNG image"
832
- expect(File.exist?("test.xml")).to be true
850
+ .to include "Image not found"
851
+ expect(File.exist?("test.xml")).to be false
833
852
  end
834
853
  end