isodoc 2.6.6 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isodoc/convert.rb +1 -1
- data/lib/isodoc/html_function/postprocess_cover.rb +13 -2
- data/lib/isodoc/metadata_date.rb +1 -1
- data/lib/isodoc/presentation_function/bibdata.rb +37 -6
- data/lib/isodoc/presentation_function/inline.rb +35 -0
- data/lib/isodoc/presentation_xml_convert.rb +2 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref/xref_counter.rb +17 -9
- data/lib/isodoc/xref/xref_sect_gen.rb +17 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cf4eea4c89d6c8b67907883ac59beb80f11c58ce6a8646b98c78498ab716e09
|
4
|
+
data.tar.gz: 4645c6421411b736ec194cbf307de7d3285662f708e871356ce355e0fe53f716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeaa4541fc33975c131cfeb8781319ec97bc952f8bae99ef2f8699e9270a9e8894fef1dcb6f0948fffadac00405d05082ec7c6b03209057ee15986971e26f86f
|
7
|
+
data.tar.gz: 94788ad30cba5e36df220f2f080c81896d887a774405b5c3a0abc254bda6f70927fccde3a7fbf377b09d6e09331bb5f7a9a095c63599693d637234f4a38a2681
|
data/lib/isodoc/convert.rb
CHANGED
@@ -136,15 +136,26 @@ module IsoDoc
|
|
136
136
|
end
|
137
137
|
|
138
138
|
def html_toc_entries(docxml, path)
|
139
|
+
xml = html_toc_entries_prep(docxml, path)
|
139
140
|
path.each_with_index.with_object([]) do |(p, i), m|
|
140
|
-
|
141
|
-
h["id"] ||= "_#{UUIDTools::UUID.random_create}"
|
141
|
+
xml.xpath(p.join(" | ")).each do |h|
|
142
142
|
m << { entry: html_toc_entry("h#{i + 1}", h),
|
143
143
|
line: h.line }
|
144
144
|
end
|
145
145
|
end.sort_by { |k| k[:line] }
|
146
146
|
end
|
147
147
|
|
148
|
+
def html_toc_entries_prep(docxml, path)
|
149
|
+
path.each do |p|
|
150
|
+
docxml.xpath(p.join(" | ")).each do |h|
|
151
|
+
h["id"] ||= "_#{UUIDTools::UUID.random_create}"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
xml = Nokogiri::XML(docxml.to_xml, &:noblanks)
|
155
|
+
xml.remove_namespaces!
|
156
|
+
xml
|
157
|
+
end
|
158
|
+
|
148
159
|
def toc_exclude_class
|
149
160
|
"[not(@class = 'TermNum')][not(@class = 'noTOC')]" \
|
150
161
|
"[string-length(normalize-space(.))>0]"
|
data/lib/isodoc/metadata_date.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module IsoDoc
|
2
2
|
class Metadata
|
3
3
|
DATETYPES = %w{published accessed created implemented obsoleted confirmed
|
4
|
-
updated issued received transmitted copied unchanged
|
4
|
+
updated corrected issued received transmitted copied unchanged
|
5
5
|
circulated vote-started
|
6
6
|
vote-ended}.freeze
|
7
7
|
|
@@ -17,7 +17,8 @@ module IsoDoc
|
|
17
17
|
|
18
18
|
def extension_insert(docxml, path = [])
|
19
19
|
ins = docxml.at(ns("//metanorma-extension")) ||
|
20
|
-
docxml.at(ns("//bibdata"))
|
20
|
+
docxml.at(ns("//bibdata"))&.after("<metanorma-extension/>")&.next_element ||
|
21
|
+
docxml.root.elements.first.before("<metanorma-extension/>").previous_element
|
21
22
|
path.each do |n|
|
22
23
|
ins = ins.at(ns("./#{n}")) || ins.add_child("<#{n}/>").first
|
23
24
|
end
|
@@ -25,9 +26,39 @@ module IsoDoc
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def preprocess_xslt_insert(docxml)
|
28
|
-
content =
|
29
|
+
content = ""
|
30
|
+
p = passthrough_xslt and content += p
|
31
|
+
p = preprocess_xslt_read and content += File.read(p)
|
32
|
+
content.empty? and return
|
29
33
|
ins = extension_insert(docxml, %w(render))
|
30
|
-
ins <<
|
34
|
+
ins << content
|
35
|
+
end
|
36
|
+
|
37
|
+
def passthrough_xslt
|
38
|
+
@output_formats.nil? and return nil
|
39
|
+
@output_formats.empty? and return nil
|
40
|
+
@output_formats.each_key.with_object([]) do |k, m|
|
41
|
+
m << <<~XSLT
|
42
|
+
<preprocess-xslt format="#{k}">
|
43
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
|
44
|
+
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
|
45
|
+
<xsl:strip-space elements="*"/>
|
46
|
+
<xsl:template match="@* | node()">
|
47
|
+
<xsl:copy>
|
48
|
+
<xsl:apply-templates select="@* | node()"/>
|
49
|
+
</xsl:copy>
|
50
|
+
</xsl:template>
|
51
|
+
<xsl:template match="*[local-name() = 'passthrough']">
|
52
|
+
<xsl:if test="contains(@formats,',#{k},')"> <!-- delimited -->
|
53
|
+
<xsl:copy>
|
54
|
+
<xsl:apply-templates select="@* | node()"/>
|
55
|
+
</xsl:copy>
|
56
|
+
</xsl:if>
|
57
|
+
</xsl:template>
|
58
|
+
</xsl:stylesheet>
|
59
|
+
</preprocess-xslt>
|
60
|
+
XSLT
|
61
|
+
end.join("\n")
|
31
62
|
end
|
32
63
|
|
33
64
|
# read in from file, but with `<preprocess-xslt @format="">` wrapper
|
@@ -45,7 +76,7 @@ module IsoDoc
|
|
45
76
|
ins << "<toc type='table'><title>#{@i18n.toc_tables}</title></toc>"
|
46
77
|
@tocfigures and
|
47
78
|
ins << "<toc type='recommendation'><title>#{@i18n.toc_recommendations}" \
|
48
|
-
|
79
|
+
"</title></toc>"
|
49
80
|
end
|
50
81
|
|
51
82
|
def address_precompose(bib)
|
@@ -152,8 +183,8 @@ module IsoDoc
|
|
152
183
|
when Array
|
153
184
|
hash.reject { |a| blank?(a) }.each_with_object([])
|
154
185
|
.with_index do |(v1, g), i|
|
155
|
-
|
156
|
-
|
186
|
+
i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
|
187
|
+
end
|
157
188
|
else [i18n_tag(pref, hash)]
|
158
189
|
end
|
159
190
|
end
|
@@ -99,8 +99,43 @@ module IsoDoc
|
|
99
99
|
elem.replace(@i18n.date(elem["value"], elem["format"].strip))
|
100
100
|
end
|
101
101
|
|
102
|
+
def inline_format(docxml)
|
103
|
+
custom_charset(docxml)
|
104
|
+
end
|
105
|
+
|
106
|
+
def custom_charset(docxml)
|
107
|
+
charsets = extract_custom_charsets(docxml)
|
108
|
+
docxml.xpath(ns("//span[@custom-charset]")).each do |s|
|
109
|
+
s["style"] ||= ""
|
110
|
+
s["style"] += ";font-family:#{charsets[s['custom-charset']]}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def passthrough(docxml)
|
115
|
+
formats = @output_formats.keys
|
116
|
+
docxml.xpath(ns("//passthrough")).each do |p|
|
117
|
+
passthrough1(p, formats)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def passthrough1(elem, formats)
|
122
|
+
(elem["formats"] && !elem["formats"].empty?) or elem["formats"] = "all"
|
123
|
+
f = elem["formats"].split(",")
|
124
|
+
(f - formats).size == f.size or elem["formats"] = "all"
|
125
|
+
elem["formats"] == "all" and elem["formats"] = formats.join(",")
|
126
|
+
elem["formats"] = ",#{elem['formats']},"
|
127
|
+
end
|
128
|
+
|
102
129
|
private
|
103
130
|
|
131
|
+
def extract_custom_charsets(docxml)
|
132
|
+
docxml.xpath(ns("//presentation-metadata/custom-charset-font")).
|
133
|
+
each_with_object({}) do |x, m|
|
134
|
+
kv = x.text.split(":", 2)
|
135
|
+
m[kv[0]] = kv[1]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
104
139
|
def found_matching_variant_sibling(node)
|
105
140
|
prev = node.xpath("./preceding-sibling::xmlns:variant")
|
106
141
|
foll = node.xpath("./following-sibling::xmlns:variant")
|
data/lib/isodoc/version.rb
CHANGED
@@ -15,15 +15,17 @@ module IsoDoc
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class Counter
|
18
|
+
attr_accessor :prefix_override
|
19
|
+
|
18
20
|
def initialize(num = 0, opts = { numerals: :arabic })
|
19
21
|
@unnumbered = false
|
20
22
|
@num = num
|
21
23
|
@letter = ""
|
22
24
|
@subseq = ""
|
23
|
-
|
24
|
-
@number_override = nil
|
25
|
+
reset_overrides
|
25
26
|
@style = opts[:numerals]
|
26
27
|
@skip_i = opts[:skip_i]
|
28
|
+
@prefix = opts[:prefix]
|
27
29
|
@base = ""
|
28
30
|
if num.is_a? String
|
29
31
|
if /^\d+$/.match?(num)
|
@@ -36,6 +38,12 @@ module IsoDoc
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
41
|
+
def reset_overrides
|
42
|
+
@letter_override = nil
|
43
|
+
@number_override = nil
|
44
|
+
@prefix_override = nil
|
45
|
+
end
|
46
|
+
|
39
47
|
def new_subseq_increment(node)
|
40
48
|
@subseq = node["subsequence"]
|
41
49
|
@num += 1 unless @num.nil?
|
@@ -57,7 +65,9 @@ module IsoDoc
|
|
57
65
|
end
|
58
66
|
|
59
67
|
def sequence_increment(node)
|
60
|
-
if node["number"]
|
68
|
+
if node["branch-number"]
|
69
|
+
@prefix_override = node["branch-number"]
|
70
|
+
elsif node["number"]
|
61
71
|
@base = @letter_override = @number_override = ""
|
62
72
|
/^(?<b>.*?)(?<n>\d+)$/ =~ node["number"]
|
63
73
|
if blank?(n)
|
@@ -130,9 +140,7 @@ module IsoDoc
|
|
130
140
|
|
131
141
|
def increment(node)
|
132
142
|
@unnumbered = (node["unnumbered"] || node["hidden"]) and return self
|
133
|
-
|
134
|
-
@letter_override = nil
|
135
|
-
@number_override = nil
|
143
|
+
reset_overrides
|
136
144
|
if node["subsequence"] != @subseq &&
|
137
145
|
!(blank?(node["subsequence"]) && blank?(@subseq))
|
138
146
|
new_subseq_increment(node)
|
@@ -143,11 +151,11 @@ module IsoDoc
|
|
143
151
|
end
|
144
152
|
|
145
153
|
def print
|
146
|
-
return nil
|
147
|
-
|
154
|
+
@unnumbered and return nil
|
155
|
+
@prefix_override and return @prefix_override
|
148
156
|
num = @number_override || @num
|
149
157
|
out = @style == :roman && !num.nil? ? RomanNumerals.to_roman(num) : num
|
150
|
-
"#{@base}#{out}#{@letter_override || @letter}"
|
158
|
+
"#{@prefix}#{@base}#{out}#{@letter_override || @letter}"
|
151
159
|
end
|
152
160
|
|
153
161
|
def ol_type(list, depth)
|
@@ -14,12 +14,13 @@ module IsoDoc
|
|
14
14
|
|
15
15
|
def clause_order_main(docxml)
|
16
16
|
[
|
17
|
-
{ path: "//clause[@type = 'scope']" },
|
17
|
+
{ path: "//sections/clause[@type = 'scope']" },
|
18
18
|
{ path: @klass.norm_ref_xpath },
|
19
19
|
{ path: "//sections/terms | " \
|
20
|
-
|
20
|
+
"//sections/clause[descendant::terms]" },
|
21
21
|
{ path: "//sections/definitions | " \
|
22
|
-
|
22
|
+
"//sections/clause[descendant::definitions]" \
|
23
|
+
"[not(descendant::terms)]" },
|
23
24
|
{ path: @klass.middle_clause(docxml), multi: true },
|
24
25
|
]
|
25
26
|
end
|
@@ -168,17 +169,18 @@ module IsoDoc
|
|
168
169
|
clause.nil? and return num
|
169
170
|
num.increment(clause)
|
170
171
|
section_name_anchors(clause, num.print, lvl)
|
171
|
-
clause.xpath(ns(SUBCLAUSES))
|
172
|
-
|
172
|
+
clause.xpath(ns(SUBCLAUSES))
|
173
|
+
.each_with_object(Counter.new(0, prefix: "#{num.print}.")) do |c, i|
|
174
|
+
section_names1(c, i.increment(c).print, lvl + 1)
|
173
175
|
end
|
174
176
|
num
|
175
177
|
end
|
176
178
|
|
177
179
|
def section_names1(clause, num, level)
|
178
180
|
section_name_anchors(clause, num, level)
|
179
|
-
i = Counter.new
|
181
|
+
i = Counter.new(0, prefix: "#{num}.")
|
180
182
|
clause.xpath(ns(SUBCLAUSES)).each do |c|
|
181
|
-
section_names1(c,
|
183
|
+
section_names1(c, i.increment(c).print, level + 1)
|
182
184
|
end
|
183
185
|
end
|
184
186
|
|
@@ -216,8 +218,9 @@ module IsoDoc
|
|
216
218
|
annex_names1(clause.at(ns("./references | ./terms | ./definitions")),
|
217
219
|
num.to_s, 1)
|
218
220
|
else
|
219
|
-
clause.xpath(ns(SUBCLAUSES))
|
220
|
-
|
221
|
+
clause.xpath(ns(SUBCLAUSES))
|
222
|
+
.each_with_object(Counter.new(0, prefix: "#{num}.")) do |c, i|
|
223
|
+
annex_names1(c, i.increment(c).print, 2)
|
221
224
|
end
|
222
225
|
end
|
223
226
|
hierarchical_asset_names(clause, num)
|
@@ -225,18 +228,18 @@ module IsoDoc
|
|
225
228
|
|
226
229
|
def annex_names1(clause, num, level)
|
227
230
|
annex_name_anchors(clause, num, level)
|
228
|
-
i = Counter.new
|
231
|
+
i = Counter.new(0, prefix: "#{num}.")
|
229
232
|
clause.xpath(ns(SUBCLAUSES)).each do |c|
|
230
|
-
annex_names1(c,
|
233
|
+
annex_names1(c, i.increment(c).print, level + 1)
|
231
234
|
end
|
232
235
|
end
|
233
236
|
|
234
237
|
def reference_names(ref)
|
235
238
|
ids = @klass.bibitem_ref_code(ref)
|
236
239
|
identifiers = @klass.render_identifier(ids)
|
237
|
-
reference = @klass
|
238
|
-
|
239
|
-
|
240
|
+
reference = @klass.
|
241
|
+
docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
|
242
|
+
identifiers[:ordinal] || identifiers[:doi])
|
240
243
|
@anchors[ref["id"]] = { xref: reference }
|
241
244
|
end
|
242
245
|
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: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html2doc
|