htmltoword 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Htmltoword
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -37,7 +37,15 @@
37
37
  </w:body>
38
38
  </xsl:template>
39
39
 
40
- <xsl:template match="div[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::table)]">
40
+ <xsl:template match="body/*[not(*)]">
41
+ <w:p>
42
+ <w:r>
43
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
44
+ </w:r>
45
+ </w:p>
46
+ </xsl:template>
47
+
48
+ <xsl:template match="div[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::table) and not(descendant::li)]">
41
49
  <xsl:comment>Divs should create a p if nothing above them has and nothing below them will</xsl:comment>
42
50
  <w:p>
43
51
  <xsl:apply-templates />
@@ -61,9 +69,7 @@
61
69
 
62
70
  <xsl:template match="p">
63
71
  <w:p>
64
- <w:r>
65
- <xsl:apply-templates />
66
- </w:r>
72
+ <xsl:apply-templates />
67
73
  </w:p>
68
74
  </xsl:template>
69
75
 
@@ -75,9 +81,9 @@
75
81
  </w:p>
76
82
  </xsl:template>
77
83
 
78
- <xsl:template match="span[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]
79
- |a[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]
80
- |small[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]">
84
+ <xsl:template match="span[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 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]
85
+ |a[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 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]
86
+ |small[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 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]|strong[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 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]">
81
87
  <xsl:comment>
82
88
  In the following situation:
83
89
 
@@ -94,6 +100,24 @@
94
100
  </w:p>
95
101
  </xsl:template>
96
102
 
103
+ <xsl:template match="text()[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 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]">
104
+ <xsl:comment>
105
+ In the following situation:
106
+
107
+ div
108
+ h2
109
+ textnode
110
+ p
111
+
112
+ The div template will not create a w:p because the div contains a h2. Therefore we need to wrap the textnode in a p here.
113
+ </xsl:comment>
114
+ <w:p>
115
+ <w:r>
116
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
117
+ </w:r>
118
+ </w:p>
119
+ </xsl:template>
120
+
97
121
  <xsl:template match="span[contains(concat(' ', @class, ' '), ' h ')]">
98
122
  <xsl:variable name="color">
99
123
  <xsl:choose>
@@ -107,7 +131,7 @@
107
131
  <w:rPr>
108
132
  <w:highlight w:val="{$color}"/>
109
133
  </w:rPr>
110
- <xsl:apply-templates/>
134
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
111
135
  </w:r>
112
136
  </xsl:template>
113
137
 
@@ -182,25 +206,8 @@
182
206
  <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
183
207
  </w:r>
184
208
  </xsl:when>
185
- <xsl:when test="parent::div 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)">
186
- <xsl:comment>
187
- In the following situation:
188
-
189
- div
190
- h2
191
- textnode
192
-
193
- The div template will not create a w:p because the div contains a h2. Therefore we need to wrap the textnode in a p here.
194
- </xsl:comment>
195
- <w:p>
196
- <w:r>
197
- <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
198
- </w:r>
199
- </w:p>
200
- </xsl:when>
201
209
  <xsl:otherwise>
202
210
  <w:r>
203
- <xsl:comment>text() fallback</xsl:comment>
204
211
  <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
205
212
  </w:r>
206
213
  </xsl:otherwise>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htmltoword
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: