html2doc 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bb21340bfc58bd193ded256493c609e890af4f5ecd92ae8ecc98d0810a1b7cb
4
- data.tar.gz: 0aebb9ed61579d9aa400d00968d3b75d534aa359f5254a6d32eee5e73ec0367f
3
+ metadata.gz: 4a7563641963ef0845a507bea481d742d970aa780935c0a6012f9724071f3a7b
4
+ data.tar.gz: 88073d037f32936739ce4629ca1ed1c9cb7e1f661ef84c87c8185e0d05146192
5
5
  SHA512:
6
- metadata.gz: 2b9ae30ec647e4821ed0a3616014af64d102b252225456ffe3aac7eabbca87e85a8749e951d02196f7607e072049308b4be481302fcbefeae732aaab4fbd00cb
7
- data.tar.gz: 2a6917a1c30e0d29d8ba06471ac548a548aafaf84a92fdc629ef27af4a4eaea9ce972dd3c37320dd5509c347082d01eb1a2bda46c4d8b75588d0c7c403b2b775
6
+ metadata.gz: 64e521545d1a41466111d7592abe7164810a8294c1669d5c7dfd7602746da9fc1e905b008ab0d6a17cc6fa4686478b70a8d804eadffb7d5fb2a33d8f5f06a756
7
+ data.tar.gz: c64b5d5c51ec9d1fd81d0489a53e169b5d6b55a820d11109b4be0b199e88fb166726402c4cc075c495c8049141222dba4fa837a71a0b6b3746f6a12feca14b18
data/.rubocop.yml CHANGED
@@ -2,6 +2,15 @@
2
2
  # See https://github.com/metanorma/cimas
3
3
  inherit_from:
4
4
  - https://raw.githubusercontent.com/riboseinc/oss-guides/main/ci/rubocop.yml
5
+ # .rubocop_todo.yml MUST be the last entry. inherit_from is last-wins:
6
+ # if listed before oss-guides, the shared config's stricter Metrics/
7
+ # (MethodLength, BlockLength, etc.) rules override the todo's per-file
8
+ # grandfathering, and the todo becomes inert on those cops. Empirically
9
+ # verified on suma 2026-07-06: with todo listed first, 34 Metrics/* offenses
10
+ # remained; moved last, cleared. Every gem in the metanorma-org fleet
11
+ # already ships a `.rubocop_todo.yml` on its live tree (audited 2026-07-06,
12
+ # 54/54 have it), so this reference is safe to emit unconditionally.
13
+ - .rubocop_todo.yml
5
14
 
6
15
  # Rubocop plugins enabled centrally so every metanorma-org gem picks them up
7
16
  # on cimas sync — best practice belongs at the shared-template layer, not
data/html2doc.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  end
27
27
  spec.required_ruby_version = Gem::Requirement.new(">= 3.3.0")
28
28
 
29
- spec.add_dependency "base64"
29
+ spec.add_dependency "base64", ">= 0.1.0"
30
30
  spec.add_dependency "htmlentities", "~> 4.3.4"
31
31
 
32
32
  spec.add_dependency "marcel"
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_dependency "vectory", "~> 0.10"
40
40
 
41
41
  spec.add_development_dependency "debug"
42
- spec.add_development_dependency "equivalent-xml", "~> 0.6"
42
+ spec.add_development_dependency "canon", "~> 0.3"
43
43
  spec.add_development_dependency "guard", "~> 2.14"
44
44
  spec.add_development_dependency "guard-rspec", "~> 4.7"
45
45
  spec.add_development_dependency "rake", "~> 12.0"
@@ -1,4 +1,4 @@
1
- require "uuidtools"
1
+ require "digest"
2
2
  require "htmlentities"
3
3
  require "nokogiri"
4
4
 
@@ -30,7 +30,9 @@ class Html2Doc
30
30
  def list_add(xpath, liststyles, listtype, level)
31
31
  xpath.each do |l|
32
32
  level == 1 && l["seen"] = true and @listnumber += 1
33
- l["id"] ||= UUIDTools::UUID.random_create
33
+ # document-scoped counter, not random entropy: this id is only used
34
+ # for list bookkeeping, and must not vary between runs
35
+ l["id"] ||= "list#{(@listididx += 1)}"
34
36
  liststyle = derive_liststyle(l, liststyles[listtype], level)
35
37
  (l.xpath(".//li") - l.xpath(".//ol//li | .//ul//li")).each do |li|
36
38
  style_list(li, level, liststyle, @listnumber)
@@ -52,14 +54,22 @@ class Html2Doc
52
54
  s = @liststyledefs[liststyle]
53
55
  .gsub(/@list\s+#{liststyle}/, "@list #{newstylename}")
54
56
  .sub(/@list\s+#{newstylename}\s+\{[^}]*\}/m, <<~LISTSTYLE)
55
- @list #{newstylename}\n{mso-list-id:#{rand(100_000_000..999_999_999)};
56
- mso-list-template-ids:#{rand(100_000_000..999_999_999)};}
57
+ @list #{newstylename}\n{mso-list-id:#{opaque_list_id(newstylename)};
58
+ mso-list-template-ids:#{opaque_list_id("#{newstylename}:template")};}
57
59
  LISTSTYLE
58
60
  .sub(/@list\s+#{newstylename}:level#{level}\s+\{/m,
59
61
  "\\0mso-level-start-at:#{start};\n")
60
62
  "#{s}\n"
61
63
  end
62
64
 
65
+ # Word treats mso-list-id / mso-list-template-ids as opaque identifiers
66
+ # that must be unique within the document stylesheet. Derive them from
67
+ # the list style name instead of random entropy, so identical input
68
+ # yields byte-identical Word output.
69
+ def opaque_list_id(seed)
70
+ 100_000_000 + Digest::SHA256.hexdigest(seed).to_i(16) % 900_000_000
71
+ end
72
+
63
73
  def list_add_tail(list, liststyles, listtype, level)
64
74
  list.xpath(".//ul[not(ancestor::li/ancestor::*/@id = '#{list['id']}')] | "\
65
75
  ".//ol[not(ancestor::li/ancestor::*/@id = '#{list['id']}')]")
@@ -129,6 +139,7 @@ class Html2Doc
129
139
 
130
140
  def parse_stylesheet_line_styles
131
141
  @listnumber = 0
142
+ @listididx = 0
132
143
  result = process_stylesheet_lines(@stylesheet.split("\n"))
133
144
  @liststyledefs = clean_result_content(result)
134
145
  @newliststyledefs = ""
data/lib/html2doc/mime.rb CHANGED
@@ -63,16 +63,20 @@ class Html2Doc
63
63
  type
64
64
  end
65
65
 
66
- def mime_boundary
67
- salt = UUIDTools::UUID.random_create.to_s.tr("-", ".")[0..17]
66
+ # Deterministic MIME boundary: minted from the content of this package
67
+ # instead of random entropy, so identical input yields byte-identical
68
+ # .doc MHTML output. Boundaries only need uniqueness within a document,
69
+ # not across the universe.
70
+ def mime_boundary(seed)
71
+ salt = uuid5(seed).tr("-", ".")[0..17]
68
72
  "----=_NextPart_#{salt}"
69
73
  end
70
74
 
71
75
  def mime_package(result, filename, dir)
72
- boundary = mime_boundary
76
+ boundary = mime_boundary("#{filename}.htm:#{result}")
73
77
  mhtml = mime_preamble(boundary, "#{filename}.htm", result)
74
78
  mhtml += mime_attachment(boundary, "#{filename}.htm", "filelist.xml", dir)
75
- Dir.foreach(dir) do |item|
79
+ Dir.entries(dir).sort.each do |item|
76
80
  next if item == "." || item == ".." || /^\./.match(item) ||
77
81
  item == "filelist.xml"
78
82
 
@@ -94,8 +98,16 @@ class Html2Doc
94
98
 
95
99
  IMAGE_PATH = "//*[local-name() = 'img' or local-name() = 'imagedata']".freeze
96
100
 
97
- def mkuuid
98
- UUIDTools::UUID.random_create.to_s
101
+ # RFC 4122 name-based (SHA-1, version 5) UUID minted from seed content.
102
+ # Word/Outlook treat Content-IDs as opaque; deriving them from content
103
+ # keeps identical documents byte-identical across runs.
104
+ def uuid5(seed)
105
+ UUIDTools::UUID.sha1_create(UUIDTools::UUID_OID_NAMESPACE,
106
+ seed).to_s
107
+ end
108
+
109
+ def image_uuid(filename)
110
+ uuid5(IO.binread(filename))
99
111
  end
100
112
 
101
113
  def warnsvg(src)
@@ -146,7 +158,7 @@ class Html2Doc
146
158
 
147
159
  def rename_image(img, dir, localdir)
148
160
  local_filename = localname(img["src"], localdir)
149
- new_filename = "#{mkuuid}#{File.extname(img['src'])}"
161
+ new_filename = "#{image_uuid(local_filename)}#{File.extname(img['src'])}"
150
162
  FileUtils.cp local_filename, File.join(dir, new_filename)
151
163
  img["src"] = File.join(File.basename(dir), new_filename)
152
164
  local_filename
@@ -228,7 +240,7 @@ class Html2Doc
228
240
  !(%r{ src="data:(image|application)/[^;]+;base64}.match a[1])
229
241
  m = / src=['"](?<src>[^"']+)['"]/.match a[1]
230
242
  m2 = /\.(?<suffix>[a-zA-Z_0-9]+)$/.match m[:src]
231
- new_filename = "#{mkuuid}.#{m2[:suffix]}"
243
+ new_filename = "#{image_uuid(localname(m[:src], localdir))}.#{m2[:suffix]}"
232
244
  FileUtils.cp localname(m[:src], localdir), File.join(dir, new_filename)
233
245
  a[1].sub!(%r{ src=['"](?<src>[^"']+)['"]}, " src='cid:#{new_filename}'")
234
246
  end
@@ -1,3 +1,3 @@
1
1
  class Html2Doc
2
- VERSION = "1.12.0".freeze
2
+ VERSION = "1.12.1".freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2doc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-11-26 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: base64
@@ -15,14 +16,14 @@ dependencies:
15
16
  requirements:
16
17
  - - ">="
17
18
  - !ruby/object:Gem::Version
18
- version: '0'
19
+ version: 0.1.0
19
20
  type: :runtime
20
21
  prerelease: false
21
22
  version_requirements: !ruby/object:Gem::Requirement
22
23
  requirements:
23
24
  - - ">="
24
25
  - !ruby/object:Gem::Version
25
- version: '0'
26
+ version: 0.1.0
26
27
  - !ruby/object:Gem::Dependency
27
28
  name: htmlentities
28
29
  requirement: !ruby/object:Gem::Requirement
@@ -164,19 +165,19 @@ dependencies:
164
165
  - !ruby/object:Gem::Version
165
166
  version: '0'
166
167
  - !ruby/object:Gem::Dependency
167
- name: equivalent-xml
168
+ name: canon
168
169
  requirement: !ruby/object:Gem::Requirement
169
170
  requirements:
170
171
  - - "~>"
171
172
  - !ruby/object:Gem::Version
172
- version: '0.6'
173
+ version: '0.3'
173
174
  type: :development
174
175
  prerelease: false
175
176
  version_requirements: !ruby/object:Gem::Requirement
176
177
  requirements:
177
178
  - - "~>"
178
179
  - !ruby/object:Gem::Version
179
- version: '0.6'
180
+ version: '0.3'
180
181
  - !ruby/object:Gem::Dependency
181
182
  name: guard
182
183
  requirement: !ruby/object:Gem::Requirement
@@ -337,6 +338,7 @@ licenses:
337
338
  - CC-BY-SA-3.0
338
339
  - BSD-2-Clause
339
340
  metadata: {}
341
+ post_install_message:
340
342
  rdoc_options: []
341
343
  require_paths:
342
344
  - lib
@@ -351,7 +353,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
351
353
  - !ruby/object:Gem::Version
352
354
  version: '0'
353
355
  requirements: []
354
- rubygems_version: 4.0.10
356
+ rubygems_version: 3.5.22
357
+ signing_key:
355
358
  specification_version: 4
356
359
  summary: Convert HTML document to Microsoft Word document
357
360
  test_files: []