avv2word 1.1.33 → 1.1.38
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avv2word/document.rb +48 -12
- data/lib/avv2word/templates/default.docx +0 -0
- data/lib/avv2word/version.rb +1 -1
- data/lib/avv2word/xslt/base.xslt +21 -1
- data/lib/avv2word/xslt/inline_elements.xslt +2 -2
- data/lib/avv2word/xslt/tables.xslt +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ff5b1268da3fddf42d52468e656cabfd04a33d7156746f25c08215b59f01de0
|
4
|
+
data.tar.gz: dfb5b9c5b3a40f8ba8a4d176a34f3fd2995886816af841093088dbad77864a0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a93bb3a486fbc7f0a23cdbb58366fd971dc9b4dc84225361de80b264524e03711b000dd4cd1f607bd9b5a48f6630db8607dd370e783fd75bb9afd4ada01e820
|
7
|
+
data.tar.gz: 5f7e69b4c5d3d6febe6f19fd465693fe73c59e00117cf4ff13ce68cc7af38076478bea48306e97f8087f6e9b64620006946c4fc6d44d5843fb30f888e3cb2c7a
|
data/lib/avv2word/document.rb
CHANGED
@@ -100,6 +100,10 @@ module Avv2word
|
|
100
100
|
def footnotes_xml_file
|
101
101
|
'word/footnotes.xml'
|
102
102
|
end
|
103
|
+
|
104
|
+
def styles_xml_file
|
105
|
+
'word/styles.xml'
|
106
|
+
end
|
103
107
|
end
|
104
108
|
|
105
109
|
def initialize(template_path)
|
@@ -184,6 +188,7 @@ module Avv2word
|
|
184
188
|
local_images(header, :header) if @header
|
185
189
|
|
186
190
|
add_footnotes(source.css("footnote").map{ |footnote| footnote.text })
|
191
|
+
add_comments(source.css("comment")) unless source.css("comment").empty?
|
187
192
|
end
|
188
193
|
|
189
194
|
def transform_doc_xml(source, extras = false)
|
@@ -194,7 +199,28 @@ module Avv2word
|
|
194
199
|
|
195
200
|
private
|
196
201
|
|
197
|
-
def
|
202
|
+
def add_comments(comments)
|
203
|
+
@replaceable_files["word/comments.xml"] = %(<?xml version="1.0" encoding="UTF-8"?><w:comments xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">)
|
204
|
+
comments.each_with_index do |comment,id|
|
205
|
+
time = comment.attributes["time"].value # 2020-04-29T11:49:00Z
|
206
|
+
author = comment.attributes["author"].value
|
207
|
+
message = comment.attributes["message"].value
|
208
|
+
initials = comment.attributes["initials"].value
|
209
|
+
comment_generator = %Q(<w:comment w:id="#{id}" w:author="#{author}" w:date="#{time}" w:initials="#{initials}"><w:p w14:paraId="2F08968D" w14:textId="06CE6739" w:rsidR="009A6661" w:rsidRDefault="009A6661"><w:pPr><w:pStyle w:val="CommentText"/></w:pPr><w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:annotationRef/></w:r><w:r><w:t>#{message}</w:t></w:r></w:p></w:comment>)
|
210
|
+
@replaceable_files["word/comments.xml"] += comment_generator
|
211
|
+
end
|
212
|
+
@replaceable_files["word/comments.xml"] += "</w:comments>"
|
213
|
+
|
214
|
+
rels = Nokogiri::XML(@replaceable_files["word/_rels/document.xml.rels"])
|
215
|
+
new_rel = %(<Relationship Id="rIdXX" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="comments.xml"/>)
|
216
|
+
new_rel.sub!(/XX/, (rels.xpath("//xmlns:Relationship").size+1).to_s )
|
217
|
+
rels.children.first << Nokogiri::XML.parse(new_rel).child
|
218
|
+
@replaceable_files["word/_rels/document.xml.rels"] = rels.to_xml
|
219
|
+
|
220
|
+
insert_nodes_to_xml(Document.content_types_xml_file, ['<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"/>'])
|
221
|
+
end
|
222
|
+
|
223
|
+
def add_footnotes(footnotes)
|
198
224
|
if footnotes.empty?
|
199
225
|
@replaceable_files["word/footnotes.xml"] = ""
|
200
226
|
return
|
@@ -247,8 +273,8 @@ module Avv2word
|
|
247
273
|
styles = Nokogiri::XML.parse(zipfile.read("word/styles.xml"))
|
248
274
|
end
|
249
275
|
end
|
250
|
-
[ '<w:style w:type="paragraph" w:styleId="FootnoteText"><w:name w:val="footnote text"/><w:basedOn w:val="Normal"/><w:link w:val="FootnoteTextChar"/><w:uiPriority w:val="99"/><w:semiHidden/><w:unhideWhenUsed/><w:rsid w:val="008D12FB"/></w:style>',
|
251
|
-
'<w:style w:type="character" w:customStyle="1" w:styleId="FootnoteTextChar"><w:name w:val="Footnote Text Char"/><w:basedOn w:val="DefaultParagraphFont"/><w:link w:val="FootnoteText"/><w:uiPriority w:val="99"/><w:semiHidden
|
276
|
+
[ '<w:style w:type="paragraph" w:styleId="FootnoteText"><w:name w:val="footnote text"/><w:basedOn w:val="Normal"/><w:link w:val="FootnoteTextChar"/><w:uiPriority w:val="99"/><w:semiHidden/><w:unhideWhenUsed/><w:rsid w:val="008D12FB"/><w:rsid w:val="008D12FB"/><w:rPr><w:sz w:val="16"/></w:rPr></w:style>',
|
277
|
+
'<w:style w:type="character" w:customStyle="1" w:styleId="FootnoteTextChar"><w:name w:val="Footnote Text Char"/><w:basedOn w:val="DefaultParagraphFont"/><w:link w:val="FootnoteText"/><w:uiPriority w:val="99"/><w:semiHidden/></w:style>',
|
252
278
|
'<w:style w:type="character" w:styleId="FootnoteReference"><w:name w:val="footnote reference"/><w:basedOn w:val="DefaultParagraphFont"/><w:uiPriority w:val="99"/><w:semiHidden/><w:unhideWhenUsed/><w:rsid w:val="008D12FB"/><w:rPr><w:vertAlign w:val="superscript"/></w:rPr></w:style>'
|
253
279
|
].each do |new_style|
|
254
280
|
styles.children.first << Nokogiri::XML.parse(new_style).child
|
@@ -261,15 +287,10 @@ module Avv2word
|
|
261
287
|
@replaceable_files["word/styles.xml"] = styles.to_xml
|
262
288
|
|
263
289
|
# content type
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
].each do |new_type|
|
269
|
-
types.children.first << Nokogiri::XML.parse(new_type).child
|
270
|
-
end
|
271
|
-
@replaceable_files["[Content_Types].xml"] = types.to_xml
|
272
|
-
end
|
290
|
+
insert_nodes_to_xml(Document.content_types_xml_file, [
|
291
|
+
# '<Override PartName="/word/endnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"/>',
|
292
|
+
'<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/>'
|
293
|
+
])
|
273
294
|
end
|
274
295
|
|
275
296
|
def inject_relations(relations, noko_html_source)
|
@@ -363,5 +384,20 @@ module Avv2word
|
|
363
384
|
#return the amended source to be saved into the zip
|
364
385
|
doc.to_s
|
365
386
|
end
|
387
|
+
|
388
|
+
def insert_nodes_to_xml(target_xml_file, inputs)
|
389
|
+
xml_content =
|
390
|
+
if @replaceable_files[target_xml_file]
|
391
|
+
Nokogiri::XML(@replaceable_files[target_xml_file])
|
392
|
+
else
|
393
|
+
Zip::File.open(@template_path) do |zipfile|
|
394
|
+
Nokogiri::XML.parse(zipfile.read(target_xml_file))
|
395
|
+
end
|
396
|
+
end
|
397
|
+
inputs.each do |new_node|
|
398
|
+
xml_content.children.first << Nokogiri::XML.parse(new_node).child
|
399
|
+
end
|
400
|
+
@replaceable_files[target_xml_file] = xml_content.to_xml
|
401
|
+
end
|
366
402
|
end
|
367
403
|
end
|
Binary file
|
data/lib/avv2word/version.rb
CHANGED
data/lib/avv2word/xslt/base.xslt
CHANGED
@@ -208,12 +208,16 @@
|
|
208
208
|
<xsl:variable name="ilvl" select="@level"></xsl:variable>
|
209
209
|
<xsl:variable name="toc-ref" select="@toc-ref" />
|
210
210
|
<xsl:variable name="cross-ref" select="@cross-ref" />
|
211
|
+
<xsl:variable name="docx-style" select="@data-docx-style" />
|
211
212
|
<w:p>
|
212
213
|
<w:pPr>
|
213
214
|
<xsl:choose>
|
214
215
|
<xsl:when test="string-length(normalize-space($toc-ref)) > 0">
|
215
216
|
<w:pStyle w:val="Heading{$ilvl+1}"/>
|
216
217
|
</xsl:when>
|
218
|
+
<xsl:when test="string-length($docx-style) > 0">
|
219
|
+
<w:pStyle w:val="{$docx-style}"/>
|
220
|
+
</xsl:when>
|
217
221
|
<xsl:otherwise>
|
218
222
|
<w:pStyle w:val="ListParagraph"/>
|
219
223
|
</xsl:otherwise>
|
@@ -280,7 +284,7 @@
|
|
280
284
|
</w:p>
|
281
285
|
</xsl:template>
|
282
286
|
|
283
|
-
<xsl:template match="text()[
|
287
|
+
<xsl:template match="text()[(parent::li) and not(parent::td) and not(parent::pre) 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)]">
|
284
288
|
<xsl:comment>
|
285
289
|
In the following situation:
|
286
290
|
|
@@ -413,6 +417,7 @@
|
|
413
417
|
<xsl:template name="text-alignment">
|
414
418
|
<xsl:param name="class" select="@class" />
|
415
419
|
<xsl:param name="style" select="@style" />
|
420
|
+
<xsl:param name="docx-style" select="@data-docx-style" />
|
416
421
|
<xsl:param name="line-height" select="@line-height" />
|
417
422
|
<xsl:param name="margin-bottom" select="@margin-bottom" />
|
418
423
|
<xsl:param name="margin-top" select="@margin-top" />
|
@@ -506,6 +511,9 @@
|
|
506
511
|
<w:jc w:val="{$alignment}"/>
|
507
512
|
</xsl:when>
|
508
513
|
</xsl:choose>
|
514
|
+
<xsl:if test="string-length($docx-style) > 0">
|
515
|
+
<w:pStyle w:val="{$docx-style}"/>
|
516
|
+
</xsl:if>
|
509
517
|
</w:pPr>
|
510
518
|
</xsl:template>
|
511
519
|
|
@@ -585,4 +593,16 @@
|
|
585
593
|
</w:del>
|
586
594
|
</xsl:template>
|
587
595
|
|
596
|
+
<xsl:template match="comment">
|
597
|
+
<xsl:number level="any" count="comment" format="1"/>
|
598
|
+
<w:commentRangeStart w:id="{format-number(count(preceding::comment),'0')}"/>
|
599
|
+
<w:r>
|
600
|
+
<w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
|
601
|
+
</w:r>
|
602
|
+
<w:commentRangeEnd w:id="{format-number(count(preceding::comment),'0')}"/>
|
603
|
+
<w:r>
|
604
|
+
<w:commentReference w:id="{format-number(count(preceding::comment),'0')}"/>
|
605
|
+
</w:r>
|
606
|
+
</xsl:template>
|
607
|
+
|
588
608
|
</xsl:stylesheet>
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<xsl:attribute name="style"><xsl:value-of select="../@style"/></xsl:attribute>
|
19
19
|
<xsl:call-template name="inlineElement"/>
|
20
20
|
</div>
|
21
|
-
<xsl:apply-templates select="following-sibling::node()[not((self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::delete|self::insert|self::text())[parent::div|parent::li|parent::td])][1]"/>
|
21
|
+
<xsl:apply-templates select="following-sibling::node()[not((self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::delete|self::insert|self::cross-ref|self::text())[parent::div|parent::li|parent::td])][1]"/>
|
22
22
|
</xsl:template>
|
23
23
|
|
24
24
|
<!-- get following inline elements... -->
|
@@ -36,6 +36,6 @@
|
|
36
36
|
<xsl:copy>
|
37
37
|
<xsl:apply-templates select="@*|node()[1]"/>
|
38
38
|
</xsl:copy>
|
39
|
-
<xsl:apply-templates select="following-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()|self::insert|self::delete]"/>
|
39
|
+
<xsl:apply-templates select="following-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()|self::insert|self::delete|self::cross-ref]"/>
|
40
40
|
</xsl:template>
|
41
41
|
</xsl:stylesheet>
|
@@ -32,14 +32,15 @@
|
|
32
32
|
<xsl:choose>
|
33
33
|
<xsl:when test="string-length(normalize-space($ind_left)) > 0">
|
34
34
|
<w:tblW w:w="{9360 - $ind_left}" w:type="dxa"/>
|
35
|
+
<!--table indent left-->
|
36
|
+
<w:tblInd w:w="{115 + $ind_left}" w:type="dxa"/>
|
35
37
|
</xsl:when>
|
36
38
|
<xsl:otherwise>
|
37
39
|
<w:tblW w:w="9360" w:type="dxa"/>
|
40
|
+
<w:tblInd w:w="115" w:type="dxa"/>
|
38
41
|
</xsl:otherwise>
|
39
42
|
</xsl:choose>
|
40
43
|
|
41
|
-
<!--table indent left-->
|
42
|
-
<w:tblInd w:w="{$ind_left}" w:type="dxa"/>
|
43
44
|
<!--table indent left, top; works in word without margin(?), not in libre-->
|
44
45
|
<!--<w:tblpPr w:leftFromText="180" w:rightFromText="180" w:vertAnchor="text" w:horzAnchor="page" w:tblpX="{$ind_left}" w:tblpY="{$ind_top}"/>-->
|
45
46
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avv2word
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marián Bilas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|