isodoc 3.7.17 → 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 +4 -4
- data/lib/isodoc/bibdata_parser.rb +101 -0
- data/lib/isodoc/gem_tasks.rb +43 -7
- data/lib/isodoc/html_function/postprocess.rb +2 -1
- data/lib/isodoc/html_function/postprocess_cover.rb +23 -1
- data/lib/isodoc/metadata_bibdata.rb +5 -5
- data/lib/isodoc/presentation_function/refs.rb +16 -0
- data/lib/isodoc/presentation_function/xrefs.rb +10 -1
- data/lib/isodoc/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 389417e16e4478a83ea47d49cd0032ed7bf0ba0b4578f3608c94278d76ea7ebd
|
|
4
|
+
data.tar.gz: 248384d71365868e13e92b0f0eff4ffacc3cf787e3e23279e84b4fa6b789a9e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 717730f8158fd65959191add83d389e407b5ab3bf5072ffcce72e07a1a9d95c463bdd8dfe4f92d724498e39d6387c60aefcc072c5fc59096dfb29df9535e86cf
|
|
7
|
+
data.tar.gz: badc6e3bf2e2067c8a6a224012a27de79195a0464f8c62db2fba2f714c1feb74200e9d06eb60983c7dd9d8232b4623a3c65399c27e4fa5d06258b06a66266baf
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "moxml"
|
|
4
|
+
require "relaton"
|
|
5
|
+
require "relaton/bib"
|
|
6
|
+
|
|
7
|
+
module IsoDoc
|
|
8
|
+
# Bibdata ingestion through relaton's library surface, not Relaton::Cli.
|
|
9
|
+
#
|
|
10
|
+
# Same pattern as Metanorma::Collection::Config::BibdataParser
|
|
11
|
+
# (metanorma/metanorma#716), which mirrors the flavor dispatch of
|
|
12
|
+
# relaton cli.rb parse_xml: the processor is named by the first
|
|
13
|
+
# docidentifier's type, else by the leading word of its text. It takes
|
|
14
|
+
# an XML String, so it behaves the same on relaton releases before and
|
|
15
|
+
# after 3.1.6, where Cli.parse_xml changed from a Nokogiri document to a
|
|
16
|
+
# String argument.
|
|
17
|
+
module BibdataParser
|
|
18
|
+
class << self
|
|
19
|
+
# @param xml [String] serialized bibdata or bibitem XML
|
|
20
|
+
# @return [Relaton::Bib::ItemData, nil] nil when the source is not
|
|
21
|
+
# parseable XML
|
|
22
|
+
def from_xml(xml)
|
|
23
|
+
return unless xml
|
|
24
|
+
|
|
25
|
+
doc = Moxml.new.parse(xml)
|
|
26
|
+
plain = without_namespaces(doc)
|
|
27
|
+
processor = processor_for_xml(doc)
|
|
28
|
+
processor ? processor.from_xml(plain) : generic_from_xml(plain)
|
|
29
|
+
rescue Moxml::ParseError
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
# No-flavor fallback: unparseable sources degrade to a nil bibdata,
|
|
36
|
+
# as in the mirrored Cli method.
|
|
37
|
+
def generic_from_xml(plain)
|
|
38
|
+
Relaton::Bib::Item.from_xml(plain)
|
|
39
|
+
rescue StandardError
|
|
40
|
+
nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The processor named by the first docidentifier's type, else by
|
|
44
|
+
# the first word of its text.
|
|
45
|
+
def processor_for_xml(doc)
|
|
46
|
+
docid = doc.xpath("//*[local-name()='docidentifier']").first
|
|
47
|
+
return unless docid
|
|
48
|
+
|
|
49
|
+
get_proc(docid) ||
|
|
50
|
+
Relaton::Db::Registry.instance.by_type(docid.text[/^\w+/])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def get_proc(docid)
|
|
54
|
+
type = docid["type"]
|
|
55
|
+
return unless type
|
|
56
|
+
|
|
57
|
+
Relaton::Db::Registry.instance.by_type(type)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# The root element as XML, with every element and attribute in no
|
|
61
|
+
# namespace (`xml:` attributes keep their prefix). The lutaml-model
|
|
62
|
+
# mappings are namespace-free, and Moxml cannot drop a namespace in
|
|
63
|
+
# place, so this builds a copy.
|
|
64
|
+
def without_namespaces(doc)
|
|
65
|
+
plain = Moxml.new.create_document
|
|
66
|
+
plain.add_child plain_element(plain, doc.root)
|
|
67
|
+
plain.root.to_xml
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def plain_element(doc, src)
|
|
71
|
+
elm = doc.create_element(src.name)
|
|
72
|
+
# An attribute in no namespace wins over a prefixed one of the
|
|
73
|
+
# same local name (`type` over `a:type`).
|
|
74
|
+
src.attributes.sort_by { |a| a.namespace ? 0 : 1 }.each do |attr|
|
|
75
|
+
elm[plain_name(attr)] = attr.value
|
|
76
|
+
end
|
|
77
|
+
src.children.each { |child| elm.add_child plain_node(doc, child) }
|
|
78
|
+
elm
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# The local name; an `xml:` attribute keeps its prefix.
|
|
82
|
+
def plain_name(attr)
|
|
83
|
+
attr.namespace&.prefix == "xml" ? "xml:#{attr.name}" : attr.name
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# An entity reference (` `) stays as its text: lutaml-model
|
|
87
|
+
# cannot read an entity it has no declaration for. A processing
|
|
88
|
+
# instruction becomes an empty text.
|
|
89
|
+
def plain_node(doc, src)
|
|
90
|
+
case src
|
|
91
|
+
when Moxml::Element then plain_element(doc, src)
|
|
92
|
+
when Moxml::Cdata then doc.create_cdata(src.content)
|
|
93
|
+
when Moxml::Text then doc.create_text(src.content)
|
|
94
|
+
when Moxml::Comment then doc.create_comment(src.content)
|
|
95
|
+
when Moxml::EntityReference then doc.create_text("&#{src.name};")
|
|
96
|
+
else doc.create_text("")
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
data/lib/isodoc/gem_tasks.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
157
|
-
|
|
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"] =
|
|
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"] ||=
|
|
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]"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require "relaton"
|
|
2
2
|
require "relaton/bib"
|
|
3
|
-
|
|
3
|
+
require_relative "bibdata_parser"
|
|
4
4
|
|
|
5
5
|
module IsoDoc
|
|
6
6
|
class BibdataConfig < ::Lutaml::Model::Serializable
|
|
@@ -16,12 +16,12 @@ module IsoDoc
|
|
|
16
16
|
to: :bibdata_to_xml }
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# Through relaton's library surface, as metanorma#716 does for
|
|
20
|
+
# collections. Under the moxml/leptris adapter the mapping node's
|
|
21
|
+
# native is not Nokogiri, so go through markup.
|
|
19
22
|
def bibdata_from_xml(model, node)
|
|
20
23
|
node or return
|
|
21
|
-
|
|
22
|
-
# (remove_namespaces!, at); under the moxml/leptris adapter the
|
|
23
|
-
# mapping node's native is not Nokogiri. Convert via markup.
|
|
24
|
-
model.bibdata = Relaton::Cli.parse_xml(Nokogiri::XML(node.to_xml))
|
|
24
|
+
model.bibdata = BibdataParser.from_xml(node.to_xml)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def bibdata_to_xml(model, parent, doc); end
|
|
@@ -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
|
|
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
|
data/lib/isodoc/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -270,6 +270,7 @@ files:
|
|
|
270
270
|
- lib/isodoc/base_style/scripts.html
|
|
271
271
|
- lib/isodoc/base_style/typography.css
|
|
272
272
|
- lib/isodoc/base_style/typography.scss
|
|
273
|
+
- lib/isodoc/bibdata_parser.rb
|
|
273
274
|
- lib/isodoc/class_utils.rb
|
|
274
275
|
- lib/isodoc/common.rb
|
|
275
276
|
- lib/isodoc/convert.rb
|