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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/html2odt/document.rb +26 -5
- data/lib/html2odt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f17ae59439de60f02d2bb78494d27c6e4107638b
|
4
|
+
data.tar.gz: 598800a2f2928bc4bfcfda35383dbb825ffd4f7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb6e4267022ff572028c42632c6edd03f3660bd91fa013933880052ecc71de6c4009cf878c440d16bb264243bf145b9478ab73e837be30d46bc3d9c8008d7293
|
7
|
+
data.tar.gz: dbe23ef34a73cdbfa7661863178fc02161be4fd405ba4817a7ec4cd432f5c4c52e52b8fa41afda2b2a72c6f0fc173885a7da56423654713c81b20fcb9d3024e7
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/html2odt/document.rb
CHANGED
@@ -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)
|
data/lib/html2odt/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dimensions
|