spec/html2doc_spec.rb in html2doc-1.2.1 vs spec/html2doc_spec.rb in html2doc-1.3.0
- old
+ new
@@ -39,19 +39,18 @@
Content-ID: <test.htm>
Content-Disposition: inline; filename="test.htm"
Content-Type: text/html; charset="utf-8"
<?xml version="1.0"?>
- <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]>
+ <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>100</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
- <![endif]-->
<meta http-equiv=Content-Type content="text/html; charset=utf-8"/>
<link rel=File-List href="cid:filelist.xml"/>
<title>blank</title><style><![CDATA[
<!--
@@ -276,10 +275,21 @@
RSpec.describe Html2Doc do
it "has a version number" do
expect(Html2Doc::VERSION).not_to be nil
end
+ it "preserves Word HTML directives" do
+ Html2Doc.process(html_input(%[A<!--[if gte mso 9]>X<![endif]-->B]), filename: "test")
+ expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
+ .to match_fuzzy(<<~OUTPUT)
+ #{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
+ #{word_body(%{A<!--[if gte mso 9]>X<![endif]-->B},
+ '<div style="mso-element:footnote-list"/>')}
+ #{WORD_FTR1}
+ OUTPUT
+ end
+
it "processes a blank document" do
Html2Doc.process(html_input(""), filename: "test")
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
.to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
@@ -365,11 +375,12 @@
it "processes a header with an image with absolute path" do
doc = File.read("spec/header_img.html", encoding: "utf-8")
File.open("spec/header_img1.html", "w:UTF-8") do |f|
f.write(
doc.sub(%r{spec/19160-6.png},
- File.expand_path(File.join(File.dirname(__FILE__), "19160-6.png"))),
+ File.expand_path(File.join(File.dirname(__FILE__),
+ "19160-6.png"))),
)
end
Html2Doc.process(html_input(""),
filename: "test", header_file: "spec/header_img1.html")
doc = guid_clean(File.read("test.doc", encoding: "utf-8"))
@@ -563,11 +574,12 @@
OUTPUT
end
it "resizes images for height, in a file in a subdirectory" do
simple_body = '<img src="19160-6.png">'
- Html2Doc.process(html_input(simple_body), filename: "spec/test", imagedir: "spec")
+ Html2Doc.process(html_input(simple_body), filename: "spec/test",
+ imagedir: "spec")
testdoc = File.read("spec/test.doc", encoding: "utf-8")
expect(testdoc).to match(%r{Content-Type: image/png})
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
#{image_clean(word_body('<img src="cid:cb7b0d19-891e-4634-815a-570d019d454c.png" width="400" height="388"></img>', '<div style="mso-element:footnote-list"/>'))}
@@ -651,10 +663,11 @@
OUTPUT
end
it "deals with absolute image locations" do
simple_body = %{<img src="#{__dir__}/19160-6.png">}
- Html2Doc.process(html_input(simple_body), filename: "spec/test", imagedir: ".")
+ Html2Doc.process(html_input(simple_body), filename: "spec/test",
+ imagedir: ".")
testdoc = File.read("spec/test.doc", encoding: "utf-8")
expect(testdoc).to match(%r{Content-Type: image/png})
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
#{image_clean(word_body('<img src="cid:cb7b0d19-891e-4634-815a-570d019d454c.png" width="400" height="388"></img>', '<div style="mso-element:footnote-list"/>'))}