html2doc 1.1.0 → 1.1.4
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/.github/workflows/rake.yml +1 -11
- data/.hound.yml +3 -1
- data/.rubocop.yml +4 -8
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/bin/html2doc +1 -2
- data/bin/rspec +1 -1
- data/html2doc.gemspec +8 -9
- data/lib/html2doc/base.rb +48 -46
- data/lib/html2doc/lists.rb +47 -42
- data/lib/html2doc/math.rb +100 -79
- data/lib/html2doc/mime.rb +41 -34
- data/lib/html2doc/notes.rb +42 -36
- data/lib/html2doc/version.rb +1 -1
- data/lib/html2doc.rb +0 -3
- data/spec/html2doc_spec.rb +566 -521
- metadata +42 -42
data/spec/html2doc_spec.rb
CHANGED
@@ -1,275 +1,276 @@
|
|
1
1
|
require "base64"
|
2
2
|
|
3
|
-
def html_input(
|
3
|
+
def html_input(xml)
|
4
4
|
<<~HTML
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
<html><head><title>blank</title>
|
6
|
+
<meta name="Originator" content="Me"/>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
#{xml}
|
10
|
+
</body></html>
|
11
11
|
HTML
|
12
12
|
end
|
13
13
|
|
14
|
-
def html_input_no_title(
|
14
|
+
def html_input_no_title(xml)
|
15
15
|
<<~HTML
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
<html><head>
|
17
|
+
<meta name="Originator" content="Me"/>
|
18
|
+
</head>
|
19
|
+
<body>
|
20
|
+
#{xml}
|
21
|
+
</body></html>
|
22
22
|
HTML
|
23
23
|
end
|
24
24
|
|
25
|
-
def html_input_empty_head(
|
25
|
+
def html_input_empty_head(xml)
|
26
26
|
<<~HTML
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
<html><head></head>
|
28
|
+
<body>
|
29
|
+
#{xml}
|
30
|
+
</body></html>
|
31
31
|
HTML
|
32
32
|
end
|
33
33
|
|
34
|
-
WORD_HDR = <<~HDR
|
35
|
-
MIME-Version: 1.0
|
36
|
-
Content-Type: multipart/related; boundary="----=_NextPart_"
|
37
|
-
|
38
|
-
------=_NextPart_
|
39
|
-
Content-ID: <test.htm>
|
40
|
-
Content-Disposition: inline; filename="test.htm"
|
41
|
-
Content-Type: text/html; charset="utf-8"
|
42
|
-
|
43
|
-
<?xml version="1.0"?>
|
44
|
-
<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]>
|
45
|
-
<xml>
|
46
|
-
<w:WordDocument>
|
47
|
-
<w:View>Print</w:View>
|
48
|
-
<w:Zoom>100</w:Zoom>
|
49
|
-
<w:DoNotOptimizeForBrowser/>
|
50
|
-
</w:WordDocument>
|
51
|
-
</xml>
|
52
|
-
<![endif]-->
|
53
|
-
<meta http-equiv=Content-Type content="text/html; charset=utf-8"/>
|
54
|
-
|
55
|
-
|
56
|
-
<title>blank</title><style><![CDATA[
|
57
|
-
|
34
|
+
WORD_HDR = <<~HDR.freeze
|
35
|
+
MIME-Version: 1.0
|
36
|
+
Content-Type: multipart/related; boundary="----=_NextPart_"
|
37
|
+
|
38
|
+
------=_NextPart_
|
39
|
+
Content-ID: <test.htm>
|
40
|
+
Content-Disposition: inline; filename="test.htm"
|
41
|
+
Content-Type: text/html; charset="utf-8"
|
42
|
+
|
43
|
+
<?xml version="1.0"?>
|
44
|
+
<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]>
|
45
|
+
<xml>
|
46
|
+
<w:WordDocument>
|
47
|
+
<w:View>Print</w:View>
|
48
|
+
<w:Zoom>100</w:Zoom>
|
49
|
+
<w:DoNotOptimizeForBrowser/>
|
50
|
+
</w:WordDocument>
|
51
|
+
</xml>
|
52
|
+
<![endif]-->
|
53
|
+
<meta http-equiv=Content-Type content="text/html; charset=utf-8"/>
|
54
|
+
|
55
|
+
<link rel=File-List href="cid:filelist.xml"/>
|
56
|
+
<title>blank</title><style><![CDATA[
|
57
|
+
<!--
|
58
58
|
HDR
|
59
59
|
|
60
|
-
WORD_HDR_END = <<~HDR
|
61
|
-
-->
|
62
|
-
]]></style>
|
63
|
-
<meta name="Originator" content="Me"/>
|
64
|
-
</head>
|
60
|
+
WORD_HDR_END = <<~HDR.freeze
|
61
|
+
-->
|
62
|
+
]]></style>
|
63
|
+
<meta name="Originator" content="Me"/>
|
64
|
+
</head>
|
65
65
|
HDR
|
66
66
|
|
67
|
-
def word_body(
|
67
|
+
def word_body(xml, footnote)
|
68
68
|
<<~BODY
|
69
|
-
<body>
|
70
|
-
|
71
|
-
|
69
|
+
<body>
|
70
|
+
#{xml}
|
71
|
+
#{footnote}</body></html>
|
72
72
|
BODY
|
73
73
|
end
|
74
74
|
|
75
|
-
WORD_FTR1 = <<~FTR
|
75
|
+
WORD_FTR1 = <<~FTR.freeze
|
76
76
|
------=_NextPart_
|
77
|
-
Content-ID: <filelist.xml>
|
78
|
-
Content-Disposition: inline; filename="filelist.xml"
|
79
|
-
Content-Transfer-Encoding: base64
|
80
|
-
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
|
77
|
+
Content-ID: <filelist.xml>
|
78
|
+
Content-Disposition: inline; filename="filelist.xml"
|
79
|
+
Content-Transfer-Encoding: base64
|
80
|
+
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
|
81
81
|
|
82
|
-
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
|
83
|
-
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
|
84
|
-
bGVsaXN0LnhtbCIvPgo8L3htbD4K
|
82
|
+
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
|
83
|
+
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
|
84
|
+
bGVsaXN0LnhtbCIvPgo8L3htbD4K
|
85
85
|
|
86
|
-
------=_NextPart_--
|
86
|
+
------=_NextPart_--
|
87
87
|
FTR
|
88
88
|
|
89
|
-
WORD_FTR2 = <<~FTR
|
89
|
+
WORD_FTR2 = <<~FTR.freeze
|
90
|
+
------=_NextPart_
|
91
|
+
Content-ID: <filelist.xml>
|
92
|
+
Content-Disposition: inline; filename="filelist.xml"
|
93
|
+
Content-Transfer-Encoding: base64
|
94
|
+
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
|
95
|
+
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
|
96
|
+
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
|
97
|
+
bGVsaXN0LnhtbCIvPgogIDxvOkZpbGUgSFJlZj0iaGVhZGVyLmh0bWwiLz4KPC94bWw+Cg==
|
90
98
|
------=_NextPart_
|
91
|
-
Content-ID: <filelist.xml>
|
92
|
-
Content-Disposition: inline; filename="filelist.xml"
|
93
|
-
Content-Transfer-Encoding: base64
|
94
|
-
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
|
95
|
-
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
|
96
|
-
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9ImZp
|
97
|
-
bGVsaXN0LnhtbCIvPgogIDxvOkZpbGUgSFJlZj0iaGVhZGVyLmh0bWwiLz4KPC94bWw+Cg==
|
98
|
-
------=_NextPart_
|
99
99
|
FTR
|
100
100
|
|
101
|
-
WORD_FTR3 = <<~FTR
|
102
|
-
------=_NextPart_
|
103
|
-
Content-ID: <filelist.xml>
|
104
|
-
Content-Disposition: inline; filename="filelist.xml"
|
105
|
-
Content-Transfer-Encoding: base64
|
106
|
-
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
|
107
|
-
|
108
|
-
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
|
109
|
-
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9IjFh
|
110
|
-
YzIwNjVmLTAzZjAtNGM3YS1iOWE2LTkyZTgyMDU5MWJmMC5wbmciLz4KICA8bzpGaWxlIEhSZWY9
|
111
|
-
ImZpbGVsaXN0LnhtbCIvPgo8L3htbD4K
|
112
|
-
------=_NextPart_
|
113
|
-
Content-ID: <cb7b0d19-891e-4634-815a-570d019d454c.png>
|
114
|
-
Content-Disposition: inline; filename="cb7b0d19-891e-4634-815a-570d019d454c.png"
|
115
|
-
Content-Transfer-Encoding: base64
|
116
|
-
Content-Type: image/png
|
117
|
-
------=_NextPart_--
|
101
|
+
WORD_FTR3 = <<~FTR.freeze
|
102
|
+
------=_NextPart_
|
103
|
+
Content-ID: <filelist.xml>
|
104
|
+
Content-Disposition: inline; filename="filelist.xml"
|
105
|
+
Content-Transfer-Encoding: base64
|
106
|
+
Content-Type: #{Html2Doc::mime_type('filelist.xml')}
|
107
|
+
|
108
|
+
PHhtbCB4bWxuczpvPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpvZmZpY2UiPgog
|
109
|
+
ICAgICAgIDxvOk1haW5GaWxlIEhSZWY9Ii4uL3Rlc3QuaHRtIi8+ICA8bzpGaWxlIEhSZWY9IjFh
|
110
|
+
YzIwNjVmLTAzZjAtNGM3YS1iOWE2LTkyZTgyMDU5MWJmMC5wbmciLz4KICA8bzpGaWxlIEhSZWY9
|
111
|
+
ImZpbGVsaXN0LnhtbCIvPgo8L3htbD4K
|
112
|
+
------=_NextPart_
|
113
|
+
Content-ID: <cb7b0d19-891e-4634-815a-570d019d454c.png>
|
114
|
+
Content-Disposition: inline; filename="cb7b0d19-891e-4634-815a-570d019d454c.png"
|
115
|
+
Content-Transfer-Encoding: base64
|
116
|
+
Content-Type: image/png
|
117
|
+
------=_NextPart_--
|
118
118
|
FTR
|
119
119
|
|
120
|
-
HEADERHTML
|
121
|
-
<html xmlns:v="urn:schemas-microsoft-com:vml"
|
122
|
-
xmlns:o="urn:schemas-microsoft-com:office:office"
|
123
|
-
xmlns:w="urn:schemas-microsoft-com:office:word"
|
124
|
-
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
|
125
|
-
xmlns:mv="http://macVmlSchemaUri" xmlns="http://www.w3.org/TR/REC-html40">
|
126
|
-
<head>
|
127
|
-
<meta name=Title content="">
|
128
|
-
<meta name=Keywords content="">
|
129
|
-
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
|
130
|
-
<meta name=ProgId content=Word.Document>
|
131
|
-
<meta name=Generator content="Microsoft Word 15">
|
132
|
-
<meta name=Originator content="Microsoft Word 15">
|
133
|
-
<link id=Main-File rel=Main-File href="FILENAME.html">
|
134
|
-
<!--[if gte mso 9]><xml>
|
135
|
-
<o:shapedefaults v:ext="edit" spidmax="2049"/>
|
136
|
-
</xml><![endif]-->
|
137
|
-
</head>
|
138
|
-
<body lang=EN link=blue vlink="#954F72">
|
139
|
-
<div style='mso-element:footnote-separator' id=fs>
|
140
|
-
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
141
|
-
normal'><span lang=EN-GB><span style='mso-special-character:footnote-separator'><![if !supportFootnotes]>
|
142
|
-
<hr align=left size=1 width="33%">
|
143
|
-
<![endif]></span></span></p>
|
144
|
-
</div>
|
145
|
-
<div style='mso-element:footnote-continuation-separator' id=fcs>
|
146
|
-
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
147
|
-
normal'><span lang=EN-GB><span style='mso-special-character:footnote-continuation-separator'><![if !supportFootnotes]>
|
148
|
-
<hr align=left size=1>
|
149
|
-
<![endif]></span></span></p>
|
150
|
-
</div>
|
151
|
-
<div style='mso-element:endnote-separator' id=es>
|
152
|
-
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
153
|
-
normal'><span lang=EN-GB><span style='mso-special-character:footnote-separator'><![if !supportFootnotes]>
|
154
|
-
<hr align=left size=1 width="33%">
|
155
|
-
<![endif]></span></span></p>
|
156
|
-
</div>
|
157
|
-
<div style='mso-element:endnote-continuation-separator' id=ecs>
|
158
|
-
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
159
|
-
normal'><span lang=EN-GB><span style='mso-special-character:footnote-continuation-separator'><![if !supportFootnotes]>
|
160
|
-
<hr align=left size=1>
|
161
|
-
<![endif]></span></span></p>
|
162
|
-
</div>
|
163
|
-
<div style='mso-element:header' id=eh1>
|
164
|
-
<p class=MsoHeader align=left style='text-align:left;line-height:12.0pt;
|
165
|
-
mso-line-height-rule:exactly'><span lang=EN-GB>ISO/IEC&nbsp;CD 17301-1:2016(E)</span></p>
|
166
|
-
</div>
|
167
|
-
<div style='mso-element:header' id=h1>
|
168
|
-
<p class=MsoHeader style='margin-bottom:18.0pt'><span lang=EN-GB
|
169
|
-
style='font-size:10.0pt;mso-bidi-font-size:11.0pt;font-weight:normal'>©
|
170
|
-
ISO/IEC&nbsp;2016&nbsp;– All rights reserved</span><span lang=EN-GB
|
171
|
-
style='font-weight:normal'><o:p></o:p></span></p>
|
172
|
-
</div>
|
173
|
-
<div style='mso-element:footer' id=ef1>
|
174
|
-
<p class=MsoFooter style='margin-top:12.0pt;line-height:12.0pt;mso-line-height-rule:
|
175
|
-
exactly'><!--[if supportFields]><b style='mso-bidi-font-weight:normal'><span
|
176
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
177
|
-
style='mso-element:field-begin'></span><span
|
178
|
-
style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  
|
179
|
-
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span></b><![endif]--><b
|
180
|
-
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
181
|
-
mso-bidi-font-size:11.0pt'><span style='mso-no-proof:yes'>2</span></span></b><!--[if supportFields]><b
|
182
|
-
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
183
|
-
mso-bidi-font-size:11.0pt'><span style='mso-element:field-end'></span></span></b><![endif]--><span
|
184
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
185
|
-
style='mso-tab-count:1'>                                                                                                                                                                           </span>©
|
186
|
-
ISO/IEC&nbsp;2016&nbsp;– All rights reserved<o:p></o:p></span></p>
|
187
|
-
</div>
|
188
|
-
<div style='mso-element:header' id=eh2>
|
189
|
-
<p class=MsoHeader align=left style='text-align:left;line-height:12.0pt;
|
190
|
-
mso-line-height-rule:exactly'><span lang=EN-GB>ISO/IEC&nbsp;CD 17301-1:2016(E)</span></p>
|
191
|
-
</div>
|
192
|
-
<div style='mso-element:header' id=h2>
|
193
|
-
<p class=MsoHeader align=right style='text-align:right;line-height:12.0pt;
|
194
|
-
mso-line-height-rule:exactly'><span lang=EN-GB>ISO/IEC&nbsp;CD 17301-1:2016(E)</span></p>
|
195
|
-
</div>
|
196
|
-
<div style='mso-element:footer' id=ef2>
|
197
|
-
<p class=MsoFooter style='line-height:12.0pt;mso-line-height-rule:exactly'><!--[if supportFields]><span
|
198
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
199
|
-
style='mso-element:field-begin'></span><span
|
200
|
-
style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  
|
201
|
-
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span><![endif]--><span
|
202
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
203
|
-
style='mso-no-proof:yes'>ii</span></span><!--[if supportFields]><span
|
204
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
205
|
-
style='mso-element:field-end'></span></span><![endif]--><span lang=EN-GB
|
206
|
-
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span style='mso-tab-count:
|
207
|
-
1'>                                                                                                                                                                           </span>©
|
208
|
-
ISO/IEC&nbsp;2016&nbsp;– All rights reserved<o:p></o:p></span></p>
|
209
|
-
</div>
|
210
|
-
<div style='mso-element:footer' id=f2>
|
211
|
-
<p class=MsoFooter style='line-height:12.0pt'><span lang=EN-GB
|
212
|
-
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'>© ISO/IEC&nbsp;2016&nbsp;– All
|
213
|
-
rights reserved<span style='mso-tab-count:1'>                                                                                                                                                                          </span></span><!--[if supportFields]><span
|
214
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
215
|
-
style='mso-element:field-begin'></span> PAGE<span style='mso-spacerun:yes'>  
|
216
|
-
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span><![endif]--><span
|
217
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
218
|
-
style='mso-no-proof:yes'>iii</span></span><!--[if supportFields]><span
|
219
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
220
|
-
style='mso-element:field-end'></span></span><![endif]--><span lang=EN-GB
|
221
|
-
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><o:p></o:p></span></p>
|
222
|
-
</div>
|
223
|
-
<div style='mso-element:footer' id=ef3>
|
224
|
-
<p class=MsoFooter style='margin-top:12.0pt;line-height:12.0pt;mso-line-height-rule:
|
225
|
-
exactly'><!--[if supportFields]><b style='mso-bidi-font-weight:normal'><span
|
226
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
227
|
-
style='mso-element:field-begin'></span><span
|
228
|
-
style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  
|
229
|
-
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span></b><![endif]--><b
|
230
|
-
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
231
|
-
mso-bidi-font-size:11.0pt'><span style='mso-no-proof:yes'>2</span></span></b><!--[if supportFields]><b
|
232
|
-
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
233
|
-
mso-bidi-font-size:11.0pt'><span style='mso-element:field-end'></span></span></b><![endif]--><span
|
234
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
235
|
-
style='mso-tab-count:1'>                                                                                                                                                                           </span>©
|
236
|
-
ISO/IEC&nbsp;2016&nbsp;– All rights reserved<o:p></o:p></span></p>
|
237
|
-
</div>
|
238
|
-
<div style='mso-element:footer' id=f3>
|
239
|
-
<p class=MsoFooter style='line-height:12.0pt'><span lang=EN-GB
|
240
|
-
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'>© ISO/IEC&nbsp;2016&nbsp;– All
|
241
|
-
rights reserved<span style='mso-tab-count:1'>                                                                                                                                                                           </span></span><!--[if supportFields]><b
|
242
|
-
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
243
|
-
mso-bidi-font-size:11.0pt'><span style='mso-element:field-begin'></span>
|
244
|
-
PAGE<span style='mso-spacerun:yes'>   </span>\\* MERGEFORMAT <span
|
245
|
-
style='mso-element:field-separator'></span></span></b><![endif]--><b
|
246
|
-
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
247
|
-
mso-bidi-font-size:11.0pt'><span style='mso-no-proof:yes'>3</span></span></b><!--[if supportFields]><b
|
248
|
-
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
249
|
-
mso-bidi-font-size:11.0pt'><span style='mso-element:field-end'></span></span></b><![endif]--><span
|
250
|
-
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><o:p></o:p></span></p>
|
251
|
-
</div>
|
252
|
-
</body>
|
253
|
-
</html>
|
120
|
+
HEADERHTML = <<~FTR.freeze
|
121
|
+
<html xmlns:v="urn:schemas-microsoft-com:vml"
|
122
|
+
xmlns:o="urn:schemas-microsoft-com:office:office"
|
123
|
+
xmlns:w="urn:schemas-microsoft-com:office:word"
|
124
|
+
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
|
125
|
+
xmlns:mv="http://macVmlSchemaUri" xmlns="http://www.w3.org/TR/REC-html40">
|
126
|
+
<head>
|
127
|
+
<meta name=Title content="">
|
128
|
+
<meta name=Keywords content="">
|
129
|
+
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
|
130
|
+
<meta name=ProgId content=Word.Document>
|
131
|
+
<meta name=Generator content="Microsoft Word 15">
|
132
|
+
<meta name=Originator content="Microsoft Word 15">
|
133
|
+
<link id=Main-File rel=Main-File href="FILENAME.html">
|
134
|
+
<!--[if gte mso 9]><xml>
|
135
|
+
<o:shapedefaults v:ext="edit" spidmax="2049"/>
|
136
|
+
</xml><![endif]-->
|
137
|
+
</head>
|
138
|
+
<body lang=EN link=blue vlink="#954F72">
|
139
|
+
<div style='mso-element:footnote-separator' id=fs>
|
140
|
+
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
141
|
+
normal'><span lang=EN-GB><span style='mso-special-character:footnote-separator'><![if !supportFootnotes]>
|
142
|
+
<hr align=left size=1 width="33%">
|
143
|
+
<![endif]></span></span></p>
|
144
|
+
</div>
|
145
|
+
<div style='mso-element:footnote-continuation-separator' id=fcs>
|
146
|
+
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
147
|
+
normal'><span lang=EN-GB><span style='mso-special-character:footnote-continuation-separator'><![if !supportFootnotes]>
|
148
|
+
<hr align=left size=1>
|
149
|
+
<![endif]></span></span></p>
|
150
|
+
</div>
|
151
|
+
<div style='mso-element:endnote-separator' id=es>
|
152
|
+
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
153
|
+
normal'><span lang=EN-GB><span style='mso-special-character:footnote-separator'><![if !supportFootnotes]>
|
154
|
+
<hr align=left size=1 width="33%">
|
155
|
+
<![endif]></span></span></p>
|
156
|
+
</div>
|
157
|
+
<div style='mso-element:endnote-continuation-separator' id=ecs>
|
158
|
+
<p class=MsoNormal style='margin-bottom:0cm;margin-bottom:.0001pt;line-height:
|
159
|
+
normal'><span lang=EN-GB><span style='mso-special-character:footnote-continuation-separator'><![if !supportFootnotes]>
|
160
|
+
<hr align=left size=1>
|
161
|
+
<![endif]></span></span></p>
|
162
|
+
</div>
|
163
|
+
<div style='mso-element:header' id=eh1>
|
164
|
+
<p class=MsoHeader align=left style='text-align:left;line-height:12.0pt;
|
165
|
+
mso-line-height-rule:exactly'><span lang=EN-GB>ISO/IEC&nbsp;CD 17301-1:2016(E)</span></p>
|
166
|
+
</div>
|
167
|
+
<div style='mso-element:header' id=h1>
|
168
|
+
<p class=MsoHeader style='margin-bottom:18.0pt'><span lang=EN-GB
|
169
|
+
style='font-size:10.0pt;mso-bidi-font-size:11.0pt;font-weight:normal'>©
|
170
|
+
ISO/IEC&nbsp;2016&nbsp;– All rights reserved</span><span lang=EN-GB
|
171
|
+
style='font-weight:normal'><o:p></o:p></span></p>
|
172
|
+
</div>
|
173
|
+
<div style='mso-element:footer' id=ef1>
|
174
|
+
<p class=MsoFooter style='margin-top:12.0pt;line-height:12.0pt;mso-line-height-rule:
|
175
|
+
exactly'><!--[if supportFields]><b style='mso-bidi-font-weight:normal'><span
|
176
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
177
|
+
style='mso-element:field-begin'></span><span
|
178
|
+
style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  
|
179
|
+
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span></b><![endif]--><b
|
180
|
+
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
181
|
+
mso-bidi-font-size:11.0pt'><span style='mso-no-proof:yes'>2</span></span></b><!--[if supportFields]><b
|
182
|
+
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
183
|
+
mso-bidi-font-size:11.0pt'><span style='mso-element:field-end'></span></span></b><![endif]--><span
|
184
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
185
|
+
style='mso-tab-count:1'>                                                                                                                                                                           </span>©
|
186
|
+
ISO/IEC&nbsp;2016&nbsp;– All rights reserved<o:p></o:p></span></p>
|
187
|
+
</div>
|
188
|
+
<div style='mso-element:header' id=eh2>
|
189
|
+
<p class=MsoHeader align=left style='text-align:left;line-height:12.0pt;
|
190
|
+
mso-line-height-rule:exactly'><span lang=EN-GB>ISO/IEC&nbsp;CD 17301-1:2016(E)</span></p>
|
191
|
+
</div>
|
192
|
+
<div style='mso-element:header' id=h2>
|
193
|
+
<p class=MsoHeader align=right style='text-align:right;line-height:12.0pt;
|
194
|
+
mso-line-height-rule:exactly'><span lang=EN-GB>ISO/IEC&nbsp;CD 17301-1:2016(E)</span></p>
|
195
|
+
</div>
|
196
|
+
<div style='mso-element:footer' id=ef2>
|
197
|
+
<p class=MsoFooter style='line-height:12.0pt;mso-line-height-rule:exactly'><!--[if supportFields]><span
|
198
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
199
|
+
style='mso-element:field-begin'></span><span
|
200
|
+
style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  
|
201
|
+
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span><![endif]--><span
|
202
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
203
|
+
style='mso-no-proof:yes'>ii</span></span><!--[if supportFields]><span
|
204
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
205
|
+
style='mso-element:field-end'></span></span><![endif]--><span lang=EN-GB
|
206
|
+
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span style='mso-tab-count:
|
207
|
+
1'>                                                                                                                                                                           </span>©
|
208
|
+
ISO/IEC&nbsp;2016&nbsp;– All rights reserved<o:p></o:p></span></p>
|
209
|
+
</div>
|
210
|
+
<div style='mso-element:footer' id=f2>
|
211
|
+
<p class=MsoFooter style='line-height:12.0pt'><span lang=EN-GB
|
212
|
+
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'>© ISO/IEC&nbsp;2016&nbsp;– All
|
213
|
+
rights reserved<span style='mso-tab-count:1'>                                                                                                                                                                          </span></span><!--[if supportFields]><span
|
214
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
215
|
+
style='mso-element:field-begin'></span> PAGE<span style='mso-spacerun:yes'>  
|
216
|
+
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span><![endif]--><span
|
217
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
218
|
+
style='mso-no-proof:yes'>iii</span></span><!--[if supportFields]><span
|
219
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
220
|
+
style='mso-element:field-end'></span></span><![endif]--><span lang=EN-GB
|
221
|
+
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><o:p></o:p></span></p>
|
222
|
+
</div>
|
223
|
+
<div style='mso-element:footer' id=ef3>
|
224
|
+
<p class=MsoFooter style='margin-top:12.0pt;line-height:12.0pt;mso-line-height-rule:
|
225
|
+
exactly'><!--[if supportFields]><b style='mso-bidi-font-weight:normal'><span
|
226
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
227
|
+
style='mso-element:field-begin'></span><span
|
228
|
+
style='mso-spacerun:yes'> </span>PAGE<span style='mso-spacerun:yes'>  
|
229
|
+
</span>\\* MERGEFORMAT <span style='mso-element:field-separator'></span></span></b><![endif]--><b
|
230
|
+
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
231
|
+
mso-bidi-font-size:11.0pt'><span style='mso-no-proof:yes'>2</span></span></b><!--[if supportFields]><b
|
232
|
+
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
233
|
+
mso-bidi-font-size:11.0pt'><span style='mso-element:field-end'></span></span></b><![endif]--><span
|
234
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><span
|
235
|
+
style='mso-tab-count:1'>                                                                                                                                                                           </span>©
|
236
|
+
ISO/IEC&nbsp;2016&nbsp;– All rights reserved<o:p></o:p></span></p>
|
237
|
+
</div>
|
238
|
+
<div style='mso-element:footer' id=f3>
|
239
|
+
<p class=MsoFooter style='line-height:12.0pt'><span lang=EN-GB
|
240
|
+
style='font-size:10.0pt;mso-bidi-font-size:11.0pt'>© ISO/IEC&nbsp;2016&nbsp;– All
|
241
|
+
rights reserved<span style='mso-tab-count:1'>                                                                                                                                                                           </span></span><!--[if supportFields]><b
|
242
|
+
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
243
|
+
mso-bidi-font-size:11.0pt'><span style='mso-element:field-begin'></span>
|
244
|
+
PAGE<span style='mso-spacerun:yes'>   </span>\\* MERGEFORMAT <span
|
245
|
+
style='mso-element:field-separator'></span></span></b><![endif]--><b
|
246
|
+
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
247
|
+
mso-bidi-font-size:11.0pt'><span style='mso-no-proof:yes'>3</span></span></b><!--[if supportFields]><b
|
248
|
+
style='mso-bidi-font-weight:normal'><span lang=EN-GB style='font-size:10.0pt;
|
249
|
+
mso-bidi-font-size:11.0pt'><span style='mso-element:field-end'></span></span></b><![endif]--><span
|
250
|
+
lang=EN-GB style='font-size:10.0pt;mso-bidi-font-size:11.0pt'><o:p></o:p></span></p>
|
251
|
+
</div>
|
252
|
+
</body>
|
253
|
+
</html>
|
254
254
|
FTR
|
255
255
|
|
256
|
-
ASCII_MATH='<m:nary><m:naryPr><m:chr m:val="∑"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><m:r><m:t>=</m:t></m:r><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>'
|
256
|
+
ASCII_MATH = '<m:nary><m:naryPr><m:chr m:val="∑"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><m:r><m:t>=</m:t></m:r><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>'.freeze
|
257
257
|
|
258
|
-
DEFAULT_STYLESHEET = File.read("lib/html2doc/wordstyle.css",
|
258
|
+
DEFAULT_STYLESHEET = File.read("lib/html2doc/wordstyle.css",
|
259
|
+
encoding: "utf-8").freeze
|
259
260
|
|
260
|
-
def guid_clean(
|
261
|
-
|
261
|
+
def guid_clean(xml)
|
262
|
+
xml.gsub(/NextPart_[0-9a-f.]+/, "NextPart_")
|
262
263
|
end
|
263
264
|
|
264
|
-
def image_clean(
|
265
|
-
|
266
|
-
gsub(%r{[0-9a-f-]+\.gif}, "image.gif")
|
267
|
-
gsub(%r{[0-9a-f-]+\.(jpeg|jpg)}, "image.jpg")
|
268
|
-
gsub(%r{------=_NextPart_\s+Content-Location: file:///C:/Doc/test_files/image\.(png|gif).*?\s-----=_NextPart_}m, "------=_NextPart_")
|
269
|
-
gsub(%r{Content-Type: image/(png|gif|jpeg)[^-]*------=_NextPart_-?-?}m, "")
|
270
|
-
gsub(%r{ICAgICAg[^-]*-----}m, "-----")
|
271
|
-
gsub(%r{\s*</img>\s*}m, "</img>")
|
272
|
-
gsub(%r{</body>\s*</html>}m, "</body></html>")
|
265
|
+
def image_clean(xml)
|
266
|
+
xml.gsub(%r{[0-9a-f-]+\.png}, "image.png")
|
267
|
+
.gsub(%r{[0-9a-f-]+\.gif}, "image.gif")
|
268
|
+
.gsub(%r{[0-9a-f-]+\.(jpeg|jpg)}, "image.jpg")
|
269
|
+
.gsub(%r{------=_NextPart_\s+Content-Location: file:///C:/Doc/test_files/image\.(png|gif).*?\s-----=_NextPart_}m, "------=_NextPart_")
|
270
|
+
.gsub(%r{Content-Type: image/(png|gif|jpeg)[^-]*------=_NextPart_-?-?}m, "")
|
271
|
+
.gsub(%r{ICAgICAg[^-]*-----}m, "-----")
|
272
|
+
.gsub(%r{\s*</img>\s*}m, "</img>")
|
273
|
+
.gsub(%r{</body>\s*</html>}m, "</body></html>")
|
273
274
|
end
|
274
275
|
|
275
276
|
RSpec.describe Html2Doc do
|
@@ -279,11 +280,11 @@ RSpec.describe Html2Doc do
|
|
279
280
|
|
280
281
|
it "processes a blank document" do
|
281
282
|
Html2Doc.process(html_input(""), filename: "test")
|
282
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
283
|
-
to match_fuzzy(<<~OUTPUT)
|
284
|
-
|
285
|
-
|
286
|
-
|
283
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
284
|
+
.to match_fuzzy(<<~OUTPUT)
|
285
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
286
|
+
#{word_body('', '<div style="mso-element:footnote-list"/>')} #{WORD_FTR1}
|
287
|
+
OUTPUT
|
287
288
|
end
|
288
289
|
|
289
290
|
it "removes any temp files" do
|
@@ -295,54 +296,67 @@ RSpec.describe Html2Doc do
|
|
295
296
|
end
|
296
297
|
|
297
298
|
it "processes a stylesheet in an HTML document with a title" do
|
298
|
-
Html2Doc.process(html_input(""),
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
299
|
+
Html2Doc.process(html_input(""),
|
300
|
+
filename: "test", stylesheet: "lib/html2doc/wordstyle.css")
|
301
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
302
|
+
.to match_fuzzy(<<~OUTPUT)
|
303
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
304
|
+
#{word_body('', '<div style="mso-element:footnote-list"/>')} #{WORD_FTR1}
|
305
|
+
OUTPUT
|
304
306
|
end
|
305
307
|
|
306
308
|
it "processes a stylesheet in an HTML document without a title" do
|
307
|
-
Html2Doc.process(html_input_no_title(""),
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
309
|
+
Html2Doc.process(html_input_no_title(""),
|
310
|
+
filename: "test", stylesheet: "lib/html2doc/wordstyle.css")
|
311
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
312
|
+
.to match_fuzzy(<<~OUTPUT)
|
313
|
+
#{WORD_HDR.sub('<title>blank</title>', '')}
|
314
|
+
#{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
315
|
+
#{word_body('', '<div style="mso-element:footnote-list"/>')} #{WORD_FTR1}
|
316
|
+
OUTPUT
|
314
317
|
end
|
315
318
|
|
316
319
|
it "processes a stylesheet in an HTML document with an empty head" do
|
317
|
-
Html2Doc.process(html_input_empty_head(""),
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
320
|
+
Html2Doc.process(html_input_empty_head(""),
|
321
|
+
filename: "test", stylesheet: "lib/html2doc/wordstyle.css")
|
322
|
+
word_hdr_end = WORD_HDR_END
|
323
|
+
.sub(%(<meta name="Originator" content="Me"/>\n), "")
|
324
|
+
.sub("</style>\n</head>", "</style></head>")
|
325
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
326
|
+
.to match_fuzzy(<<~OUTPUT)
|
327
|
+
#{WORD_HDR.sub('<title>blank</title>', '')}
|
328
|
+
#{DEFAULT_STYLESHEET}
|
329
|
+
#{word_hdr_end}
|
330
|
+
#{word_body('', '<div style="mso-element:footnote-list"/>')} #{WORD_FTR1}
|
331
|
+
OUTPUT
|
325
332
|
end
|
326
333
|
|
327
334
|
it "processes a header" do
|
328
|
-
Html2Doc.process(html_input(""),
|
335
|
+
Html2Doc.process(html_input(""),
|
336
|
+
filename: "test", header_file: "spec/header.html")
|
329
337
|
html = guid_clean(File.read("test.doc", encoding: "utf-8"))
|
330
|
-
hdr = Base64.decode64(
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
expect(
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
338
|
+
hdr = Base64.decode64(
|
339
|
+
html
|
340
|
+
.sub(%r{^.*Content-Location: file:///C:/Doc/test_files/header.html}, "")
|
341
|
+
.sub(%r{^.*Content-Type: text/html charset="utf-8"}m, "")
|
342
|
+
.sub(%r{------=_NextPart_--.*$}m, ""),
|
343
|
+
).force_encoding("UTF-8")
|
344
|
+
# expect(hdr.gsub(/\xa0/, " ")).to match_fuzzy(HEADERHTML)
|
345
|
+
expect(HTMLEntities.new.encode(hdr, :hexadecimal)
|
346
|
+
.gsub(/</, "<").gsub(/>/, ">")
|
347
|
+
.gsub(/'/, "'").gsub(/"/, '"')
|
348
|
+
.gsub(/
/, "
").gsub(/
/, "\n"))
|
349
|
+
.to match_fuzzy(HEADERHTML)
|
350
|
+
expect(html.sub(%r{Content-ID: <header.html>.*$}m, ""))
|
351
|
+
.to match_fuzzy(<<~OUTPUT)
|
352
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET.gsub(/url\("[^"]+"\)/, 'url(cid:header.html)')}
|
353
|
+
#{WORD_HDR_END} #{word_body('', '<div style="mso-element:footnote-list"/>')} #{WORD_FTR2}
|
354
|
+
OUTPUT
|
342
355
|
end
|
343
356
|
|
344
357
|
it "processes a header with an image" do
|
345
|
-
Html2Doc.process(html_input(""),
|
358
|
+
Html2Doc.process(html_input(""),
|
359
|
+
filename: "test", header_file: "spec/header_img.html")
|
346
360
|
doc = guid_clean(File.read("test.doc", encoding: "utf-8"))
|
347
361
|
expect(doc).to match(%r{Content-Type: image/png})
|
348
362
|
expect(doc).to match(%r{iVBORw0KGgoAAAANSUhEUgAAA5cAAAN7CAYAAADRE24cAAAgAElEQVR4XuydB5gUxdaGC65gTogB})
|
@@ -351,158 +365,174 @@ RSpec.describe Html2Doc do
|
|
351
365
|
it "processes a header with an image with absolute path" do
|
352
366
|
doc = File.read("spec/header_img.html", encoding: "utf-8")
|
353
367
|
File.open("spec/header_img1.html", "w:UTF-8") do |f|
|
354
|
-
f.write
|
368
|
+
f.write(
|
369
|
+
doc.sub(%r{spec/19160-6.png},
|
370
|
+
File.expand_path(File.join(File.dirname(__FILE__), "19160-6.png"))),
|
371
|
+
)
|
355
372
|
end
|
356
|
-
Html2Doc.process(html_input(""),
|
373
|
+
Html2Doc.process(html_input(""),
|
374
|
+
filename: "test", header_file: "spec/header_img1.html")
|
357
375
|
doc = guid_clean(File.read("test.doc", encoding: "utf-8"))
|
358
376
|
expect(doc).to match(%r{Content-Type: image/png})
|
359
377
|
expect(doc).to match(%r{iVBORw0KGgoAAAANSUhEUgAAA5cAAAN7CAYAAADRE24cAAAgAElEQVR4XuydB5gUxdaGC65gTogB})
|
360
378
|
end
|
361
379
|
|
362
|
-
|
363
380
|
it "processes a populated document" do
|
364
381
|
simple_body = "<h1>Hello word!</h1>
|
365
382
|
<div>This is a very simple document</div>"
|
366
383
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
367
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
368
|
-
to match_fuzzy(<<~OUTPUT)
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
384
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
385
|
+
.to match_fuzzy(<<~OUTPUT)
|
386
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
387
|
+
#{word_body(simple_body, '<div style="mso-element:footnote-list"/>')}
|
388
|
+
#{WORD_FTR1}
|
389
|
+
OUTPUT
|
373
390
|
end
|
374
391
|
|
375
392
|
it "processes AsciiMath" do
|
376
|
-
Html2Doc.process(html_input(%[<div>{{sum_(i=1)^n i^3=((n(n+1))/2)^2 text("integer"))}}</div>]),
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
393
|
+
Html2Doc.process(html_input(%[<div>{{sum_(i=1)^n i^3=((n(n+1))/2)^2 text("integer"))}}</div>]),
|
394
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
395
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
396
|
+
.to match_fuzzy(<<~OUTPUT)
|
397
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
398
|
+
#{word_body(%{
|
399
|
+
<div><m:oMath>
|
400
|
+
<m:nary><m:naryPr><m:chr m:val="∑"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t>"integer"</m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span>
|
401
|
+
</m:oMath>
|
402
|
+
</div>}, '<div style="mso-element:footnote-list"/>')}
|
403
|
+
#{WORD_FTR1}
|
404
|
+
OUTPUT
|
405
|
+
end
|
406
|
+
|
407
|
+
it "processes mstyle" do
|
408
|
+
Html2Doc.process(html_input(%[<div>{{bb (-log_2 (p_u)) bb "BB" bbb "BBB" cc "CC" bcc "BCC" tt "TT" fr "FR" bfr "BFR" sf "SF" bsf "BSFα" sfi "SFI" sfbi "SFBIα" bii "BII" ii "II"}}</div>]),
|
409
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
410
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
411
|
+
.to match_fuzzy(<<~OUTPUT)
|
412
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
413
|
+
#{word_body(%{
|
414
|
+
<div><m:oMath>
|
415
|
+
<span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>−</m:t></m:r></span><m:sSub><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>log</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>2</m:t></m:r></span></m:sub></m:sSub><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:sSub><m:e><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>p</m:t></m:r></span></m:e><m:sub><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:sty m:val="b"></m:sty></m:rPr><m:t>u</m:t></m:r></span></m:sub></m:sSub></m:e></m:d><span style="font-style:normal;font-weight:bold;"><m:r><m:rPr><m:nor></m:nor><m:sty m:val="b"></m:sty></m:rPr><m:t>BB</m:t></m:r></span><m:r><m:rPr><m:nor></m:nor><m:scr m:val="double-struck"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>𝔹𝔹𝔹</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr></m:rPr><m:t>𝒞𝒞</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="script"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>𝓑𝓒𝓒</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="monospace"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>𝚃𝚃</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>𝔉ℜ</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="fraktur"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>𝕭𝕱𝕽</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="p"></m:sty></m:rPr><m:t>𝖲𝖥</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="b"></m:sty></m:rPr><m:t>𝗕𝗦𝗙𝝰</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr></m:rPr><m:t>𝖲𝖥𝖨</m:t></m:r><m:r><m:rPr><m:nor></m:nor><m:scr m:val="sans-serif"></m:scr><m:sty m:val="bi"></m:sty></m:rPr><m:t>𝙎𝙁𝘽𝙄𝞪</m:t></m:r><span class="nostem" style="font-weight:bold;"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="bi"></m:sty></m:rPr><m:t>BII</m:t></m:r></span><span class="nostem"><em></em><m:r><m:rPr><m:nor></m:nor><m:sty m:val="i"></m:sty></m:rPr><m:t>II</m:t></m:r></span>
|
416
|
+
</m:oMath>
|
417
|
+
</div>}, '<div style="mso-element:footnote-list"/>')}
|
418
|
+
#{WORD_FTR1}
|
419
|
+
OUTPUT
|
401
420
|
end
|
402
421
|
|
403
422
|
it "processes spaces in AsciiMath" do
|
404
|
-
Html2Doc.process(html_input(%[<div>{{text " integer ")}}</div>]),
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
423
|
+
Html2Doc.process(html_input(%[<div>{{text " integer ")}}</div>]),
|
424
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
425
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
426
|
+
.to match_fuzzy(<<~OUTPUT)
|
427
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
428
|
+
#{word_body('
|
429
|
+
<div><m:oMath>
|
430
|
+
<m:r><m:t>text</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t> integer </m:t></m:r><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>)</m:t></m:r></span>
|
431
|
+
</m:oMath>
|
432
|
+
</div>', '<div style="mso-element:footnote-list"/>')}
|
433
|
+
#{WORD_FTR1}
|
434
|
+
OUTPUT
|
415
435
|
end
|
416
436
|
|
417
437
|
it "processes spaces in MathML mtext" do
|
418
438
|
Html2Doc.process(html_input("<div><math xmlns='http://www.w3.org/1998/Math/MathML'>
|
419
439
|
<mrow><mi>H</mi><mtext> original </mtext><mi>J</mi></mrow>
|
420
|
-
</math></div>"),
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
440
|
+
</math></div>"),
|
441
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
442
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
443
|
+
.to match_fuzzy(<<~OUTPUT)
|
444
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
445
|
+
#{word_body('<div><m:oMath>
|
446
|
+
<m:r><m:t>H</m:t></m:r><m:r><m:rPr><m:nor></m:nor></m:rPr><m:t> original </m:t></m:r><m:r><m:t>J</m:t></m:r>
|
447
|
+
</m:oMath>
|
448
|
+
</div>', '<div style="mso-element:footnote-list"/>')}
|
449
|
+
#{WORD_FTR1}
|
450
|
+
OUTPUT
|
430
451
|
end
|
431
452
|
|
432
453
|
it "unwraps accent in MathML" do
|
433
454
|
Html2Doc.process(html_input("<div><math xmlns='http://www.w3.org/1998/Math/MathML'>
|
434
455
|
<mover accent='true'><mrow><mi>p</mi></mrow><mrow><mo>^</mo></mrow></mover>
|
435
456
|
</math></div>"), filename: "test", asciimathdelims: ["{{", "}}"])
|
436
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
437
|
-
to match_fuzzy(<<~OUTPUT)
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
457
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
458
|
+
.to match_fuzzy(<<~OUTPUT)
|
459
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
460
|
+
#{word_body('<div><m:oMath>
|
461
|
+
<m:acc><m:accPr><m:chr m:val="^"></m:chr></m:accPr><m:e><m:r><m:t>p</m:t></m:r></m:e></m:acc>
|
462
|
+
</m:oMath>
|
463
|
+
</div>', '<div style="mso-element:footnote-list"/>')}
|
464
|
+
#{WORD_FTR1}
|
465
|
+
OUTPUT
|
445
466
|
end
|
446
467
|
|
447
468
|
it "left-aligns AsciiMath" do
|
448
|
-
Html2Doc.process(html_input("<div style='text-align:left;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"),
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
469
|
+
Html2Doc.process(html_input("<div style='text-align:left;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"),
|
470
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
471
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
472
|
+
.to match_fuzzy(<<~OUTPUT)
|
473
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
474
|
+
#{word_body(%{
|
475
|
+
<div style="text-align:left;"><m:oMathPara><m:oMathParaPr><m:jc m:val="left"/></m:oMathParaPr><m:oMath>
|
476
|
+
<m:nary><m:naryPr><m:chr m:val="∑"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
|
477
|
+
</m:oMath>
|
478
|
+
</m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
|
479
|
+
#{WORD_FTR1}
|
480
|
+
OUTPUT
|
459
481
|
end
|
460
482
|
|
461
483
|
it "right-aligns AsciiMath" do
|
462
|
-
Html2Doc.process(html_input("<div style='text-align:right;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"),
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
484
|
+
Html2Doc.process(html_input("<div style='text-align:right;'>{{sum_(i=1)^n i^3=((n(n+1))/2)^2}}</div>"),
|
485
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
486
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
487
|
+
.to match_fuzzy(<<~OUTPUT)
|
488
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
489
|
+
#{word_body(%{
|
490
|
+
<div style="text-align:right;"><m:oMathPara><m:oMathParaPr><m:jc m:val="right"/></m:oMathParaPr><m:oMath>
|
491
|
+
<m:nary><m:naryPr><m:chr m:val="∑"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=1</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>i</m:t></m:r></m:e><m:sup><m:r><m:t>3</m:t></m:r></m:sup></m:sSup></m:e></m:nary><span style="font-style:normal;"><m:r><m:rPr><m:sty m:val="p"></m:sty></m:rPr><m:t>=</m:t></m:r></span><m:sSup><m:e><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:f><m:fPr><m:type m:val="bar"></m:type></m:fPr><m:num><m:r><m:t>n</m:t></m:r><m:d><m:dPr><m:sepChr m:val=","></m:sepChr></m:dPr><m:e><m:r><m:t>n+1</m:t></m:r></m:e></m:d></m:num><m:den><m:r><m:t>2</m:t></m:r></m:den></m:f></m:e></m:d></m:e><m:sup><m:r><m:t>2</m:t></m:r></m:sup></m:sSup>
|
492
|
+
</m:oMath>
|
493
|
+
</m:oMathPara></div>}, '<div style="mso-element:footnote-list"/>')}
|
494
|
+
#{WORD_FTR1}
|
495
|
+
OUTPUT
|
473
496
|
end
|
474
497
|
|
475
498
|
it "raises error in processing of broken AsciiMath" do
|
476
499
|
begin
|
477
|
-
|
500
|
+
expect do
|
501
|
+
Html2Doc.process(html_input(%[<div style='text-align:right;'>{{u_c = 6.6"unitsml(kHz)}}</div>]),
|
502
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
503
|
+
end.to output('parsing: u_c = 6.6"unitsml(kHz)').to_stderr
|
478
504
|
rescue StandardError
|
479
505
|
end
|
480
|
-
expect
|
506
|
+
expect do
|
507
|
+
Html2Doc.process(html_input(%[<div style='text-align:right;'>{{u_c = 6.6"unitsml(kHz)}}</div>]),
|
508
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
509
|
+
end.to raise_error(StandardError)
|
481
510
|
end
|
482
511
|
|
483
512
|
it "wraps msup after munderover in MathML" do
|
484
513
|
Html2Doc.process(html_input("<div><math xmlns='http://www.w3.org/1998/Math/MathML'>
|
485
|
-
<munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow><mi>n</mi></mrow></munderover><msup><mn>2</mn><mrow><mi>i</mi></mrow></msup></math></div>"),
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
514
|
+
<munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>0</mn></mrow><mrow><mi>n</mi></mrow></munderover><msup><mn>2</mn><mrow><mi>i</mi></mrow></msup></math></div>"),
|
515
|
+
filename: "test", asciimathdelims: ["{{", "}}"])
|
516
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
517
|
+
.to match_fuzzy(<<~OUTPUT)
|
518
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
519
|
+
#{word_body('<div><m:oMath>
|
520
|
+
<m:nary><m:naryPr><m:chr m:val="∑"></m:chr><m:limLoc m:val="undOvr"></m:limLoc><m:grow m:val="on"></m:grow><m:subHide m:val="off"></m:subHide><m:supHide m:val="off"></m:supHide></m:naryPr><m:sub><m:r><m:t>i=0</m:t></m:r></m:sub><m:sup><m:r><m:t>n</m:t></m:r></m:sup><m:e><m:sSup><m:e><m:r><m:t>2</m:t></m:r></m:e><m:sup><m:r><m:t>i</m:t></m:r></m:sup></m:sSup></m:e></m:nary></m:oMath>
|
521
|
+
</div>', '<div style="mso-element:footnote-list"/>')}
|
522
|
+
#{WORD_FTR1}
|
523
|
+
OUTPUT
|
494
524
|
end
|
495
525
|
|
496
526
|
it "processes tabs" do
|
497
527
|
simple_body = "<h1>Hello word!</h1>
|
498
528
|
<div>This is a very &tab; simple document</div>"
|
499
529
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
500
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
501
|
-
to match_fuzzy(<<~OUTPUT)
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
530
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
531
|
+
.to match_fuzzy(<<~OUTPUT)
|
532
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
533
|
+
#{word_body(simple_body.gsub(/&tab;/, %[<span style="mso-tab-count:1">  </span>]), '<div style="mso-element:footnote-list"/>')}
|
534
|
+
#{WORD_FTR1}
|
535
|
+
OUTPUT
|
506
536
|
end
|
507
537
|
|
508
538
|
it "makes unstyled paragraphs be MsoNormal" do
|
@@ -510,12 +540,12 @@ RSpec.describe Html2Doc do
|
|
510
540
|
<p>This is a very simple document</p>
|
511
541
|
<p class="x">This style stays</p>'
|
512
542
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
513
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
514
|
-
to match_fuzzy(<<~OUTPUT)
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
543
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
544
|
+
.to match_fuzzy(<<~OUTPUT)
|
545
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
546
|
+
#{word_body(simple_body.gsub(/<p>/, %[<p class="MsoNormal">]), '<div style="mso-element:footnote-list"/>')}
|
547
|
+
#{WORD_FTR1}
|
548
|
+
OUTPUT
|
519
549
|
end
|
520
550
|
|
521
551
|
it "makes unstyled list entries be MsoNormal" do
|
@@ -525,12 +555,12 @@ RSpec.describe Html2Doc do
|
|
525
555
|
<li class="x">This style stays</li>
|
526
556
|
</ul>'
|
527
557
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
528
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
529
|
-
to match_fuzzy(<<~OUTPUT)
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
558
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
559
|
+
.to match_fuzzy(<<~OUTPUT)
|
560
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
561
|
+
#{word_body(simple_body.gsub(/<li>/, %[<li class="MsoNormal">]), '<div style="mso-element:footnote-list"/>')}
|
562
|
+
#{WORD_FTR1}
|
563
|
+
OUTPUT
|
534
564
|
end
|
535
565
|
|
536
566
|
it "resizes images for height, in a file in a subdirectory" do
|
@@ -539,9 +569,9 @@ RSpec.describe Html2Doc do
|
|
539
569
|
testdoc = File.read("spec/test.doc", encoding: "utf-8")
|
540
570
|
expect(testdoc).to match(%r{Content-Type: image/png})
|
541
571
|
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
|
542
|
-
|
543
|
-
|
544
|
-
|
572
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
573
|
+
#{image_clean(word_body('<img src="cid:cb7b0d19-891e-4634-815a-570d019d454c.png" width="400" height="388"></img>', '<div style="mso-element:footnote-list"/>'))}
|
574
|
+
#{image_clean(WORD_FTR3)}
|
545
575
|
OUTPUT
|
546
576
|
end
|
547
577
|
|
@@ -551,9 +581,9 @@ RSpec.describe Html2Doc do
|
|
551
581
|
testdoc = File.read("test.doc", encoding: "utf-8")
|
552
582
|
expect(testdoc).to match(%r{Content-Type: image/gif})
|
553
583
|
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
|
554
|
-
|
555
|
-
|
556
|
-
|
584
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
585
|
+
#{image_clean(word_body('<img src="cid:cb7b0d19-891e-4634-815a-570d019d454c.gif" width="400" height="118"></img>', '<div style="mso-element:footnote-list"/>'))}
|
586
|
+
#{image_clean(WORD_FTR3).gsub(/image\.png/, 'image.gif')}
|
557
587
|
OUTPUT
|
558
588
|
end
|
559
589
|
|
@@ -563,41 +593,51 @@ RSpec.describe Html2Doc do
|
|
563
593
|
testdoc = File.read("test.doc", encoding: "utf-8")
|
564
594
|
expect(testdoc).to match(%r{Content-Type: image/jpeg})
|
565
595
|
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
|
566
|
-
|
567
|
-
|
568
|
-
|
596
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
597
|
+
#{image_clean(word_body('<img src="cid:cb7b0d19-891e-4634-815a-570d019d454c.jpg" width="208" height="680"></img>', '<div style="mso-element:footnote-list"/>'))}
|
598
|
+
#{image_clean(WORD_FTR3).gsub(/image\.png/, 'image.jpg')}
|
569
599
|
OUTPUT
|
570
600
|
end
|
571
601
|
|
572
602
|
it "resizes images with missing or auto sizes" do
|
573
603
|
image = { "src" => "spec/19160-8.jpg" }
|
574
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
604
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
605
|
+
.to eq [30, 100]
|
575
606
|
image["width"] = "20"
|
576
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
607
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
608
|
+
.to eq [20, 65]
|
577
609
|
image.delete("width")
|
578
610
|
image["height"] = "50"
|
579
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
611
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
612
|
+
.to eq [15, 50]
|
580
613
|
image.delete("height")
|
581
614
|
image["width"] = "500"
|
582
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
615
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
616
|
+
.to eq [30, 100]
|
583
617
|
image.delete("width")
|
584
618
|
image["height"] = "500"
|
585
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
619
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
620
|
+
.to eq [30, 100]
|
586
621
|
image["width"] = "20"
|
587
622
|
image["height"] = "auto"
|
588
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
623
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
624
|
+
.to eq [20, 65]
|
589
625
|
image["width"] = "auto"
|
590
626
|
image["height"] = "50"
|
591
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
627
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
628
|
+
.to eq [15, 50]
|
592
629
|
image["width"] = "500"
|
593
630
|
image["height"] = "auto"
|
594
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
631
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
632
|
+
.to eq [30, 100]
|
595
633
|
image["width"] = "auto"
|
596
634
|
image["height"] = "500"
|
597
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
635
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
636
|
+
.to eq [30, 100]
|
598
637
|
image["width"] = "auto"
|
599
638
|
image["height"] = "auto"
|
600
|
-
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
639
|
+
expect(Html2Doc.image_resize(image, "spec/19160-8.jpg", 100, 100))
|
640
|
+
.to eq [30, 100]
|
601
641
|
end
|
602
642
|
|
603
643
|
it "does not move images if they are external URLs" do
|
@@ -605,49 +645,48 @@ RSpec.describe Html2Doc do
|
|
605
645
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
606
646
|
testdoc = File.read("test.doc", encoding: "utf-8")
|
607
647
|
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
|
608
|
-
|
609
|
-
|
610
|
-
|
648
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
649
|
+
#{image_clean(word_body('<img src="https://example.com/19160-6.png"></img>', '<div style="mso-element:footnote-list"/>'))}
|
650
|
+
#{image_clean(WORD_FTR1)}
|
611
651
|
OUTPUT
|
612
652
|
end
|
613
653
|
|
614
654
|
it "deals with absolute image locations" do
|
615
|
-
simple_body = %{<img src="#{
|
655
|
+
simple_body = %{<img src="#{__dir__}/19160-6.png">}
|
616
656
|
Html2Doc.process(html_input(simple_body), filename: "spec/test")
|
617
657
|
testdoc = File.read("spec/test.doc", encoding: "utf-8")
|
618
658
|
expect(testdoc).to match(%r{Content-Type: image/png})
|
619
659
|
expect(image_clean(guid_clean(testdoc))).to match_fuzzy(<<~OUTPUT)
|
620
|
-
|
621
|
-
|
622
|
-
|
660
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
661
|
+
#{image_clean(word_body('<img src="cid:cb7b0d19-891e-4634-815a-570d019d454c.png" width="400" height="388"></img>', '<div style="mso-element:footnote-list"/>'))}
|
662
|
+
#{image_clean(WORD_FTR3)}
|
623
663
|
OUTPUT
|
624
664
|
end
|
625
665
|
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
end
|
631
|
-
=end
|
666
|
+
# it "warns about SVG" do
|
667
|
+
# simple_body = '<img src="https://example.com/19160-6.svg">'
|
668
|
+
# expect{ Html2Doc.process(html_input(simple_body), filename: "test") }
|
669
|
+
# .to output("https://example.com/19160-6.svg: SVG not supported\n").to_stderr
|
670
|
+
# end
|
632
671
|
|
633
672
|
it "processes epub:type footnotes" do
|
634
|
-
simple_body = '<div>This is a very simple
|
673
|
+
simple_body = '<div>This is a very simple
|
635
674
|
document<a epub:type="footnote" href="#a1">1</a> allegedly<a epub:type="footnote" href="#a2">2</a></div>
|
636
675
|
<aside id="a1">Footnote</aside>
|
637
676
|
<aside id="a2">Other Footnote</aside>'
|
638
677
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
639
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
640
|
-
to match_fuzzy(<<~OUTPUT)
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
|
646
|
-
<div style="mso-element:footnote" id="ftn2">
|
647
|
-
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
648
|
-
</div>')}
|
649
|
-
|
650
|
-
|
678
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
679
|
+
.to match_fuzzy(<<~OUTPUT)
|
680
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
681
|
+
#{word_body('<div>This is a very simple
|
682
|
+
document<a epub:type="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a epub:type="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
|
683
|
+
'<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
|
684
|
+
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
|
685
|
+
<div style="mso-element:footnote" id="ftn2">
|
686
|
+
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
687
|
+
</div>')}
|
688
|
+
#{WORD_FTR1}
|
689
|
+
OUTPUT
|
651
690
|
end
|
652
691
|
|
653
692
|
it "processes class footnotes" do
|
@@ -656,38 +695,38 @@ RSpec.describe Html2Doc do
|
|
656
695
|
<aside id="a1">Footnote</aside>
|
657
696
|
<aside id="a2">Other Footnote</aside>'
|
658
697
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
659
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
660
|
-
to match_fuzzy(<<~OUTPUT)
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
|
666
|
-
<div style="mso-element:footnote" id="ftn2">
|
667
|
-
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
668
|
-
</div>')}
|
669
|
-
|
670
|
-
|
698
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
699
|
+
.to match_fuzzy(<<~OUTPUT)
|
700
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
701
|
+
#{word_body('<div>This is a very simple
|
702
|
+
document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
|
703
|
+
'<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
|
704
|
+
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
|
705
|
+
<div style="mso-element:footnote" id="ftn2">
|
706
|
+
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
707
|
+
</div>')}
|
708
|
+
#{WORD_FTR1}
|
709
|
+
OUTPUT
|
671
710
|
end
|
672
711
|
|
673
712
|
it "processes footnotes with text wrapping the footnote reference" do
|
674
|
-
|
713
|
+
simple_body = '<div>This is a very simple
|
675
714
|
document<a class="footnote" href="#a1">(<span class="MsoFootnoteReference">1</span>)</a> allegedly<a class="footnote" href="#a2">2</a></div>
|
676
715
|
<aside id="a1">Footnote</aside>
|
677
716
|
<aside id="a2">Other Footnote</aside>'
|
678
717
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
679
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
680
|
-
to match_fuzzy(<<~OUTPUT)
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference">(</span><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span><span class="MsoFootnoteReference">)</span></a>Footnote</p></div>
|
686
|
-
<div style="mso-element:footnote" id="ftn2">
|
687
|
-
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
688
|
-
</div>')}
|
689
|
-
|
690
|
-
|
718
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
719
|
+
.to match_fuzzy(<<~OUTPUT)
|
720
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
721
|
+
#{word_body('<div>This is a very simple
|
722
|
+
document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference">(</span><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span><span class="MsoFootnoteReference">)</span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
|
723
|
+
'<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
|
724
|
+
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference">(</span><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span><span class="MsoFootnoteReference">)</span></a>Footnote</p></div>
|
725
|
+
<div style="mso-element:footnote" id="ftn2">
|
726
|
+
<p id="" class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
727
|
+
</div>')}
|
728
|
+
#{WORD_FTR1}
|
729
|
+
OUTPUT
|
691
730
|
end
|
692
731
|
|
693
732
|
it "extracts paragraphs from footnotes" do
|
@@ -696,18 +735,18 @@ RSpec.describe Html2Doc do
|
|
696
735
|
<aside id="a1"><p>Footnote</p></aside>
|
697
736
|
<div id="a2"><p>Other Footnote</p></div>'
|
698
737
|
Html2Doc.process(html_input(simple_body), filename: "test")
|
699
|
-
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
700
|
-
to match_fuzzy(<<~OUTPUT)
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
<p class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
|
706
|
-
<div style="mso-element:footnote" id="ftn2">
|
707
|
-
<p class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
708
|
-
</div>')}
|
709
|
-
|
710
|
-
|
738
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
739
|
+
.to match_fuzzy(<<~OUTPUT)
|
740
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
741
|
+
#{word_body('<div>This is a very simple
|
742
|
+
document<a class="footnote" href="#_ftn1" style="mso-footnote-id:ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a> allegedly<a class="footnote" href="#_ftn2" style="mso-footnote-id:ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a></div>',
|
743
|
+
'<div style="mso-element:footnote-list"><div style="mso-element:footnote" id="ftn1">
|
744
|
+
<p class="MsoFootnoteText"><a style="mso-footnote-id:ftn1" href="#_ftn1" name="_ftnref1" title="" id="_ftnref1"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Footnote</p></div>
|
745
|
+
<div style="mso-element:footnote" id="ftn2">
|
746
|
+
<p class="MsoFootnoteText"><a style="mso-footnote-id:ftn2" href="#_ftn2" name="_ftnref2" title="" id="_ftnref2"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"></span></span></a>Other Footnote</p></div>
|
747
|
+
</div>')}
|
748
|
+
#{WORD_FTR1}
|
749
|
+
OUTPUT
|
711
750
|
end
|
712
751
|
|
713
752
|
it "labels lists with list styles" do
|
@@ -715,38 +754,39 @@ RSpec.describe Html2Doc do
|
|
715
754
|
<div><ul id="0">
|
716
755
|
<li><div><p><ol id="1"><li><ul id="2"><li><p><ol id="3"><li><ol id="4"><li>A</li><li><p>B</p><p>B2</p></li><li>C</li></ol></li></ol></p></li></ul></li></ol></p></div></li><div><ul id="5"><li>C</li></ul></div>
|
717
756
|
BODY
|
718
|
-
Html2Doc.process(html_input(simple_body),
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
757
|
+
Html2Doc.process(html_input(simple_body),
|
758
|
+
filename: "test", liststyles: { ul: "l1", ol: "l2" })
|
759
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
760
|
+
.to match_fuzzy(<<~OUTPUT)
|
761
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
762
|
+
#{word_body('<div>
|
763
|
+
<p style="mso-list:l1 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p><div><p style="mso-list:l1 level1 lfo2;" class="MsoListParagraphCxSpFirst">C</p></div>
|
764
|
+
</div>',
|
765
|
+
'<div style="mso-element:footnote-list"/>')}
|
766
|
+
#{WORD_FTR1}
|
767
|
+
OUTPUT
|
728
768
|
end
|
729
769
|
|
730
|
-
|
731
770
|
it "restarts numbering of lists with list styles" do
|
732
771
|
simple_body = <<~BODY
|
733
772
|
<div>
|
734
773
|
<ol id="1"><li><div><p><ol id="2"><li><ul id="3"><li><p><ol id="4"><li><ol id="5"><li>A</li></ol></li></ol></p></li></ul></li></ol></p></div></li></ol>
|
735
774
|
<ol id="6"><li><div><p><ol id="7"><li><ul id="8"><li><p><ol id="9"><li><ol id="10"><li>A</li></ol></li></ol></p></li></ul></li></ol></p></div></li></ol></div>
|
736
775
|
BODY
|
737
|
-
Html2Doc.process(html_input(simple_body),
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
776
|
+
Html2Doc.process(html_input(simple_body),
|
777
|
+
filename: "test", liststyles: { ul: "l1", ol: "l2" })
|
778
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
779
|
+
.to match_fuzzy(<<~OUTPUT)
|
780
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
781
|
+
#{word_body('<div>
|
782
|
+
<p style="mso-list:l2 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p></p></p></p></div></p>
|
783
|
+
<p style="mso-list:l2 level1 lfo2;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo2;" class="MsoListParagraphCxSpFirst">A</p></p></p></p></div></p></div>',
|
784
|
+
'<div style="mso-element:footnote-list"/>')}
|
785
|
+
#{WORD_FTR1}
|
786
|
+
OUTPUT
|
787
|
+
end
|
788
|
+
|
789
|
+
it "labels lists with multiple list styles" do
|
750
790
|
simple_body = <<~BODY
|
751
791
|
<div><ul class="steps" id="0">
|
752
792
|
<li><div><p><ol id="1"><li><ul id="2"><li><p><ol id="3"><li><ol id="4"><li>A</li><li><p>B</p><p>B2</p></li><li>C</li></ol></li></ol></p></li></ul></li></ol></p></div></li></ul></div>
|
@@ -755,19 +795,21 @@ RSpec.describe Html2Doc do
|
|
755
795
|
<div><ul class="other" id="10">
|
756
796
|
<li><div><p><ol id="11"><li><ul id="12"><li><p><ol id="13"><li><ol id="14"><li>A</li><li><p>B</p><p>B2</p></li><li>C</li></ol></li></ol></p></li></ul></li></ol></p></div></li></ul></div>
|
757
797
|
BODY
|
758
|
-
Html2Doc.process(html_input(simple_body),
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
798
|
+
Html2Doc.process(html_input(simple_body),
|
799
|
+
filename: "test",
|
800
|
+
liststyles: { ul: "l1", ol: "l2", steps: "l3" })
|
801
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
802
|
+
.to match_fuzzy(<<~OUTPUT)
|
803
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
804
|
+
#{word_body('<div>
|
805
|
+
<p style="mso-list:l3 level1 lfo2;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l3 level2 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l3 level4 lfo2;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l3 level5 lfo2;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>
|
806
|
+
<div>
|
807
|
+
<p style="mso-list:l1 level1 lfo1;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo1;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo1;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>
|
808
|
+
<div>
|
809
|
+
<p style="mso-list:l1 level1 lfo3;" class="MsoListParagraphCxSpFirst"><div><p class="MsoNormal"><p style="mso-list:l2 level2 lfo3;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level4 lfo3;" class="MsoListParagraphCxSpFirst"><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpFirst">A</p><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpMiddle">B<p class="MsoListParagraphCxSpMiddle">B2</p></p><p style="mso-list:l2 level5 lfo3;" class="MsoListParagraphCxSpLast">C</p></p></p></p></div></p></div>',
|
810
|
+
'<div style="mso-element:footnote-list"/>')}
|
811
|
+
#{WORD_FTR1}
|
812
|
+
OUTPUT
|
771
813
|
end
|
772
814
|
|
773
815
|
it "replaces id attributes with explicit a@name bookmarks" do
|
@@ -777,27 +819,30 @@ RSpec.describe Html2Doc do
|
|
777
819
|
<p id="b"/>
|
778
820
|
</div>
|
779
821
|
BODY
|
780
|
-
Html2Doc.process(html_input(simple_body),
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
<
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
822
|
+
Html2Doc.process(html_input(simple_body),
|
823
|
+
filename: "test", liststyles: { ul: "l1", ol: "l2" })
|
824
|
+
expect(guid_clean(File.read("test.doc", encoding: "utf-8")))
|
825
|
+
.to match_fuzzy(<<~OUTPUT)
|
826
|
+
#{WORD_HDR} #{DEFAULT_STYLESHEET} #{WORD_HDR_END}
|
827
|
+
#{word_body('<div>
|
828
|
+
<p class="MsoNormal"><a name="a" id="a"></a>Hello</p>
|
829
|
+
<p class="MsoNormal"><a name="b" id="b"></a></p>
|
830
|
+
</div>',
|
831
|
+
'<div style="mso-element:footnote-list"/>')}
|
832
|
+
#{WORD_FTR1}
|
833
|
+
OUTPUT
|
791
834
|
end
|
792
835
|
|
793
836
|
it "test image base64 image encoding" do
|
794
837
|
simple_body = '<img src="19160-6.png">'
|
795
|
-
Html2Doc.process(html_input(simple_body),
|
838
|
+
Html2Doc.process(html_input(simple_body),
|
839
|
+
filename: "spec/test", debug: true)
|
796
840
|
testdoc = File.read("spec/test.doc", encoding: "utf-8")
|
797
841
|
base64_image = testdoc[/image\/png\n\n(.*?)\n\n----/m, 1].gsub!("\n", "")
|
798
842
|
base64_image_basename = testdoc[%r{Content-ID: <([0-9a-z\-]+)\.png}m, 1]
|
799
843
|
doc_bin_image = Base64.strict_decode64(base64_image)
|
800
|
-
file_bin_image = IO
|
844
|
+
file_bin_image = IO
|
845
|
+
.read("spec/test_files/#{base64_image_basename}.png", mode: "rb")
|
801
846
|
expect(doc_bin_image).to eq file_bin_image
|
802
847
|
FileUtils.rm_rf %w[spec/test_files spec/test.doc spec/test.htm]
|
803
848
|
end
|