Skip to content

Commit

Permalink
Extract target_extname to allow 'html:HTML:EmbedImages'
Browse files Browse the repository at this point in the history
fix DocSpring#27

When the target format was 'html:HTML:EmbededImages', the current implementation of
the extension extraction logic generated an incorrect file extension of 'html:HTML'.

To address this issue, we have revised the extension extraction logic to correctly
identify and generate the appropriate file extension for the target format.
  • Loading branch information
yhirano55 committed Apr 13, 2023
1 parent 05ce17c commit 5cff65d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/libreconv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ def escaped_source_path

# @return [String]
def target_filename
File.basename(escaped_source_path, '.*') + '.' + File.basename(@convert_to, ':*')
File.basename(escaped_source_path, '.*') + '.' + target_extname
end

# @return [String]
def target_extname
@convert_to.split(':')[0]
end

# @raise [IOError] If soffice headless command line tool not found.
Expand Down
Binary file added spec/fixtures/docx_with_image.docx
Binary file not shown.
11 changes: 11 additions & 0 deletions spec/libreconv/converter_convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
end
end

it 'converts a file to the specified target html with EmbedImages options' do
create_tmpfile(['', '.html']) do |target_file|
fixture_file = fixture_path('docx_with_image.docx')
described_class.new(fixture_file, target_file, nil, 'html:HTML:EmbedImages').convert

converted_file = File.read(target_file)
expect(File.size?(target_file)).to be > 0
expect(converted_file).to include('data:image/png;base64')
end
end

Helpers::FILE_TYPES.each do |type|
it "converts a #{type} to pdf" do
Dir.mktmpdir do |target_path|
Expand Down

0 comments on commit 5cff65d

Please sign in to comment.