isodoc 3.7.20 → 3.7.22
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 +4 -4
- data/lib/isodoc/asset_store.rb +46 -0
- data/lib/isodoc/convert.rb +18 -11
- data/lib/isodoc/function/blocks.rb +1 -1
- data/lib/isodoc/function/footnotes.rb +36 -5
- data/lib/isodoc/function/setup.rb +39 -9
- data/lib/isodoc/headlesshtml_convert.rb +15 -9
- data/lib/isodoc/html_convert.rb +23 -9
- data/lib/isodoc/html_function/postprocess.rb +34 -15
- data/lib/isodoc/init.rb +2 -2
- data/lib/isodoc/pdf_convert.rb +10 -8
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_convert.rb +4 -5
- data/lib/isodoc/word_function/footnotes.rb +18 -7
- data/lib/isodoc/word_function/postprocess_cover.rb +3 -1
- data/lib/isodoc/word_function/postprocess_toc.rb +1 -1
- data/lib/isodoc/xslfo_convert.rb +2 -5
- data/lib/isodoc.rb +1 -0
- metadata +3 -11
- data/lib/isodoc/base_style/all.css +0 -463
- data/lib/isodoc/base_style/bands.css +0 -135
- data/lib/isodoc/base_style/blocks.css +0 -0
- data/lib/isodoc/base_style/coverpage.css +0 -0
- data/lib/isodoc/base_style/defaults.css +0 -0
- data/lib/isodoc/base_style/metanorma_word.css +0 -72
- data/lib/isodoc/base_style/nav.css +0 -0
- data/lib/isodoc/base_style/reset.css +0 -327
- data/lib/isodoc/base_style/typography.css +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dbf70f2270108a9954659cb9a101a731e81c333e9d7b8b2206888bb3a6d7cd99
|
|
4
|
+
data.tar.gz: c33ceb407707efcc89acbb01d913bc68d0aed61c5722d2afe7e76927b67226a8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 647e985063f6a163df57c24e278eab3b5b57c4755bd3f9423b0aecf1a42d510bb3d808ee35a5427cdcfadc5263b20ba8740989a539448591e9a828ba8f501b6d
|
|
7
|
+
data.tar.gz: 82e7df3303fad27057a4104b271fea4ee42696e86811e972bacf03d2670beea904abfa253637dd893217a868b3d8322083e56240a34501b5f03fe1849bff6a9d
|
|
@@ -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
|
data/lib/isodoc/convert.rb
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
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,
|
|
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
|
-
|
|
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"]
|
|
53
|
-
attrs = { class: "FootnoteRef", href: "
|
|
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
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
#
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
strip_head("#{filename}
|
|
28
|
-
|
|
29
|
-
|
|
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)
|
data/lib/isodoc/html_convert.rb
CHANGED
|
@@ -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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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 & 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
|
-
@
|
|
120
|
-
@
|
|
119
|
+
@workdir = options[:workdir]
|
|
120
|
+
@workdir_owner = @workdir.nil?
|
|
121
121
|
@sourcefilename = options[:sourcefilename]
|
|
122
122
|
@files_to_delete = []
|
|
123
123
|
@tempfile_cache = []
|
data/lib/isodoc/pdf_convert.rb
CHANGED
|
@@ -14,10 +14,11 @@ module IsoDoc
|
|
|
14
14
|
@maxheight = 800
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
+
tmp_html,
|
|
32
33
|
output_filename || "#{filename}.#{@suffix}",
|
|
33
34
|
)
|
|
34
|
-
|
|
35
|
+
ensure
|
|
36
|
+
teardown_workdir unless debug
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
def xref_parse(node, out)
|
data/lib/isodoc/version.rb
CHANGED
data/lib/isodoc/word_convert.rb
CHANGED
|
@@ -16,10 +16,9 @@ module IsoDoc
|
|
|
16
16
|
super
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
module IsoDoc
|
|
2
2
|
module WordFunction
|
|
3
3
|
module Footnotes
|
|
4
|
+
# Word bookmark ids for _Toc and _Ref bookmarks. Minted from a
|
|
5
|
+
# document-scoped counter so that DOCX output is deterministic:
|
|
6
|
+
# identical input yields identical ids on every run (isodoc#923).
|
|
7
|
+
# The `%09d` shape keeps Word's _TocNNNNNNNNN convention.
|
|
4
8
|
def bookmarkid
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
9
|
+
@bookmarkid_counter ||= 0
|
|
10
|
+
ret = @bookmarkid_counter += 1
|
|
11
|
+
ret += 1 while @bookmarks_allocated[ret]
|
|
9
12
|
@bookmarks_allocated[ret] = true
|
|
10
|
-
|
|
13
|
+
@bookmarkid_counter = ret
|
|
14
|
+
format "%09d", ret
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Word footnote body id scheme: `ftn` prefix, no colon (Word bookmark
|
|
18
|
+
# names may not contain punctuation). Pairs with `fn_body_id` so that
|
|
19
|
+
# footnote anchors and their bodies cannot drift apart.
|
|
20
|
+
def fn_body_id(id)
|
|
21
|
+
"ftn#{id}"
|
|
11
22
|
end
|
|
12
23
|
|
|
13
24
|
def fmt_fn_body_parse(node, out)
|
|
@@ -15,7 +26,7 @@ module IsoDoc
|
|
|
15
26
|
aside = node.parent.name == "fmt-footnote-container"
|
|
16
27
|
tag = aside ? "aside" : "div"
|
|
17
28
|
id = node["is_table"] ? node["reference"] : node["id"]
|
|
18
|
-
out.send tag, id:
|
|
29
|
+
out.send tag, id: fn_body_id(id) do |div|
|
|
19
30
|
children_parse(node, div)
|
|
20
31
|
end
|
|
21
32
|
end
|
|
@@ -63,7 +74,7 @@ module IsoDoc
|
|
|
63
74
|
semx.name = "a"
|
|
64
75
|
semx["class"] = "FootnoteRef"
|
|
65
76
|
semx["epub:type"] = "footnote"
|
|
66
|
-
semx["href"] = "
|
|
77
|
+
semx["href"] = "##{fn_body_id(node['target'])}"
|
|
67
78
|
end
|
|
68
79
|
end
|
|
69
80
|
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
|
-
|
|
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)
|
|
@@ -32,7 +32,7 @@ module IsoDoc
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def word_toc_entry(toclevel, heading)
|
|
35
|
-
bookmark = bookmarkid
|
|
35
|
+
bookmark = bookmarkid
|
|
36
36
|
<<~TOC
|
|
37
37
|
<p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span lang="EN-GB" style='mso-no-proof:yes'>
|
|
38
38
|
<a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB" class="MsoTocTextSpan">
|
data/lib/isodoc/xslfo_convert.rb
CHANGED
|
@@ -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
|