avv2word 1.1.30 → 1.1.31

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: 8f21aa08f0eb889b07a6ae13cb5ed80156eb8bd3b2730b3bd99eb204a2c5b790
4
- data.tar.gz: 172e0cde722ad248e304ca092769bef904806efb5d43a11fdc4173385ad5963b
3
+ metadata.gz: 5d8568faddf890ada2e05ab971a1d9829938e0300213f0c510921322ad2f71a0
4
+ data.tar.gz: 3a175e32880587cdad276769604517f774c1995c1134802c5d8214aee82e7365
5
5
  SHA512:
6
- metadata.gz: 6a46e14ff10f766f006a3c3513875d6b58afe385f715b471ecedb4e5a2711514dcc468364949fdb6e51210d017e36624147f8006be361d460f137e90060922cc
7
- data.tar.gz: '03578535709c0f1761318c6cf9c723f8bc073b8566485d7bb4b61d98df1beb18916d5a40d8c33f69a87945bef5d345022e6171b763a42df391433c945e4c679f'
6
+ metadata.gz: e2e040b9b91976b7ce8a58723af3de9863e433d93f35728aaa46a74527932f7514d4ffd9c974bcb017c38d282c2c0b016e8e97b428c1c0fd4ba59f8bad2c5747
7
+ data.tar.gz: f971b5da98c1f4af48fbb7ce3c24870a1eb218e4174589d88a9a1503fb89726fdec17df71d3953879a3f6e1504ce20577c27cdcdde715927c24d88a5b9b4be07
@@ -272,19 +272,34 @@ module Avv2word
272
272
  end
273
273
  end
274
274
 
275
- def inject_image_relations(relations, noko_html_source)
275
+ def inject_relations(relations, noko_html_source)
276
276
  rel_doc = Nokogiri::XML(relations)
277
277
  relations_root = rel_doc.css("Relationships").first
278
-
279
278
  relations_size = relations_root.css("Relationship").size
279
+ img_counter = 0
280
280
 
281
- noko_html_source.css("img").each_with_index do |img,i|
281
+ html = noko_html_source.to_xml
282
+ html.scan(/<img.*?>|<a.*?\/a>/).each_with_index do |link,i|
282
283
  new_relation = relations_root.css("Relationship").last.clone
283
- new_relation["Id"] = "rId#{i + 10}" # use relations_size for dynamic relations create, todo
284
- new_relation["Type"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
285
- new_relation["Target"] = "media/image#{i+1}#{File.extname(img[:src])}"
284
+
285
+ case link
286
+ when /^<a/
287
+ a_href = link.match(/href="(.*?)"/)[1]
288
+ new_relation["Id"] = "rId#{i + 1 + relations_size}"
289
+ new_relation["Type"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
290
+ new_relation["TargetMode"] = "External"
291
+ new_relation["Target"] = a_href
292
+ when /^<img/
293
+ img_counter += 1
294
+ img_src = link.match(/src="(.*?)"/)[1]
295
+ new_relation["Id"] = "rId#{i + 1 + relations_size}"
296
+ new_relation["Type"] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"
297
+ new_relation["Target"] = "media/image#{img_counter}#{File.extname(img_src)}"
298
+ new_relation.remove_attribute("TargetMode") if new_relation["TargetMode"]
299
+ end
286
300
  relations_root.add_child new_relation
287
301
  end
302
+
288
303
  rel_doc.to_xml
289
304
  end
290
305
 
@@ -292,8 +307,9 @@ module Avv2word
292
307
  stylesheet = xslt(stylesheet_path: stylesheet_path)
293
308
  content = stylesheet.apply_to(source)
294
309
  content.gsub!(/\s*xmlns:(\w+)="(.*?)\s*"/, '') if remove_ns
295
- if ( file =~ /document\.xml\.rels/ ) && ( source.css("img").size > 0 )
296
- content = inject_image_relations(content, source)
310
+
311
+ if ( file =~ /document\.xml\.rels/ ) && (( source.css("a").size > 0 ) || ( source.css("img").size > 0 ))
312
+ content = inject_relations(content, source)
297
313
  elsif file =~ /header/i
298
314
  @replaceable_files["word/_rels/header.xml.rels"] = %(<?xml version="1.0" encoding="UTF-8"?>\n<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\n</Relationships>)
299
315
  source.css("img").each_with_index do |noko_img,i|
Binary file
@@ -1,3 +1,3 @@
1
1
  module Avv2word
2
- VERSION = '1.1.30'
2
+ VERSION = '1.1.31'
3
3
  end
@@ -27,9 +27,7 @@
27
27
  <w:color w:val="000080"/>
28
28
  <w:u w:val="single"/>
29
29
  </w:rPr>
30
- <w:t xml:space="preserve">
31
- <xsl:value-of select="."/>
32
- </w:t>
30
+ <w:t xml:space="preserve"><xsl:value-of select="."/></w:t>
33
31
  </w:r>
34
32
  </w:hyperlink>
35
33
  </xsl:template>
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.30
4
+ version: 1.1.31
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: 2019-11-05 00:00:00.000000000 Z
11
+ date: 2020-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack