html2odt 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9acdd4dd439c892b26e76cdaa4357a22715d970
4
- data.tar.gz: 1d93cf21cfe79188b4b11e51cdfd757174d65568
3
+ metadata.gz: f17ae59439de60f02d2bb78494d27c6e4107638b
4
+ data.tar.gz: 598800a2f2928bc4bfcfda35383dbb825ffd4f7f
5
5
  SHA512:
6
- metadata.gz: 6ca018cee5cb3d8e74f2d94672f7de539199ededb3165f209daba36e16077c452779348e200f014a1aebfa57df86e140e7799ac523ff85132b43f342957e8ec0
7
- data.tar.gz: 67f05f3ade7cf012d9aaf73623601f2331e492c4d70e1dc0334ee099315a3053ff7836c0bf60aee4c97fed95e86b7493664658378741b931a529fd93740a8678
6
+ metadata.gz: eb6e4267022ff572028c42632c6edd03f3660bd91fa013933880052ecc71de6c4009cf878c440d16bb264243bf145b9478ab73e837be30d46bc3d9c8008d7293
7
+ data.tar.gz: dbe23ef34a73cdbfa7661863178fc02161be4fd405ba4817a7ec4cd432f5c4c52e52b8fa41afda2b2a72c6f0fc173885a7da56423654713c81b20fcb9d3024e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.2.1 - 2016-05-25
2
+
3
+ Adding workarounds for HTML structures not supported by xhtml2odt.
4
+
1
5
  # v0.2.0 - 2016-05-24
2
6
 
3
7
  Generating OpenDocument v1.1 instead of 1.2 to improve compatibility with
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- html2odt (0.2.0)
4
+ html2odt (0.2.1)
5
5
  dimensions (~> 1.3.0)
6
6
  nokogiri (~> 1.6.7.2)
7
7
  rubyzip (~> 1.0)
@@ -186,15 +186,12 @@ class Html2Odt::Document
186
186
  def prepare_html
187
187
  html = self.html
188
188
  html = fix_images_in_html(html)
189
+ html = fix_document_structure(html)
189
190
  html = create_document(html)
190
191
  html
191
192
  end
192
193
 
193
194
 
194
- def create_document(html)
195
- %Q{<html xmlns="http://www.w3.org/1999/xhtml">#{html}</html>}
196
- end
197
-
198
195
  def fix_images_in_html(html)
199
196
  doc = Nokogiri::HTML::DocumentFragment.parse(html)
200
197
 
@@ -223,7 +220,31 @@ class Html2Odt::Document
223
220
  end
224
221
  end
225
222
 
226
- doc.to_xml
223
+ doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML)
224
+ end
225
+
226
+ def fix_document_structure(html)
227
+ doc = Nokogiri::HTML::DocumentFragment.parse(html)
228
+
229
+ # XHTML2ODT cannot handle <code> elements without parent block elements,
230
+ # i.e. a containing <pre> or <p>. Adding a <p> in that case
231
+ doc.css("code").select { |code| code.ancestors("p, pre").empty? }.each do |code|
232
+ p = create_node(doc, "p")
233
+ code.add_next_sibling(p)
234
+ p.add_child(code)
235
+ end
236
+
237
+ # XHTML2ODT cannot handle <br> within <pre> tags properly, replacing them
238
+ # with new lines should have the same side effects.
239
+ doc.css("pre br").each do |br|
240
+ br.replace("\n")
241
+ end
242
+
243
+ doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML)
244
+ end
245
+
246
+ def create_document(html)
247
+ %Q{<html xmlns="http://www.w3.org/1999/xhtml">#{html}</html>}
227
248
  end
228
249
 
229
250
  def file_path_for(src)
@@ -1,3 +1,3 @@
1
1
  module Html2Odt
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2odt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregor Schmidt (Planio)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-24 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dimensions