From 629742d7c5626ffaa74bd36f5f6593e8474b897c Mon Sep 17 00:00:00 2001 From: Satoshi Kojima Date: Sat, 22 Feb 2020 18:35:11 +0900 Subject: [PATCH] fix #110; do not remove properties in GEPUB::Item#guess_content_property --- lib/gepub/item.rb | 4 +--- spec/gepub_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/gepub/item.rb b/lib/gepub/item.rb index c6cbe9e..4685a83 100644 --- a/lib/gepub/item.rb +++ b/lib/gepub/item.rb @@ -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'] diff --git a/spec/gepub_spec.rb b/spec/gepub_spec.rb index 1496f9e..7532060 100644 --- a/spec/gepub_spec.rb +++ b/spec/gepub_spec.rb @@ -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('')).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