htmltoword 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +15 -0
- data/lib/htmltoword/document.rb +2 -1
- data/lib/htmltoword/version.rb +1 -1
- data/lib/htmltoword/xslt/base.xslt +20 -1
- data/lib/htmltoword/xslt/cleanup.xslt +1 -0
- data/lib/htmltoword/xslt/images.xslt +63 -56
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c47d1b5bc4522ff27b68ab48736b845e1879856e
|
4
|
+
data.tar.gz: 126c012568a4dbb529194e24c1a84ccd11690807
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 215fce4c96862fecf5be83838ae721e7f99a3f170b23a1f04bc4cd0440fba816cef205cfd5d137f884d7be8def32054684a311f035ced6b944750837a974da25
|
7
|
+
data.tar.gz: 3c802b88efcb2025195b3ce210e7d5addff8c1d63894e370f886b1f0d9bff27229f56c6654f3c2d635dc160d2fb85564a91718920c4eb2a0b71c946b00cb1b41
|
data/README.md
CHANGED
@@ -148,6 +148,21 @@ To create page breaks simply add a div with class -page-break ie:
|
|
148
148
|
<div class="-page-break"></div>
|
149
149
|
````
|
150
150
|
|
151
|
+
### Images
|
152
|
+
Support for images is very basic and is only possible for external images(i.e accessed via URL). If the image doesn't
|
153
|
+
have correctly defined it's width and height it won't be included in the document
|
154
|
+
|
155
|
+
**Limitations:**
|
156
|
+
- Images are external i.e. pictures accessed via URL, not stored within document
|
157
|
+
- only sizing is customisable
|
158
|
+
|
159
|
+
Examples:
|
160
|
+
```html
|
161
|
+
<img src="http://placehold.it/250x100.png" style="width: 250px; height: 100px">
|
162
|
+
<img src="http://placehold.it/250x100.png" data-width="250px" data-height="100px">
|
163
|
+
<img src="http://placehold.it/250x100.png" data-height="150px" style="width:250px; height:100px">
|
164
|
+
```
|
165
|
+
|
151
166
|
## Contributing / Extending
|
152
167
|
|
153
168
|
Word docx files are essentially just a zipped collection of xml files and resources.
|
data/lib/htmltoword/document.rb
CHANGED
@@ -91,7 +91,8 @@ module Htmltoword
|
|
91
91
|
|
92
92
|
def replace_files(html, extras = false)
|
93
93
|
html = '<body></body>' if html.nil? || html.empty?
|
94
|
-
|
94
|
+
original_source = Nokogiri::HTML(html.gsub(/>\s+</, '><'))
|
95
|
+
source = xslt(stylesheet_name: 'cleanup').transform(original_source)
|
95
96
|
transform_and_replace(source, xslt_path('numbering'), Document.numbering_xml_file)
|
96
97
|
transform_and_replace(source, xslt_path('relations'), Document.relations_xml_file)
|
97
98
|
transform_doc_xml(source, extras)
|
data/lib/htmltoword/version.rb
CHANGED
@@ -77,7 +77,7 @@
|
|
77
77
|
</w:p>
|
78
78
|
</xsl:template>
|
79
79
|
|
80
|
-
<xsl:template match="div[not(ancestor::li) and not(ancestor::td) and not(ancestor::th) and not(ancestor::p) and not(descendant::div) and not(descendant::p) and not(descendant::h1) and not(descendant::h2) and not(descendant::h3) and not(descendant::h4) and not(descendant::h5) and not(descendant::h6) and not(descendant::table) and not(descendant::li) and not (descendant::pre)]">
|
80
|
+
<xsl:template match="div[not(ancestor::li) and not(ancestor::td) and not(ancestor::th) and not(ancestor::p) and not(ancestor::dl) and not(descendant::dl) and not(descendant::div) and not(descendant::p) and not(descendant::h1) and not(descendant::h2) and not(descendant::h3) and not(descendant::h4) and not(descendant::h5) and not(descendant::h6) and not(descendant::table) and not(descendant::li) and not (descendant::pre)]">
|
81
81
|
<xsl:comment>Divs should create a p if nothing above them has and nothing below them will</xsl:comment>
|
82
82
|
<w:p>
|
83
83
|
<xsl:call-template name="text-alignment" />
|
@@ -178,6 +178,25 @@
|
|
178
178
|
</xsl:for-each>
|
179
179
|
</xsl:template>
|
180
180
|
|
181
|
+
<xsl:template match="dl">
|
182
|
+
<xsl:apply-templates/>
|
183
|
+
</xsl:template>
|
184
|
+
|
185
|
+
<xsl:template match="dt">
|
186
|
+
<w:p>
|
187
|
+
<xsl:apply-templates/>
|
188
|
+
</w:p>
|
189
|
+
</xsl:template>
|
190
|
+
|
191
|
+
<xsl:template match="dd">
|
192
|
+
<w:p>
|
193
|
+
<w:pPr>
|
194
|
+
<w:ind w:left="720"/>
|
195
|
+
</w:pPr>
|
196
|
+
<xsl:apply-templates/>
|
197
|
+
</w:p>
|
198
|
+
</xsl:template>
|
199
|
+
|
181
200
|
<xsl:template match="span[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
182
201
|
|a[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
183
202
|
|small[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
|
@@ -23,6 +23,7 @@
|
|
23
23
|
<xsl:template match="command"/>
|
24
24
|
<xsl:template match="font"/>
|
25
25
|
<xsl:template match="iframe"/>
|
26
|
+
<xsl:template match="img[not(starts-with(@src, 'http://')) and not(starts-with(@src, 'https://'))]"/>
|
26
27
|
<xsl:template match="isindex"/>
|
27
28
|
<xsl:template match="map"/>
|
28
29
|
<xsl:template match="noframes"/>
|
@@ -37,62 +37,69 @@
|
|
37
37
|
<xsl:include href="./image_functions.xslt"/>
|
38
38
|
|
39
39
|
<xsl:template match="img|body/img" name="image">
|
40
|
-
<
|
41
|
-
<
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
<
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
<
|
56
|
-
<
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
40
|
+
<xsl:choose>
|
41
|
+
<xsl:when test="not(@data-width) and not(@data-height) and not(contains(@style, 'width')) and not(contains(@style, 'height'))">
|
42
|
+
<!-- Do not transfor images unless width and height are correctly specified -->
|
43
|
+
</xsl:when>
|
44
|
+
<xsl:otherwise>
|
45
|
+
<w:drawing>
|
46
|
+
<wp:inline distT="0" distB="0" distL="0" distR="0">
|
47
|
+
<wp:extent>
|
48
|
+
<xsl:call-template name="image-dimention-attributes"/>
|
49
|
+
</wp:extent>
|
50
|
+
<wp:effectExtent l="0" t="0" r="0" b="0"/>
|
51
|
+
<wp:docPr>
|
52
|
+
<xsl:attribute name="id"><xsl:value-of select="count(preceding::img)+1" /></xsl:attribute>
|
53
|
+
<xsl:attribute name="name">Picture <xsl:value-of select="count(preceding::img)+1" /></xsl:attribute>
|
54
|
+
</wp:docPr>
|
55
|
+
<wp:cNvGraphicFramePr>
|
56
|
+
<a:graphicFrameLocks noChangeAspect="1"/>
|
57
|
+
</wp:cNvGraphicFramePr>
|
58
|
+
<a:graphic>
|
59
|
+
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
|
60
|
+
<pic:pic>
|
61
|
+
<pic:nvPicPr>
|
62
|
+
<pic:cNvPr>
|
63
|
+
<xsl:attribute name="id"><xsl:value-of select="count(preceding::img)+1" /></xsl:attribute>
|
64
|
+
<xsl:attribute name="title"><xsl:value-of select="@alt" /></xsl:attribute>
|
65
|
+
<xsl:attribute name="name"><xsl:call-template name="image-name">
|
66
|
+
<xsl:with-param name="source" select="@src"/>
|
67
|
+
<xsl:with-param name="data-filename" select="@data-filename"/>
|
68
|
+
</xsl:call-template></xsl:attribute>
|
69
|
+
</pic:cNvPr>
|
70
|
+
<pic:cNvPicPr/>
|
71
|
+
</pic:nvPicPr>
|
72
|
+
<pic:blipFill>
|
73
|
+
<a:blip>
|
74
|
+
<xsl:attribute name="r:embed"><xsl:call-template name="relationship-id"/></xsl:attribute>
|
75
|
+
<a:extLst>
|
76
|
+
<a:ext uri="{{28A0092B-C50C-407E-A947-70E740481C1C}}">
|
77
|
+
<a14:useLocalDpi val="0"/>
|
78
|
+
</a:ext>
|
79
|
+
</a:extLst>
|
80
|
+
</a:blip>
|
81
|
+
<a:stretch>
|
82
|
+
<a:fillRect/>
|
83
|
+
</a:stretch>
|
84
|
+
</pic:blipFill>
|
85
|
+
<pic:spPr>
|
86
|
+
<a:xfrm>
|
87
|
+
<a:off x="0" y="0"/>
|
88
|
+
<a:ext>
|
89
|
+
<xsl:call-template name="image-dimention-attributes"/>
|
90
|
+
</a:ext>
|
91
|
+
</a:xfrm>
|
92
|
+
<a:prstGeom prst="rect">
|
93
|
+
<a:avLst/>
|
94
|
+
</a:prstGeom>
|
95
|
+
</pic:spPr>
|
96
|
+
</pic:pic>
|
97
|
+
</a:graphicData>
|
98
|
+
</a:graphic>
|
99
|
+
</wp:inline>
|
100
|
+
</w:drawing>
|
101
|
+
</xsl:otherwise>
|
102
|
+
</xsl:choose>
|
96
103
|
</xsl:template>
|
97
104
|
|
98
105
|
<!--
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmltoword
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicholas Frandsen, Cristina Matonte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
177
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.6.13
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: This simple gem allows you to create MS Word docx documents from simple html
|