avv2word 1.1.32 → 1.1.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31e19ebe56e8f9af6892a0f3c9e425d314fde6898672952f34ff7f5000d23ff7
4
- data.tar.gz: 2a750cc0c1e6fc0f52e71b1755909dc1bfa613896e196b394e84f9ad10a3a37b
3
+ metadata.gz: 4dba72f05d26da97e550a062c06917cd8ae4bc0d0aeca8e3ea50b698d1ea37a9
4
+ data.tar.gz: d20f014128c0e5f421b1c8367969562335f224c6e82fef83da088c41b04f47ce
5
5
  SHA512:
6
- metadata.gz: 9e5f606383a872b1d64149604df9546d69ae76774e9c78a57f46f73cc97b6db0bf9ab8a27721368132e170afb365a5a09e9d437a169479ef9157d1dc8036e70b
7
- data.tar.gz: ece605d7fd55a4d00b6003774297afab490a4ab241d6347342d13c098db97f54230f4cbe5c918bdd4719c4e192bd3eb25d1a6d5027cc56ce876598be6995a4f1
6
+ metadata.gz: 7ffb19037b6d64ad5a066b2c76d81f7e46c42e2dc5f96e32b5cb1845dcb76a7f79ac97a189b7f339e5fbb336e2869a55d8746dfc2fc40b8e40904ad39bf78b90
7
+ data.tar.gz: 7c3207c55fd8e6e4779d5714b9f4086deab434470dc43212c66ad46d19867aa1ca56cbc894717989babb698499b801c69c1e43c4bb9fd0b80f4b392a8cb87bbe
@@ -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 add_footnotes(footnotes)
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/><w:rsid w:val="008D12FB"/></w:style>',
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
- Zip::File.open(@template_path) do |zipfile|
265
- types = Nokogiri::XML.parse(zipfile.read("[Content_Types].xml"))
266
- [ # '<Override PartName="/word/endnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"/>',
267
- '<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/>'
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
@@ -1,3 +1,3 @@
1
1
  module Avv2word
2
- VERSION = '1.1.32'
2
+ VERSION = '1.1.37'
3
3
  end
@@ -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()[not(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)]">
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::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>
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.32
4
+ version: 1.1.37
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-02-11 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack