isodoc 3.7.18 → 3.7.19

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: 78cb90e0e0fea60ab1ebfc166b51618d39abf17d345de2237a2b841acf9e0dff
4
- data.tar.gz: 4a3828eb99a8e58d62ce6a77a26adceee9e40e5ac58d16c5501d17fdbbb861b5
3
+ metadata.gz: 389417e16e4478a83ea47d49cd0032ed7bf0ba0b4578f3608c94278d76ea7ebd
4
+ data.tar.gz: 248384d71365868e13e92b0f0eff4ffacc3cf787e3e23279e84b4fa6b789a9e1
5
5
  SHA512:
6
- metadata.gz: f81f19086e763fca68dc8b1ad70b325592eeac99945628f81e16fadebed2b6e010df91cccf0b27d8232a62d769514a1bcbac2a9f907bbda3f0a2e3ed39fcd73f
7
- data.tar.gz: 6349cad368a56fe08aad86ea77825ef72aff7947828dcb955cec2aadec17911df52607ef0a3c1a57f6742157654025e0b4aa71146682354b8d80c32dd18a461c
6
+ metadata.gz: 717730f8158fd65959191add83d389e407b5ab3bf5072ffcce72e07a1a9d95c463bdd8dfe4f92d724498e39d6387c60aefcc072c5fc59096dfb29df9535e86cf
7
+ data.tar.gz: badc6e3bf2e2067c8a6a224012a27de79195a0464f8c62db2fba2f714c1feb74200e9d06eb60983c7dd9d8232b4623a3c65399c27e4fa5d06258b06a66266baf
@@ -5,6 +5,7 @@
5
5
  # (undeclared) sassc dependency.
6
6
  require "rake/clean"
7
7
  require "tmpdir"
8
+ require "digest"
8
9
 
9
10
  module IsoDoc
10
11
  module GemTasks
@@ -19,27 +20,45 @@ module IsoDoc
19
20
  end
20
21
 
21
22
  def install
23
+ scss_sources = {}
24
+ packaging = false
25
+ compiled_outputs = {}
22
26
  rule ".css" => [proc { |tn| tn.sub(/\.css$/, ".scss") }] do |current_task|
23
27
  puts(current_task)
24
- compile_scss_task(current_task)
28
+ compiled_outputs[current_task.name] = compile_scss_task(current_task)
25
29
  rescue StandardError => e
26
- notify_broken_compilation(e, current_task)
30
+ restore_scss_sources(scss_sources)
31
+ fail_on_error = packaging
32
+ packaging = false
33
+ notify_broken_compilation(e, current_task, fail_on_error: fail_on_error)
27
34
  end
28
35
 
29
36
  scss_files = Rake::FileList["lib/**/*.scss"]
30
37
  source_files = scss_files.ext(".css")
31
38
 
32
39
  task :comment_out_liquid do
40
+ packaging = true
41
+ scss_sources = scss_files.to_h { |name| [name, File.binread(name)] }
33
42
  process_css_files(scss_files) do |file_name|
34
43
  comment_out_liquid(File.read(file_name, encoding: "UTF-8"))
35
44
  end
45
+ rescue StandardError
46
+ restore_scss_sources(scss_sources)
47
+ packaging = false
48
+ raise
36
49
  end
37
50
 
38
51
  task build_scss: [:comment_out_liquid].push(*source_files) do
39
52
  process_css_files(scss_files) do |file_name|
40
53
  uncomment_out_liquid(File.read(file_name, encoding: "UTF-8"))
41
54
  end
55
+ validate_compiled_files(source_files, compiled_outputs)
42
56
  git_cache_compiled_files && puts("Built scss!")
57
+ rescue StandardError
58
+ restore_scss_sources(scss_sources)
59
+ raise
60
+ ensure
61
+ packaging = false
43
62
  end
44
63
 
45
64
  # `rake release` packages through bundler/gem_tasks (gem build), which
@@ -62,15 +81,32 @@ module IsoDoc
62
81
  ENV["CI"] == nil
63
82
  end
64
83
 
65
- def notify_broken_compilation(error, current_task)
84
+ def notify_broken_compilation(error, current_task, fail_on_error: false)
66
85
  puts("Cannot compile #{current_task} because of #{error.message}")
67
- return unless interactive?
86
+ raise error if fail_on_error || !interactive?
68
87
 
69
88
  puts("continue anyway[y|n]?")
70
89
  answer = $stdin.gets.strip
71
90
  exit(0) unless %w[y yes].include?(answer.strip.downcase)
72
91
  end
73
92
 
93
+ def restore_scss_sources(sources)
94
+ sources.each { |name, content| File.binwrite(name, content) }
95
+ end
96
+
97
+ def validate_compiled_files(source_files, compiled_outputs = {})
98
+ # Mixin/variable-only modules legitimately compile to empty CSS. Match
99
+ # every asset against this build's successful compiler result instead
100
+ # of accepting a stale sibling or rejecting valid zero-byte output.
101
+ missing = source_files.reject do |name|
102
+ File.file?(name) && compiled_outputs[name] &&
103
+ Digest::SHA256.file(name).hexdigest == compiled_outputs[name]
104
+ end
105
+ return if missing.empty?
106
+
107
+ raise "Missing or changed compiled CSS: #{missing.join(', ')}"
108
+ end
109
+
74
110
  def git_cache_compiled_files
75
111
  @@css_list.each do |css_file|
76
112
  sh "git add #{css_file}"
@@ -153,11 +189,11 @@ module IsoDoc
153
189
  basename = File.basename(filename, ".*")
154
190
  compiled_path = File.join(File.dirname(filename), "#{basename}.css")
155
191
  content = uncomment_out_liquid(compile_scss(filename))
156
- File.open(compiled_path, "w:UTF-8") do |f|
157
- f.write(content)
158
- end
192
+ # Preserve the hashed compiler bytes when Windows text mode expands LF.
193
+ File.binwrite(compiled_path, content)
159
194
  @@css_list << compiled_path
160
195
  CLEAN << compiled_path
196
+ Digest::SHA256.hexdigest(content)
161
197
  end
162
198
  end
163
199
  end
@@ -127,11 +127,12 @@ module IsoDoc
127
127
  end
128
128
 
129
129
  def term_header(docxml)
130
+ ids = html_existing_ids(docxml)
130
131
  %w(h1 h2 h3 h4 h5 h6 h7 h8).each do |h|
131
132
  docxml.xpath("//p[@class = 'TermNum'][../#{h}]").each do |p|
132
133
  p.name = "h#{h[1].to_i + 1}"
133
134
  id = p["id"]
134
- p["id"] = "_#{Metanorma::Utils.random_uuid}"
135
+ p["id"] = html_content_id(p, ids)
135
136
  p.wrap("<div id='#{id}'></div>")
136
137
  end
137
138
  end
@@ -152,13 +152,35 @@ module IsoDoc
152
152
  end
153
153
 
154
154
  def html_toc_entries_prep(docxml, path)
155
+ ids = html_existing_ids(docxml)
155
156
  docxml.xpath(path.join(" | "))
156
157
  .each_with_index.with_object({}) do |(h, i), m|
157
- h["id"] ||= "_#{Metanorma::Utils.random_uuid}"
158
+ h["id"] ||= html_content_id(h, ids)
158
159
  m[h["id"]] = i
159
160
  end
160
161
  end
161
162
 
163
+ # HTML adds headings that are absent from the presentation XML. Use the
164
+ # same content/path-derived identifiers as presentation conversion, but
165
+ # do not collide with an existing author-supplied anchor.
166
+ def html_content_id(node, ids)
167
+ base = Metanorma::Utils.contenthash(node)
168
+ id = base
169
+ suffix = 0
170
+ while ids.key?(id)
171
+ suffix += 1
172
+ id = "#{base}-#{suffix}"
173
+ end
174
+ ids[id] = true
175
+ id
176
+ end
177
+
178
+ def html_existing_ids(docxml)
179
+ docxml.xpath("//*[@id]").each_with_object({}) do |node, ids|
180
+ ids[node["id"]] = true
181
+ end
182
+ end
183
+
162
184
  def toc_exclude_class
163
185
  "[not(@class = 'TermNum')][not(@class = 'noTOC')]" \
164
186
  "[string-length(normalize-space(.))>0]"
@@ -49,6 +49,7 @@ module IsoDoc
49
49
  bibrender_formattedref(f, bib)
50
50
  else bibrender_relaton(bib, renderings)
51
51
  end
52
+ strip_retained_semantic_ids(bib)
52
53
  bibitem_notes(bib)
53
54
  end
54
55
 
@@ -67,6 +68,21 @@ module IsoDoc
67
68
  end
68
69
  end
69
70
 
71
+ # When a bibitem is rendered through relaton, the rendered formattedref
72
+ # supersedes the retained raw title. The title subtree's renderable ids
73
+ # are transferred to original-id, mirroring the semx convention on
74
+ # in-place elements: the FO tree must see each id only once, since FOP
75
+ # treats a duplicate id as fatal.
76
+ def strip_retained_semantic_ids(bib)
77
+ title = bib.at(ns("./title")) or return
78
+ bib.at(ns("./formattedref")) or return
79
+ title.xpath("self::*[@id] | .//*[@id]").each do |x|
80
+ next unless x["id"]
81
+ x["original-id"] = x["id"]
82
+ x.delete("id")
83
+ end
84
+ end
85
+
70
86
  def bibitem_notes(bib)
71
87
  f = bib.at(ns("./formattedref")) or return
72
88
  bibnote_extract(bib, "display").each do |n|
@@ -181,7 +181,16 @@ module IsoDoc
181
181
  end, "or"))
182
182
  else
183
183
  ret = loc2xref(list[0])
184
- list[1..].each { |l| ret = i18n_chain_boolean(ret, l) }
184
+ list[1..].each do |l|
185
+ # entries with no connective (an erefstack authored without
186
+ # one) are comma-joined; the boolean chain needs a connective
187
+ # word to localise, and would send "chain_" on nil
188
+ ret = if l[:conn]
189
+ i18n_chain_boolean(ret, l)
190
+ else
191
+ connectives_spans("#{ret}, #{loc2xref(l)}")
192
+ end
193
+ end
185
194
  if list[0][:conn] == "from" && list[0][:custom]
186
195
  # TODO: languages with mandatory from, include from in chain_to
187
196
  ret = connectives_spans("<conn>#{list[0][:custom]}</conn> ") + ret
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "3.7.18".freeze
2
+ VERSION = "3.7.19".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.18
4
+ version: 3.7.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-21 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64