isodoc 3.7.20 → 3.7.21

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: b533831a501b075f7725d8f1e6fdfca4403fa270cf989fc9ae0fdbef5ea129c9
4
- data.tar.gz: 4146069e94e8c48ea3c61507e181e1fb4f016123031d0fd624621718a0058449
3
+ metadata.gz: f78d832952e372d48e705af0e68f1256a591ce795de69db5baea2eb670546e36
4
+ data.tar.gz: 611959196a20f772f32a82d975c3e2db5378327ece1ff4013ac4267d8643f5f8
5
5
  SHA512:
6
- metadata.gz: 9d83bac4d179f0b53a263c6d789648b5ff2d24b1d61cef9153daf65fed28ee0f3c3cd6dfeea958b81997de606ca80bfab0162b1eb5c6ef19cef4f5760b231690
7
- data.tar.gz: 9a9718b43db2b9f52553087c799e5a5ec787ca4e5c59c95896091f88477c8dcdbc9fc86c20ca45d93544c7244caa32ba3685951cb3d4c516ea7ebeb0c0e0054a
6
+ metadata.gz: 79afedd59e0dbd331bc7b62ddbb450596e85267d953cbdbc9be1f9cde78084ff29adbe977969eb1a06aa64fdef6af54ae1093f37e20dde004f087de68ff86217
7
+ data.tar.gz: b6b3cf61467751cf58d77715fe62bbc5067bb84dfb7daed10fee83ed130cfa7f47db5eff882e7651a03671d7dd62ec8b4966c247023aa39c3cca4ea253f0c298
@@ -0,0 +1,46 @@
1
+ require "digest"
2
+ require "fileutils"
3
+
4
+ module IsoDoc
5
+ # Content-addressed asset store shared by every converter of a compile.
6
+ #
7
+ # Each image enters the store exactly once, keyed by the SHA-256 of its
8
+ # bytes ("<sha256>.<ext>"): identical images within a document, and the
9
+ # same image consumed by different converters of one compile, resolve to
10
+ # a single stored file. The store lives under the compile's work root,
11
+ # whose lifecycle belongs to the compile driver (Metanorma::Compile);
12
+ # converters only ingest into it and materialize from it.
13
+ #
14
+ # Content addressing also makes random filenames in published output
15
+ # unrepresentable: emitted image names are the store's content addresses.
16
+ class AssetStore
17
+ attr_reader :dir
18
+
19
+ def initialize(dir)
20
+ @dir = dir
21
+ FileUtils.mkdir_p @dir
22
+ end
23
+
24
+ # Copy the image at +source_path+ into the store under its content
25
+ # address, and return the store-relative filename. Already-stored
26
+ # content is not rewritten, so unchanged images are reused as-is
27
+ # (the cache unit for change-proportional rebuilds).
28
+ def add(source_path, ext)
29
+ name = filename(source_path, ext)
30
+ File.exist?(path(name)) or FileUtils.cp(source_path, path(name))
31
+ name
32
+ end
33
+
34
+ def path(name)
35
+ File.join(@dir, name)
36
+ end
37
+
38
+ def filename(source_path, ext)
39
+ "#{hash(source_path)}.#{ext}"
40
+ end
41
+
42
+ def hash(source_path)
43
+ Digest::SHA256.file(source_path).hexdigest
44
+ end
45
+ end
46
+ end
@@ -1,10 +1,12 @@
1
1
  require "isodoc/common"
2
+ require "isodoc/asset_store"
3
+ require "digest"
2
4
  require "fileutils"
3
5
  require "tempfile"
6
+ require "tmpdir"
4
7
  require_relative "i18n"
5
8
  require_relative "css"
6
9
  require_relative "init"
7
- require "securerandom"
8
10
  require "mn-requirements"
9
11
 
10
12
  module IsoDoc
@@ -52,6 +54,10 @@ module IsoDoc
52
54
  # sourcehighlighter: whether to apply sourcecode highlighting
53
55
  # semantic_xml_insert: whether to insert into presentation XML
54
56
  # a copy of semantic XML
57
+ # workdir: work root for this compile, hosting the shared asset store
58
+ # and per-converter scratch directories. Supplied by the compile
59
+ # driver (Metanorma::Compile), which owns its lifecycle; when absent,
60
+ # the root is derived deterministically from the source content.
55
61
  # output_formats: hash of supported output formats and suffixes
56
62
  def initialize(options) # rubocop:disable Lint/MissingSuper
57
63
  @options = options_preprocess(options)
@@ -66,14 +72,6 @@ module IsoDoc
66
72
  init_arrangement(@options)
67
73
  end
68
74
 
69
- def tmpimagedir_suffix
70
- "_#{SecureRandom.hex(8)}_images"
71
- end
72
-
73
- def tmpfilesdir_suffix
74
- "_#{SecureRandom.hex(8)}_files"
75
- end
76
-
77
75
  def html_doc_path(*file)
78
76
  file.each do |f|
79
77
  ret = File.join(@libdir, File.join("html", f))
@@ -111,7 +109,7 @@ module IsoDoc
111
109
 
112
110
  def convert_init(file, input_filename, debug)
113
111
  docxml = Nokogiri::XML(file, &:huge)
114
- filename, dir = init_file(input_filename, debug)
112
+ filename, dir = init_file(input_filename, file, debug)
115
113
  docxml.root.default_namespace = ""
116
114
  docxml_var_init(docxml)
117
115
  convert_i18n_init(docxml)
@@ -157,7 +155,16 @@ module IsoDoc
157
155
  debug and return result
158
156
  output_filename ||= "#{filename}.#{@suffix}"
159
157
  postprocess(result, output_filename, dir)
160
- FileUtils.rm_rf dir
158
+ ensure
159
+ # The compile driver owns the work root when it supplies one; a
160
+ # root this converter derived for itself is removed with the
161
+ # conversion. Debug runs keep everything for inspection.
162
+ teardown_workdir unless debug
163
+ end
164
+
165
+ # Remove the work root if and only if this converter created it.
166
+ def teardown_workdir
167
+ @workdir && @workdir_owner and FileUtils.rm_rf(@workdir)
161
168
  end
162
169
 
163
170
  def middle_clause(_docxml = nil)
@@ -246,7 +246,7 @@ module IsoDoc
246
246
  node.at(ns(".//fmt-fn-label"))&.remove
247
247
  tag = node.parent.name == "fmt-footnote-container" ? "aside" : "div"
248
248
  id = node["is_table"] ? node["reference"] : node["id"]
249
- out.send tag, id: "fn:#{id}", class: "footnote" do |div|
249
+ out.send tag, id: fn_body_id(id), class: "footnote" do |div|
250
250
  children_parse(node, div)
251
251
  end
252
252
  end
@@ -1,8 +1,16 @@
1
1
  module IsoDoc
2
2
  module Function
3
3
  module Footnotes
4
+ # The footnote body id scheme (prefix + id), used both for the footnote
5
+ # body id and for the anchor href that targets it: the two MUST be the
6
+ # same string, so the pair is single-sourced here. HTML default;
7
+ # overridden by the Word function for its `ftn` bookmark naming.
8
+ def fn_body_id(id)
9
+ "fn:#{id}"
10
+ end
11
+
4
12
  def make_table_footnote_link(out, fnid, node)
5
- attrs = { href: "##{fnid}", class: "TableFootnoteRef" }
13
+ attrs = { href: "##{fn_body_id(fnid)}", class: "TableFootnoteRef" }
6
14
  sup = node&.at(ns(".//sup")) and sup.replace(sup.children)
7
15
  out.a(**attrs) do |a|
8
16
  children_parse(node, a)
@@ -12,7 +20,7 @@ module IsoDoc
12
20
  def get_table_ancestor_id(node)
13
21
  table = node.ancestors("table")
14
22
  table.empty? and table = node.ancestors("figure")
15
- table.empty? and return [nil, Metanorma::Utils.random_uuid]
23
+ table.empty? and return [nil, nil]
16
24
  [table.last, table.last["id"]]
17
25
  end
18
26
 
@@ -20,8 +28,14 @@ module IsoDoc
20
28
  # do not output footnote text if we have already seen it for this table
21
29
 
22
30
  def table_footnote_parse(node, out)
23
- fn = node["reference"] || Metanorma::Utils.random_uuid
31
+ # The footnote reference forms part of the published anchor
32
+ # (href="#fn:<table id><reference>"), so when the source lacks a
33
+ # reference attribute it is derived from the node content rather
34
+ # than a random identifier: compiling the same document twice
35
+ # must produce the same output.
36
+ fn = node["reference"] || Metanorma::Utils::contenthash(node)
24
37
  table, tid = get_table_ancestor_id(node)
38
+ tid or raise table_footnote_ancestor_error(node, table)
25
39
  make_table_footnote_link(out, tid + fn, node.at(ns("./fmt-fn-label")))
26
40
  # do not output footnote text if we have already seen it for this table
27
41
  @seen_footnote.include?(tid + fn) and return
@@ -29,6 +43,23 @@ module IsoDoc
29
43
  @seen_footnote << (tid + fn)
30
44
  end
31
45
 
46
+ # Table footnotes are anchored to the id of their ancestor table or
47
+ # figure. A footnote outside one, or inside one that carries no id,
48
+ # cannot form that anchor: fail with a diagnostic naming the
49
+ # degenerate input instead of crashing on `nil + String`.
50
+ def table_footnote_ancestor_error(node, table)
51
+ context = if table
52
+ "ancestor #{table.name} element has no id attribute"
53
+ else
54
+ "no ancestor table or figure"
55
+ end
56
+ "Cannot generate table footnote anchor for <#{node.name}> " \
57
+ "(reference: #{node['reference'].inspect}, " \
58
+ "target: #{node['target'].inspect}): #{context}. " \
59
+ "Table footnotes must occur inside a table or figure carrying " \
60
+ "an id attribute."
61
+ end
62
+
32
63
  def update_table_fn_body_ref(fnote, table, reference)
33
64
  fnbody = table.at(ns(".//fmt-fn-body[@id = '#{fnote['target']}']")) or
34
65
  return
@@ -49,8 +80,8 @@ module IsoDoc
49
80
 
50
81
  def footnote_parse(node, out)
51
82
  table_footnote?(node) and return table_footnote_parse(node, out)
52
- fn = node["target"] # || Metanorma::Utils.random_uuid
53
- attrs = { class: "FootnoteRef", href: "#fn:#{fn}" }
83
+ fn = node["target"]
84
+ attrs = { class: "FootnoteRef", href: "##{fn_body_id(fn)}" }
54
85
  f = node.at(ns("./fmt-fn-label"))
55
86
  out.a(**attrs) do |a|
56
87
  children_parse(f, a)
@@ -1,3 +1,4 @@
1
+ require "digest"
1
2
  require "fileutils"
2
3
  require "pathname"
3
4
 
@@ -8,10 +9,11 @@ module IsoDoc
8
9
  @note
9
10
  end
10
11
 
11
- def init_file(filename, debug)
12
+ def init_file(filename, file, debug)
12
13
  filepath = Pathname.new(filename)
13
14
  filename = filepath.sub_ext("").sub(/\.presentation$/, "").to_s
14
- dir = init_dir(filename, debug)
15
+ init_workdirs(file, debug)
16
+ dir = init_dir(debug)
15
17
  @filename = filename
16
18
  @output_dir = File.dirname(filename)
17
19
  @localdir = "#{@baseassetpath || filepath.parent.to_s}/"
@@ -21,8 +23,24 @@ module IsoDoc
21
23
  [filename, dir]
22
24
  end
23
25
 
24
- def init_dir(filename, debug)
25
- dir = "#{filename}#{@tmpfilesdir_suffix}"
26
+ # The work root hosts the compile's shared asset store and this
27
+ # converter's scratch directory. It is supplied by the compile
28
+ # driver (Metanorma::Compile), which derives it from the source
29
+ # content and owns its teardown; absent a driver, the root is
30
+ # derived from the source content itself, never from entropy, so
31
+ # identical compiles use identical roots.
32
+ def init_workdirs(file, debug)
33
+ @workdir ||= File.join(
34
+ Dir.tmpdir, "isodoc-work",
35
+ "doc-#{Digest::SHA256.hexdigest(file.to_s)}",
36
+ )
37
+ @asset_store = AssetStore.new(File.join(@workdir, "assets")) unless debug
38
+ end
39
+
40
+ # Per-converter scratch under the work root, keyed by the converter
41
+ # class so parallel output legs never share scratch state.
42
+ def init_dir(debug)
43
+ dir = File.join(leg_workdir, "files")
26
44
  unless debug
27
45
  FileUtils.mkdir_p(dir)
28
46
  FileUtils.chmod 0o777, dir
@@ -31,13 +49,25 @@ module IsoDoc
31
49
  dir
32
50
  end
33
51
 
34
- # tmp image dir is same directory as @filename
35
- def tmpimagedir
36
- @filename + @tmpimagedir_suffix
52
+ # This converter's leg directory under the work root: hosts its
53
+ # scratch and its transient intermediate artifacts. Removed with the
54
+ # work root, whose teardown belongs to the compile driver (or to
55
+ # this converter, when it derived the root itself).
56
+ def leg_workdir
57
+ File.join(@workdir, converter_work_name)
58
+ end
59
+
60
+ def converter_work_name
61
+ self.class.name.split("::").last
62
+ .gsub(/(.)([A-Z])/) { "#{Regexp.last_match(1)}_#{Regexp.last_match(2)}" }
63
+ .downcase
37
64
  end
38
65
 
39
- def rel_tmpimagedir
40
- Pathname.new(@filename).basename.to_s + @tmpimagedir_suffix
66
+ # The asset store of the compile. Images are ingested here exactly
67
+ # once, under their content address; emitted output resolves them
68
+ # through rel_asset_path.
69
+ def asset_store
70
+ @asset_store
41
71
  end
42
72
 
43
73
  def info(isoxml, out)
@@ -5,10 +5,6 @@ module IsoDoc
5
5
  class HeadlessHtmlConvert < ::IsoDoc::Convert
6
6
  include HtmlFunction::Html
7
7
 
8
- def tmpimagedir_suffix
9
- "_#{SecureRandom.hex(8)}_headlessimages"
10
- end
11
-
12
8
  def initialize(options)
13
9
  @format = :html
14
10
  @suffix = "headless.html"
@@ -22,11 +18,21 @@ module IsoDoc
22
18
  result = convert1(docxml, filename, dir)
23
19
  return result if debug
24
20
 
25
- postprocess(result, "#{filename}.tmp.html", dir)
26
- FileUtils.rm_rf dir
27
- strip_head("#{filename}.tmp.html",
28
- output_filename || "#{filename}.#{@suffix}")
29
- FileUtils.rm_rf ["#{filename}.tmp.html", tmpimagedir]
21
+ tmp_html = File.join(leg_workdir, "#{File.basename(filename)}.tmp.html")
22
+ postprocess(result, tmp_html, dir)
23
+ strip_head(tmp_html, output_filename || "#{filename}.#{@suffix}")
24
+ ensure
25
+ teardown_workdir unless debug
26
+ end
27
+
28
+ # The headless fragment is assembled into larger outputs by the
29
+ # consumers, which relocate or encode image targets themselves; the
30
+ # emitted references stay document-keyed and content-addressed, and
31
+ # no asset set is materialized beside the fragment.
32
+ def materialize_asset(_name, _artifact_dir); end
33
+
34
+ def rel_asset_path
35
+ "#{File.basename(@filename)}_headlessimages"
30
36
  end
31
37
 
32
38
  def strip_head(input, output)
@@ -8,10 +8,6 @@ module IsoDoc
8
8
  include HtmlFunction::Form
9
9
  include HtmlFunction::Html
10
10
 
11
- def tmpimagedir_suffix
12
- "_#{SecureRandom.hex(8)}_htmlimages"
13
- end
14
-
15
11
  def initialize(options)
16
12
  @format = :html
17
13
  @suffix = "html"
@@ -26,11 +22,29 @@ module IsoDoc
26
22
  empty_tags(super)
27
23
  end
28
24
 
29
- def convert(filename, file = nil, debug = false, output_filename = nil)
30
- ret = super
31
- Dir.exist?(tmpimagedir) and Dir["#{tmpimagedir}/*"].empty? and
32
- FileUtils.rm_r tmpimagedir
33
- ret
25
+ # The HTML artifact is published beside the output file and outlives
26
+ # the compile's work root, so its emitted image references target a
27
+ # published asset directory keyed by the document name: multi-document
28
+ # output directories keep documents' asset sets apart, and the alt
29
+ # output leg gets its own set. The names within are the asset store's
30
+ # content addresses: compiling the same document twice emits the same
31
+ # paths.
32
+ def rel_asset_path
33
+ "#{File.basename(@filename)}#{'_alt' if @options[:alt]}_htmlimages"
34
+ end
35
+
36
+ # Wipe-on-first-materialize keeps the published asset set exactly this
37
+ # compile's: a recompile into an existing output directory cannot
38
+ # leave stale images behind.
39
+ def materialize_asset(name, artifact_dir)
40
+ dir = File.join(artifact_dir, rel_asset_path)
41
+ @asset_dir_prepped ||= begin
42
+ FileUtils.rm_rf(dir)
43
+ FileUtils.mkdir_p(dir)
44
+ true
45
+ end
46
+ dest = File.join(dir, name)
47
+ File.exist?(dest) or FileUtils.cp asset_store.path(name), dest
34
48
  end
35
49
  end
36
50
  end
@@ -15,7 +15,8 @@ module IsoDoc
15
15
 
16
16
  def toHTML(result, filename)
17
17
  result = from_xhtml(html_cleanup(to_xhtml(result)))
18
- result = from_xhtml(move_images(resize_images(to_xhtml(result))))
18
+ result = from_xhtml(move_images(resize_images(to_xhtml(result)),
19
+ File.dirname(filename)))
19
20
  result = html5(empty_tags(script_cdata(inject_script(result))))
20
21
  # Unescape &#x26; to & in href attributes after all Nokogiri processing
21
22
  result = unescape_amp_in_hrefs(result)
@@ -94,16 +95,44 @@ module IsoDoc
94
95
  end
95
96
 
96
97
  # presupposes that the image source is local
97
- def move_images(docxml)
98
- FileUtils.rm_rf tmpimagedir
99
- FileUtils.mkdir tmpimagedir
98
+ def move_images(docxml, artifact_dir)
100
99
  docxml.xpath("//*[local-name() = 'img'][@src]").each do |i|
101
100
  /^data:/.match? i["src"] and next
102
- @datauriimage ? datauri(i) : move_image1(i)
101
+ @datauriimage ? datauri(i) : move_image1(i, artifact_dir)
103
102
  end
104
103
  docxml
105
104
  end
106
105
 
106
+ # Ingest the image into the compile's shared asset store under its
107
+ # content address, reference it through rel_asset_path, and
108
+ # materialize it beside the consuming artifact. Identical images
109
+ # share one stored file, and emitted names carry no entropy.
110
+ def move_image1(img, artifact_dir)
111
+ local_filename = image_localfile(img)
112
+ name = asset_store.add(local_filename, image_suffix(img))
113
+ img["src"] = File.join(rel_asset_path, name)
114
+ materialize_asset(name, artifact_dir)
115
+ end
116
+
117
+ # How the consuming artifact references assets of the store. The
118
+ # default is store-relative: converters whose transient artifact
119
+ # lives inside the compile's work root resolve the store beside
120
+ # themselves. Converters publishing artifacts that outlive the work
121
+ # root override this (see HtmlConvert, HeadlessHtmlConvert).
122
+ def rel_asset_path
123
+ "assets"
124
+ end
125
+
126
+ # Copy a stored asset next to the consuming artifact, so emitted
127
+ # references resolve after the work root is gone. Content addressing
128
+ # deduplicates: each unique image is copied once per artifact.
129
+ def materialize_asset(name, artifact_dir)
130
+ dest = File.join(artifact_dir, rel_asset_path, name)
131
+ File.exist?(dest) and return
132
+ FileUtils.mkdir_p(File.dirname(dest))
133
+ FileUtils.cp asset_store.path(name), dest
134
+ end
135
+
107
136
  def datauri(img)
108
137
  img["src"] = Vectory::Utils::datauri(img["src"], @localdir)
109
138
  end
@@ -116,16 +145,6 @@ module IsoDoc
116
145
  "png"
117
146
  end
118
147
 
119
- def move_image1(img)
120
- suffix = image_suffix(img)
121
- uuid = Metanorma::Utils.random_uuid
122
- fname = "#{uuid}.#{suffix}"
123
- new_full_filename = File.join(tmpimagedir, fname)
124
- local_filename = image_localfile(img)
125
- FileUtils.cp local_filename, new_full_filename
126
- img["src"] = File.join(rel_tmpimagedir, fname)
127
- end
128
-
129
148
  def term_header(docxml)
130
149
  ids = html_existing_ids(docxml)
131
150
  %w(h1 h2 h3 h4 h5 h6 h7 h8).each do |h|
data/lib/isodoc/init.rb CHANGED
@@ -116,8 +116,8 @@ module IsoDoc
116
116
  def init_locations(options)
117
117
  @libdir ||= File.dirname(__FILE__)
118
118
  @baseassetpath = options[:baseassetpath]
119
- @tmpimagedir_suffix = tmpimagedir_suffix
120
- @tmpfilesdir_suffix = tmpfilesdir_suffix
119
+ @workdir = options[:workdir]
120
+ @workdir_owner = @workdir.nil?
121
121
  @sourcefilename = options[:sourcefilename]
122
122
  @files_to_delete = []
123
123
  @tempfile_cache = []
@@ -14,10 +14,11 @@ module IsoDoc
14
14
  @maxheight = 800
15
15
  end
16
16
 
17
- def tmpimagedir_suffix
18
- "_#{SecureRandom.hex(8)}_pdfimages"
19
- end
20
-
17
+ # The intermediate HTML handed to the PDF renderer is a transient
18
+ # artifact inside the compile's work root, where it resolves the
19
+ # store's assets beside itself (rel_asset_path default); the work
20
+ # root teardown removes it with the compile. Ruby-side naming only,
21
+ # the PDF rendering pipeline itself is untouched.
21
22
  def convert(input_filename, file = nil, debug = false, output_filename = nil)
22
23
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
23
24
  @openmathdelim, @closemathdelim = extract_delims(file)
@@ -25,13 +26,14 @@ module IsoDoc
25
26
  result = convert1(docxml, filename, dir)
26
27
  return result if debug
27
28
 
28
- postprocess(result, "#{filename}.tmp.html", dir)
29
- FileUtils.rm_rf dir
29
+ tmp_html = File.join(leg_workdir, "#{File.basename(filename)}.tmp.html")
30
+ postprocess(result, tmp_html, dir)
30
31
  ::Metanorma::Output::Pdf.new.convert(
31
- "#{filename}.tmp.html",
32
+ tmp_html,
32
33
  output_filename || "#{filename}.#{@suffix}",
33
34
  )
34
- FileUtils.rm_rf ["#{filename}.tmp.html", tmpimagedir]
35
+ ensure
36
+ teardown_workdir unless debug
35
37
  end
36
38
 
37
39
  def xref_parse(node, out)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "3.7.20".freeze
2
+ VERSION = "3.7.21".freeze
3
3
  end
@@ -16,10 +16,9 @@ module IsoDoc
16
16
  super
17
17
  end
18
18
 
19
- def convert(filename, file = nil, debug = false, output_filename = nil)
20
- ret = super
21
- FileUtils.rm_rf tmpimagedir
22
- ret
23
- end
19
+ # Images are embedded into the output by Html2Doc, not moved through
20
+ # the asset store; the base convert's teardown removes the work root
21
+ # when this converter derived it itself, and the compile driver owns
22
+ # it otherwise.
24
23
  end
25
24
  end
@@ -10,12 +10,19 @@ module IsoDoc
10
10
  sprintf "%09d", ret
11
11
  end
12
12
 
13
+ # Word footnote body id scheme: `ftn` prefix, no colon (Word bookmark
14
+ # names may not contain punctuation). Pairs with `fn_body_id` so that
15
+ # footnote anchors and their bodies cannot drift apart.
16
+ def fn_body_id(id)
17
+ "ftn#{id}"
18
+ end
19
+
13
20
  def fmt_fn_body_parse(node, out)
14
21
  node.at(ns(".//fmt-fn-label"))&.remove
15
22
  aside = node.parent.name == "fmt-footnote-container"
16
23
  tag = aside ? "aside" : "div"
17
24
  id = node["is_table"] ? node["reference"] : node["id"]
18
- out.send tag, id: "ftn#{id}" do |div|
25
+ out.send tag, id: fn_body_id(id) do |div|
19
26
  children_parse(node, div)
20
27
  end
21
28
  end
@@ -63,7 +70,7 @@ module IsoDoc
63
70
  semx.name = "a"
64
71
  semx["class"] = "FootnoteRef"
65
72
  semx["epub:type"] = "footnote"
66
- semx["href"] = "#ftn#{node['target']}"
73
+ semx["href"] = "##{fn_body_id(node['target'])}"
67
74
  end
68
75
  end
69
76
  end
@@ -114,7 +114,9 @@ module IsoDoc
114
114
  meta = @meta.get.merge(@labels ? { labels: @labels } : {})
115
115
  .merge(@meta.labels ? { labels: @meta.labels } : {})
116
116
  meta[:filename] = filename
117
- meta.transform_keys(&:to_s)
117
+ # all levels, as in populate_template: nested hashes such as
118
+ # meta[:bibdata] must reach Liquid with string keys
119
+ meta.stringify_all_keys
118
120
  end
119
121
 
120
122
  def word_section_breaks(docxml)
@@ -37,10 +37,6 @@ module IsoDoc
37
37
  ret
38
38
  end
39
39
 
40
- def tmpimagedir_suffix
41
- "_#{SecureRandom.hex(8)}_pdfimages"
42
- end
43
-
44
40
  def pdf_stylesheet(_docxml)
45
41
  nil
46
42
  end
@@ -88,6 +84,8 @@ module IsoDoc
88
84
  filename, output_fname || output_filename(input_fname),
89
85
  @xsl, opts
90
86
  )
87
+ ensure
88
+ teardown_workdir unless debug
91
89
  end
92
90
 
93
91
  def convert_prep(input_fname, file, debug)
@@ -117,7 +115,6 @@ module IsoDoc
117
115
  temp_file.write docxml
118
116
  temp_file.flush
119
117
  @tempfile_cache << temp_file # Add to cache to prevent garbage collection
120
- FileUtils.rm_rf dir
121
118
 
122
119
  [temp_file, docxml, temp_file.path]
123
120
  end
data/lib/isodoc.rb CHANGED
@@ -10,6 +10,7 @@ require "htmlentities"
10
10
  require "relaton/render"
11
11
 
12
12
  require "isodoc/common"
13
+ require "isodoc/asset_store"
13
14
  require "isodoc/convert"
14
15
  require "isodoc/metadata"
15
16
  require "isodoc/html_convert"
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.20
4
+ version: 3.7.21
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-24 00:00:00.000000000 Z
11
+ date: 2026-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -250,25 +250,17 @@ files:
250
250
  - lib/isodoc-yaml/i18n-zh-Hans.yaml
251
251
  - lib/isodoc-yaml/i18n-zh-Hant.yaml
252
252
  - lib/isodoc.rb
253
- - lib/isodoc/base_style/all.css
253
+ - lib/isodoc/asset_store.rb
254
254
  - lib/isodoc/base_style/all.scss
255
- - lib/isodoc/base_style/bands.css
256
255
  - lib/isodoc/base_style/bands.scss
257
- - lib/isodoc/base_style/blocks.css
258
256
  - lib/isodoc/base_style/blocks.scss
259
- - lib/isodoc/base_style/coverpage.css
260
257
  - lib/isodoc/base_style/coverpage.scss
261
- - lib/isodoc/base_style/defaults.css
262
258
  - lib/isodoc/base_style/defaults.scss
263
- - lib/isodoc/base_style/metanorma_word.css
264
259
  - lib/isodoc/base_style/metanorma_word.scss
265
- - lib/isodoc/base_style/nav.css
266
260
  - lib/isodoc/base_style/nav.scss
267
- - lib/isodoc/base_style/reset.css
268
261
  - lib/isodoc/base_style/reset.scss
269
262
  - lib/isodoc/base_style/rouge.css
270
263
  - lib/isodoc/base_style/scripts.html
271
- - lib/isodoc/base_style/typography.css
272
264
  - lib/isodoc/base_style/typography.scss
273
265
  - lib/isodoc/bibdata_parser.rb
274
266
  - lib/isodoc/class_utils.rb