Skip to content

Commit

Permalink
Merge pull request #112 from skoji/fix-properties-overwrite
Browse files Browse the repository at this point in the history
Do not remove properties in GEPUB::Item#guess_content_property
  • Loading branch information
skoji authored Feb 22, 2020
2 parents 22a373c + 629742d commit cca2898
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/gepub/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def landmark(type:, title:, id: nil)
# guess and set content property from contents.
def guess_content_property
if File.extname(self.href) =~ /.x?html/ && @attributes['media-type'] === 'application/xhtml+xml'
@attributes['properties'] = (@attributes['properties'] || []).reject {
|x| x == 'svg' || x == 'mathml' || x == 'switch' || x == 'remote-resources'
}
@attributes['properties'] ||= []
parsed = Nokogiri::XML::Document.parse(@content)
return unless parsed.root.node_name === "html"
ns_prefix = parsed.namespaces.invert['http://www.w3.org/1999/xhtml']
Expand Down
14 changes: 14 additions & 0 deletions spec/gepub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,18 @@
expect(FileUtils.compare_file(epubname1, epubname2)).to be true
end

it 'should not forget svg attribute when parsing book' do
@book = GEPUB::Book.new
@book.identifier = 'test'
@book.add_ordered_item('foobar.xhtml', content: StringIO.new('<html><img src="image.svg" /></html>')).add_property 'svg'
epubname = File.join(__dir__, 'testepub.epub')
@book.generate_epub(epubname)
File.open(epubname) do |f|
parsed_book = GEPUB::Book.parse(f)
item = parsed_book.item_by_href 'foobar.xhtml'
expect(item).not_to be_nil
expect(item['properties']).to include 'svg'
end
end

end

0 comments on commit cca2898

Please sign in to comment.