Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions converters/libre/lib/libre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def convert

Dir.mktmpdir do |tdir|
user_installation = File.join(tdir, "user_installation")
command(cd + join + soffice( source, user_installation ) + join + move(thisdir(outfile)) )
command(cd + join + soffice( source, user_installation ) )
fix_image_path
command(cd + join + move(thisdir(outfile)) )
end

end #def
Expand All @@ -50,5 +52,17 @@ def soffice( src, user_installation )
"#{LIBRE_OFFICE_BIN} --headless --convert-to #{preview_format} --outdir #{shell_quote tmpdir} -env:UserInstallation=file://#{user_installation} #{shell_quote src}"
end
end #def

def fix_image_path
filepath = Dir[tmpdir+"/*.html"][0]
return if filepath.nil?
basefilename = filepath.split('/')[-1].split('.')[0]
return if basefilename.ascii_only?
if File.exists?(filepath)
text = File.read(filepath)
new_contents = text.gsub(/(?<=img src=")([a-zA-z%\d]+)(?=_html)/, URI::encode_www_form_component(basefilename))
File.open(filepath, "w") {|file| file.puts new_contents }
end
end

end #class
end #class