html2doc 1.4.0 → 1.4.2

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: df61b49c5ba557bf2742f1d7240d5990322f2be01019dc6dd712eeecc0752e61
4
- data.tar.gz: d85fdda65fcc3c7ed6bdcd5a38501549abc03d536ab00ac9bcb28f061790a3fd
3
+ metadata.gz: 834f2d69887ce656cd78e78822c78c98a19017e01ff1fbaffb5bcf9951fb1419
4
+ data.tar.gz: b7c12ae5d35ae84ac8de00d3cde42dc27549f5567623a5d88a50c3757a4c6dcd
5
5
  SHA512:
6
- metadata.gz: 6173d729141614e61dfd5502c3ab0e6192b6c4fdf95b8689d882b14f97401086eab3188ac0c7a5154464a0c735226fa762041c926fe2827e8b936143e422ac29
7
- data.tar.gz: dcc3a65d88d7ded0855930ac56f1848c72fa4ac45fa86187f2c2df4af9af593ec0f292a16e3df73a60a99d515dfff9dfaba7205c1bf633a425f54ead25b87760
6
+ metadata.gz: 02a2b5f53337616b673d43f20a3f90594bcf5355288235d4eafe2622cac8e6af01d24ea2b05a8d2fea0fb9256b4d43686f3c81cb075ea562f6fcb616791abfeb
7
+ data.tar.gz: 565a6554f2de5e99bbaa9cc5de81e3c7d9789e36d9251641518cf82f44c2183a36a9305d2054535396813b21e475a31af1ca9577c9cb7c4bd7a9dbc0b872cf6b
data/html2doc.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "htmlentities", "~> 4.3.4"
29
29
  spec.add_dependency "image_size"
30
30
  spec.add_dependency "mime-types"
31
- spec.add_dependency "nokogiri", "~> 1.12"
31
+ spec.add_dependency "nokogiri", "~> 1.13"
32
32
  spec.add_dependency "plane1converter", "~> 0.0.1"
33
33
  spec.add_dependency "thread_safe"
34
34
  spec.add_dependency "uuidtools"
data/lib/html2doc/base.rb CHANGED
@@ -14,6 +14,7 @@ class Html2Doc
14
14
  @imagedir = hash[:imagedir]
15
15
  @debug = hash[:debug]
16
16
  @liststyles = hash[:liststyles]
17
+ @stylesheet = hash[:stylesheet]
17
18
  @xsltemplate =
18
19
  Nokogiri::XSLT(File.read(File.join(File.dirname(__FILE__), "mml2omml.xsl"),
19
20
  encoding: "utf-8"))
@@ -30,37 +30,48 @@ class Html2Doc
30
30
  end
31
31
 
32
32
  def list_add(xpath, liststyles, listtype, level)
33
- xpath.each_with_index do |l, _i|
34
- @listnumber += 1 if level == 1
35
- l["seen"] = true if level == 1
33
+ xpath.each do |l|
34
+ level == 1 and l["seen"] = true and @listnumber += 1
36
35
  l["id"] ||= UUIDTools::UUID.random_create
37
36
  (l.xpath(".//li") - l.xpath(".//ol//li | .//ul//li")).each do |li|
38
37
  style_list(li, level, liststyles[listtype], @listnumber)
39
38
  list_add1(li, liststyles, listtype, level)
40
39
  end
41
- l.xpath(".//ul[not(ancestor::li/ancestor::*/@id = '#{l['id']}')] | "\
42
- ".//ol[not(ancestor::li/ancestor::*/@id = '#{l['id']}')]")
43
- .each do |li|
44
- list_add1(li.parent, liststyles, listtype, level - 1)
45
- end
40
+ list_add_tail(l, liststyles, listtype, level)
41
+ end
42
+ end
43
+
44
+ def list_add_tail(list, liststyles, listtype, level)
45
+ list.xpath(".//ul[not(ancestor::li/ancestor::*/@id = '#{list['id']}')] | "\
46
+ ".//ol[not(ancestor::li/ancestor::*/@id = '#{list['id']}')]")
47
+ .each do |li|
48
+ list_add1(li.parent, liststyles, listtype, level - 1)
46
49
  end
47
50
  end
48
51
 
49
52
  def list2para(list)
50
53
  return if list.xpath("./li").empty?
51
54
 
52
- list.xpath("./li").first["class"] ||= "MsoListParagraphCxSpFirst"
53
- list.xpath("./li").last["class"] ||= "MsoListParagraphCxSpLast"
54
- list.xpath("./li/p").each { |p| p["class"] ||= "MsoListParagraphCxSpMiddle" }
55
+ list2para_position(list)
55
56
  list.xpath("./li").each do |l|
56
57
  l.name = "p"
57
58
  l["class"] ||= "MsoListParagraphCxSpMiddle"
58
- l&.first_element_child&.name == "p" and
59
- l.first_element_child.replace(l.first_element_child.children)
59
+ next unless l.first_element_child&.name == "p"
60
+
61
+ l["style"] += (l.first_element_child["style"]&.sub(/mso-list[^;]+;/, "") || "")
62
+ l.first_element_child.replace(l.first_element_child.children)
60
63
  end
61
64
  list.replace(list.children)
62
65
  end
63
66
 
67
+ def list2para_position(list)
68
+ list.xpath("./li").first["class"] ||= "MsoListParagraphCxSpFirst"
69
+ list.xpath("./li").last["class"] ||= "MsoListParagraphCxSpLast"
70
+ list.xpath("./li/p").each do |p|
71
+ p["class"] ||= "MsoListParagraphCxSpMiddle"
72
+ end
73
+ end
74
+
64
75
  TOPLIST = "[not(ancestor::ul) and not(ancestor::ol)]".freeze
65
76
 
66
77
  def lists1(docxml, liststyles, style)
@@ -72,7 +83,7 @@ class Html2Doc
72
83
  else
73
84
  list_add(docxml.xpath("//ol[@class = '#{style}']#{TOPLIST} | "\
74
85
  "//ul[@class = '#{style}']#{TOPLIST}"),
75
- liststyles, style, 1)
86
+ liststyles, style, 1)
76
87
  end
77
88
  end
78
89
 
@@ -1,3 +1,3 @@
1
1
  class Html2Doc
2
- VERSION = "1.4.0".freeze
2
+ VERSION = "1.4.2".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-03 00:00:00.000000000 Z
11
+ date: 2022-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.12'
75
+ version: '1.13'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.12'
82
+ version: '1.13'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: plane1converter
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -334,7 +334,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
334
334
  - !ruby/object:Gem::Version
335
335
  version: '0'
336
336
  requirements: []
337
- rubygems_version: 3.3.9
337
+ rubygems_version: 3.3.16
338
338
  signing_key:
339
339
  specification_version: 4
340
340
  summary: Convert HTML document to Microsoft Word document