Skip to content

Commit

Permalink
header image debug: closes metanorma/metanorma-m3aawg#22
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Jan 27, 2020
1 parent eb6499e commit 7d2ecf5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/html2doc/mime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ def self.warnsvg(src)

# only processes locally stored images
def self.image_cleanup(docxml, dir, localdir)
#docxml.xpath(IMAGE_PATH).each do |i|
docxml.traverse do |i|
next unless i.element? && %w(img v:imagedata).include?(i.name)
warnsvg(i["src"])
#warnsvg(i["src"])
next if /^http/.match i["src"]
next if %r{^data:image/[^;]+;base64}.match i["src"]
local_filename = %r{^([A-Z]:)?/}.match(i["src"]) ? i["src"] :
Expand All @@ -115,12 +114,12 @@ def self.header_image_cleanup1(a, dir, filename, localdir)
if a.size == 2 && !(/ src="https?:/.match a[1]) &&
!(%r{ src="data:image/[^;]+;base64}.match a[1])
m = / src=['"](?<src>[^"']+)['"]/.match a[1]
warnsvg(m[:src])
#warnsvg(m[:src])
m2 = /\.(?<suffix>[a-zA-Z_0-9]+)$/.match m[:src]
new_filename = "file:///C:/Doc/#{filename}_files/#{mkuuid}.#{m2[:suffix]}"
new_filename = "#{mkuuid}.#{m2[:suffix]}"
old_filename = %r{^([A-Z]:)?/}.match(m[:src]) ? m[:src] : File.join(localdir, m[:src])
FileUtils.cp old_filename, File.join(dir, "#{mkuuid}.#{m2[:suffix]}")
a[1].sub!(%r{ src=['"](?<src>[^"']+)['"]}, " src='#{new_filename}'")
FileUtils.cp old_filename, File.join(dir, new_filename)
a[1].sub!(%r{ src=['"](?<src>[^"']+)['"]}, " src='file:///C:/Doc/#{filename}_files/#{new_filename}'")
end
a.join
end
Expand Down
2 changes: 2 additions & 0 deletions spec/html2doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,12 @@ def image_clean(x)
OUTPUT
end

=begin
it "warns about SVG" do
simple_body = '<img src="https://example.com/19160-6.svg">'
expect{ Html2Doc.process(html_input(simple_body), filename: "test") }.to output("https://example.com/19160-6.svg: SVG not supported\n").to_stderr
end
=end

it "processes epub:type footnotes" do
simple_body = '<div>This is a very simple
Expand Down

0 comments on commit 7d2ecf5

Please sign in to comment.