isodoc 2.3.5 → 2.4.0
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/isodoc.gemspec +1 -2
- data/lib/isodoc/base_style/nav.scss +12 -0
- data/lib/isodoc/class_utils.rb +6 -1
- data/lib/isodoc/convert.rb +4 -4
- data/lib/isodoc/function/cleanup.rb +1 -1
- data/lib/isodoc/function/inline_simple.rb +2 -1
- data/lib/isodoc/function/utils.rb +4 -0
- data/lib/isodoc/html_function/html.rb +4 -2
- data/lib/isodoc/metadata_contributor.rb +21 -15
- data/lib/isodoc/presentation_function/bibdata.rb +9 -9
- data/lib/isodoc/presentation_function/erefs.rb +182 -0
- data/lib/isodoc/presentation_function/inline.rb +13 -164
- data/lib/isodoc/presentation_function/refs.rb +1 -1
- data/lib/isodoc/presentation_function/section.rb +1 -1
- data/lib/isodoc/presentation_function/terms.rb +15 -15
- data/lib/isodoc/presentation_function/xrefs.rb +31 -13
- data/lib/isodoc/presentation_xml_convert.rb +4 -2
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/postprocess_cover.rb +83 -58
- data/lib/isodoc/xref/xref_gen.rb +11 -11
- metadata +6 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a7c100c4751a8d8bfe69eeaf31614c74bfeec4c56d188fd0d4a6a16c09d3257
|
4
|
+
data.tar.gz: '0858086207425a9c38bb6f12fba1a219599c4c7e469aea40e4f29255f152333b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc74e409e73b0b63f5a609e44b0a90a88cf4e83253604cbf6634f62b9c6ff12cccdc40fa2399acd4c373c44d3748ff311828890f319fc508c35e4993c88ff800
|
7
|
+
data.tar.gz: b6f7d0abe389ee3c0342fbdd862f0671bc94959eb9f7b3755e51c7aac1aad74e65127b8819f5b3f310a8e2c2ede29dd663642f9a16e12b5fdf563dd9e2e9bb4f
|
data/isodoc.gemspec
CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_dependency "mathml2asciimath"
|
40
40
|
spec.add_dependency "metanorma-utils", "~> 1.4.5"
|
41
41
|
spec.add_dependency "mn2pdf"
|
42
|
-
spec.add_dependency "mn-requirements", "~> 0.
|
42
|
+
spec.add_dependency "mn-requirements", "~> 0.3.1"
|
43
43
|
spec.add_dependency "relaton-cli"
|
44
44
|
spec.add_dependency "relaton-render", "~> 0.5.2"
|
45
45
|
spec.add_dependency "roman-numerals"
|
@@ -52,7 +52,6 @@ Gem::Specification.new do |spec|
|
|
52
52
|
spec.add_development_dependency "guard", "~> 2.14"
|
53
53
|
spec.add_development_dependency "guard-rspec", "~> 4.7"
|
54
54
|
spec.add_development_dependency "rake", "~> 13.0"
|
55
|
-
spec.add_development_dependency "rexml"
|
56
55
|
spec.add_development_dependency "rspec", "~> 3.6"
|
57
56
|
spec.add_development_dependency "rubocop", "~> 1.5.2"
|
58
57
|
spec.add_development_dependency "sassc", "~> 2.4.0"
|
@@ -30,6 +30,18 @@
|
|
30
30
|
padding-left: 50px;
|
31
31
|
}
|
32
32
|
|
33
|
+
.h4 {
|
34
|
+
padding-left: 70px;
|
35
|
+
}
|
36
|
+
|
37
|
+
.h5 {
|
38
|
+
padding-left: 90px;
|
39
|
+
}
|
40
|
+
|
41
|
+
.h6 {
|
42
|
+
padding-left: 110px;
|
43
|
+
}
|
44
|
+
|
33
45
|
.toc-active, li:hover {
|
34
46
|
background: $colorLinkActiveBg;
|
35
47
|
box-shadow: inset -5px 0px 10px -5px $colorLinkActiveBg !important;
|
data/lib/isodoc/class_utils.rb
CHANGED
@@ -47,6 +47,11 @@ module IsoDoc
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
def to_xml(node)
|
51
|
+
node&.to_xml(encoding: "UTF-8", indent: 0,
|
52
|
+
save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
|
53
|
+
end
|
54
|
+
|
50
55
|
def case_with_markup(linkend, casing, script, firstonly: true)
|
51
56
|
seen = false
|
52
57
|
xml = Nokogiri::XML("<root>#{linkend}</root>")
|
@@ -57,7 +62,7 @@ module IsoDoc
|
|
57
62
|
firstonly: firstonly))
|
58
63
|
seen = true if firstonly
|
59
64
|
end
|
60
|
-
xml.root.children
|
65
|
+
to_xml(xml.root.children)
|
61
66
|
end
|
62
67
|
|
63
68
|
def nearest_block_parent(node)
|
data/lib/isodoc/convert.rb
CHANGED
@@ -38,7 +38,7 @@ module IsoDoc
|
|
38
38
|
# scripts_override: Override scripts file for HTML
|
39
39
|
# scripts_pdf: Scripts file for PDF (not used in XSLT PDF)
|
40
40
|
# datauriimage: Encode images in HTML output as data URIs
|
41
|
-
#
|
41
|
+
# breakupurlsintables: whether to insert spaces in URLs in tables
|
42
42
|
# every 40-odd chars
|
43
43
|
# sectionsplit: split up HTML output on sections
|
44
44
|
# bare: do not insert any prefatory material (coverpage, boilerplate)
|
@@ -74,7 +74,7 @@ module IsoDoc
|
|
74
74
|
@olstyle = options[:olstyle]
|
75
75
|
@datauriimage = options[:datauriimage]
|
76
76
|
@suppressheadingnumbers = options[:suppressheadingnumbers]
|
77
|
-
@break_up_urls_in_tables = options[:
|
77
|
+
@break_up_urls_in_tables = options[:breakupurlsintables]
|
78
78
|
@sectionsplit = options[:sectionsplit] == "true"
|
79
79
|
@suppressasciimathdup = options[:suppressasciimathdup] == "true"
|
80
80
|
@bare = options[:bare]
|
@@ -151,9 +151,9 @@ module IsoDoc
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def init_toc(options)
|
154
|
-
@wordToClevels = options[:doctoclevels].to_i
|
154
|
+
@wordToClevels = (options[:doctoclevels] || options[:toclevels]).to_i
|
155
155
|
@wordToClevels = 2 if @wordToClevels.zero?
|
156
|
-
@htmlToClevels = options[:htmltoclevels].to_i
|
156
|
+
@htmlToClevels = (options[:htmltoclevels] || options[:toclevels]).to_i
|
157
157
|
@htmlToClevels = 2 if @htmlToClevels.zero?
|
158
158
|
@tocfigures = options[:tocfigures]
|
159
159
|
@toctables = options[:toctables]
|
@@ -78,7 +78,7 @@ module IsoDoc
|
|
78
78
|
def html_button
|
79
79
|
return "" if @bare
|
80
80
|
|
81
|
-
'<button onclick="topFunction()" id="myBtn" '\
|
81
|
+
'<button onclick="topFunction()" id="myBtn" ' \
|
82
82
|
'title="Go to top">Top</button>'.freeze
|
83
83
|
end
|
84
84
|
|
@@ -121,7 +121,9 @@ module IsoDoc
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def underline_parse(node, out)
|
124
|
-
|
124
|
+
style = node["style"] ? " #{node['style']}" : ""
|
125
|
+
attr = { style: "text-decoration: underline#{style}" }
|
126
|
+
out.span **attr do |e|
|
125
127
|
node.children.each { |n| parse(n, e) }
|
126
128
|
end
|
127
129
|
end
|
@@ -2,23 +2,29 @@ module IsoDoc
|
|
2
2
|
class Metadata
|
3
3
|
def extract_person_names(authors)
|
4
4
|
authors.reduce([]) do |ret, a|
|
5
|
-
if a.at(ns("./name/completename"))
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
ret << "#{fn.join(' ')} #{a&.at(ns('./name/surname'))&.text}"
|
11
|
-
end
|
5
|
+
ret << if a.at(ns("./name/completename"))
|
6
|
+
a.at(ns("./name/completename")).text
|
7
|
+
else
|
8
|
+
extract_person_name_from_components(a)
|
9
|
+
end
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
13
|
+
def extract_person_name_from_components(person)
|
14
|
+
name = person.xpath(ns("./name/forename"))
|
15
|
+
name.empty? and name = person.xpath(ns("./name/formatted-initials"))
|
16
|
+
out = name.map(&:text)
|
17
|
+
out << person.at(ns("./name/surname"))&.text
|
18
|
+
l10n(out.compact.join(" "))
|
19
|
+
end
|
20
|
+
|
15
21
|
def extract_person_affiliations(authors)
|
16
22
|
authors.reduce([]) do |m, a|
|
17
|
-
name = a
|
18
|
-
subdivs = a
|
23
|
+
name = a.at(ns("./affiliation/organization/name"))&.text
|
24
|
+
subdivs = a.xpath(ns("./affiliation/organization/subdivision"))&.map(&:text)&.join(", ")
|
19
25
|
name and subdivs and !subdivs.empty? and
|
20
26
|
name = l10n("#{name}, #{subdivs}")
|
21
|
-
location = a
|
27
|
+
location = a.at(ns("./affiliation/organization/address/formattedAddress"))&.text
|
22
28
|
m << (if !name.nil? && !location.nil?
|
23
29
|
l10n("#{name}, #{location}")
|
24
30
|
else
|
@@ -40,7 +46,7 @@ module IsoDoc
|
|
40
46
|
end
|
41
47
|
|
42
48
|
def personal_authors(isoxml)
|
43
|
-
authors = isoxml.xpath(ns("//bibdata/contributor[role/@type = 'author' "\
|
49
|
+
authors = isoxml.xpath(ns("//bibdata/contributor[role/@type = 'author' " \
|
44
50
|
"or xmlns:role/@type = 'editor']/person"))
|
45
51
|
set(:authors, extract_person_names(authors))
|
46
52
|
set(:authors_affiliations, extract_person_names_affiliations(authors))
|
@@ -61,10 +67,10 @@ module IsoDoc
|
|
61
67
|
def agency1(xml)
|
62
68
|
agency = ""
|
63
69
|
publisher = []
|
64
|
-
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\
|
70
|
+
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/" \
|
65
71
|
"organization")).each do |org|
|
66
|
-
name = org
|
67
|
-
agency1 = org
|
72
|
+
name = org.at(ns("./name"))&.text
|
73
|
+
agency1 = org.at(ns("./abbreviation"))&.text || name
|
68
74
|
publisher << name if name
|
69
75
|
agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
|
70
76
|
end
|
@@ -79,7 +85,7 @@ module IsoDoc
|
|
79
85
|
end
|
80
86
|
|
81
87
|
def agency_addr(xml)
|
82
|
-
a = xml.at(ns("//bibdata/contributor[xmlns:role/@type = 'publisher'][1]/"\
|
88
|
+
a = xml.at(ns("//bibdata/contributor[xmlns:role/@type = 'publisher'][1]/" \
|
83
89
|
"organization")) or return
|
84
90
|
{ subdivision: "./subdivision", pub_phone: "./phone[not(@type = 'fax')]",
|
85
91
|
pub_fax: "./phone[@type = 'fax']", pub_email: "./email",
|
@@ -10,7 +10,7 @@ module IsoDoc
|
|
10
10
|
address_precompose(a)
|
11
11
|
bibdata_i18n(a)
|
12
12
|
a.next =
|
13
|
-
"<localized-strings>#{i8n_name(trim_hash(@i18n.get), '').join}"\
|
13
|
+
"<localized-strings>#{i8n_name(trim_hash(@i18n.get), '').join}" \
|
14
14
|
"</localized-strings>"
|
15
15
|
end
|
16
16
|
|
@@ -24,7 +24,7 @@ module IsoDoc
|
|
24
24
|
@toctables and
|
25
25
|
ins << "<toc type='table'><title>#{@i18n.toc_tables}</title></toc>"
|
26
26
|
@tocfigures and
|
27
|
-
ins << "<toc type='recommendation'><title>#{@i18n.toc_recommendations}"\
|
27
|
+
ins << "<toc type='recommendation'><title>#{@i18n.toc_recommendations}" \
|
28
28
|
"</title></toc>"
|
29
29
|
end
|
30
30
|
|
@@ -50,17 +50,17 @@ module IsoDoc
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def presmeta(name, value)
|
53
|
-
"<presentation-metadata><name>#{name}</name><value>#{value}</value>"\
|
53
|
+
"<presentation-metadata><name>#{name}</name><value>#{value}</value>" \
|
54
54
|
"</presentation-metadata>"
|
55
55
|
end
|
56
56
|
|
57
57
|
def address_precompose1(addr)
|
58
58
|
ret = []
|
59
|
-
addr.xpath(ns("./street")).each { |s| ret << s.children
|
60
|
-
a = addr.at(ns("./city")) and ret << a.children
|
61
|
-
addr.xpath(ns("./state")).each { |s| ret << s.children
|
62
|
-
a = addr.at(ns("./country")) and ret << a.children
|
63
|
-
a = addr.at(ns("./postcode")) and ret[-1] += " #{a.children
|
59
|
+
addr.xpath(ns("./street")).each { |s| ret << to_xml(s.children) }
|
60
|
+
a = addr.at(ns("./city")) and ret << to_xml(a.children)
|
61
|
+
addr.xpath(ns("./state")).each { |s| ret << to_xml(s.children) }
|
62
|
+
a = addr.at(ns("./country")) and ret << to_xml(a.children)
|
63
|
+
a = addr.at(ns("./postcode")) and ret[-1] += " #{to_xml a.children}"
|
64
64
|
ret.join("<br/>")
|
65
65
|
end
|
66
66
|
|
@@ -118,7 +118,7 @@ module IsoDoc
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def i18n_tag(key, value)
|
121
|
-
"<localized-string key='#{key}' language='#{@lang}'>#{value}"\
|
121
|
+
"<localized-string key='#{key}' language='#{@lang}'>#{value}" \
|
122
122
|
"</localized-string>"
|
123
123
|
end
|
124
124
|
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require "metanorma-utils"
|
2
|
+
|
3
|
+
module IsoDoc
|
4
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
5
|
+
def expand_citeas(text)
|
6
|
+
text.nil? and return text
|
7
|
+
HTMLEntities.new.decode(text.gsub(/&#x/, "&#"))
|
8
|
+
end
|
9
|
+
|
10
|
+
def erefstack1(elem)
|
11
|
+
locs = elem.xpath(ns("./eref")).map do |e|
|
12
|
+
[e["connective"], to_xml(e)]
|
13
|
+
end.flatten
|
14
|
+
ret = resolve_eref_connectives(locs)
|
15
|
+
elem.replace(ret[1])
|
16
|
+
end
|
17
|
+
|
18
|
+
def eref_localities(refs, target, node)
|
19
|
+
if can_conflate_eref_rendering?(refs)
|
20
|
+
l10n(", #{eref_localities_conflated(refs, target, node)}")
|
21
|
+
else
|
22
|
+
ret = resolve_eref_connectives(eref_locality_stacks(refs, target, node))
|
23
|
+
l10n(ret.join)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def eref_localities_conflated(refs, target, node)
|
28
|
+
droploc = node["droploc"]
|
29
|
+
node["droploc"] = true
|
30
|
+
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
|
31
|
+
node))
|
32
|
+
node.delete("droploc") unless droploc
|
33
|
+
eref_localities1({ target: target, number: "pl",
|
34
|
+
type: refs.first.at(ns("./locality/@type")).text,
|
35
|
+
from: l10n(ret[1..-1].join), node: node, lang: @lang })
|
36
|
+
end
|
37
|
+
|
38
|
+
def can_conflate_eref_rendering?(refs)
|
39
|
+
(refs.size > 1 &&
|
40
|
+
refs.all? { |r| r.name == "localityStack" } &&
|
41
|
+
refs.all? { |r| r.xpath(ns("./locality")).size == 1 }) or return false
|
42
|
+
|
43
|
+
first = refs.first.at(ns("./locality/@type")).text
|
44
|
+
refs.all? do |r|
|
45
|
+
r.at(ns("./locality/@type")).text == first
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def resolve_eref_connectives(locs)
|
50
|
+
locs = resolve_comma_connectives(locs)
|
51
|
+
locs = resolve_to_connectives(locs)
|
52
|
+
return locs if locs.size < 3
|
53
|
+
|
54
|
+
locs = locs.each_slice(2).with_object([]) do |a, m|
|
55
|
+
m << { conn: a[0], label: a[1] }
|
56
|
+
end
|
57
|
+
[", ", combine_conn(locs)]
|
58
|
+
end
|
59
|
+
|
60
|
+
def resolve_comma_connectives(locs)
|
61
|
+
locs1 = []
|
62
|
+
add = ""
|
63
|
+
until locs.empty?
|
64
|
+
locs, locs1, add = resolve_comma_connectives1(locs, locs1, add)
|
65
|
+
end
|
66
|
+
locs1 << add unless add.empty?
|
67
|
+
locs1
|
68
|
+
end
|
69
|
+
|
70
|
+
def resolve_comma_connectives1(locs, locs1, add)
|
71
|
+
if [", ", " "].include?(locs[1])
|
72
|
+
add += locs[0..2].join
|
73
|
+
locs.shift(3)
|
74
|
+
else
|
75
|
+
locs1 << add unless add.empty?
|
76
|
+
add = ""
|
77
|
+
locs1 << locs.shift
|
78
|
+
end
|
79
|
+
[locs, locs1, add]
|
80
|
+
end
|
81
|
+
|
82
|
+
def resolve_to_connectives(locs)
|
83
|
+
locs1 = []
|
84
|
+
until locs.empty?
|
85
|
+
if locs[1] == "to"
|
86
|
+
locs1 << @i18n.chain_to.sub(/%1/, locs[0]).sub(/%2/, locs[2])
|
87
|
+
locs.shift(3)
|
88
|
+
else locs1 << locs.shift
|
89
|
+
end
|
90
|
+
end
|
91
|
+
locs1
|
92
|
+
end
|
93
|
+
|
94
|
+
def eref_locality_stacks(refs, target, node)
|
95
|
+
ret = refs.each_with_index.with_object([]) do |(r, i), m|
|
96
|
+
added = eref_locality_stack(r, i, target, node)
|
97
|
+
added.empty? and next
|
98
|
+
added.each { |a| m << a }
|
99
|
+
next if i == refs.size - 1
|
100
|
+
|
101
|
+
m << eref_locality_delimiter(r)
|
102
|
+
end
|
103
|
+
ret.empty? ? ret : [", "] + ret
|
104
|
+
end
|
105
|
+
|
106
|
+
def eref_locality_delimiter(ref)
|
107
|
+
if ref&.next_element&.name == "localityStack"
|
108
|
+
ref.next_element["connective"]
|
109
|
+
else locality_delimiter(ref)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def eref_locality_stack(ref, idx, target, node)
|
114
|
+
ret = []
|
115
|
+
if ref.name == "localityStack"
|
116
|
+
ret = eref_locality_stack1(ref, target, node, ret)
|
117
|
+
else
|
118
|
+
l = eref_localities0(ref, idx, target, node) and ret << l
|
119
|
+
end
|
120
|
+
ret[-1] == ", " and ret.pop
|
121
|
+
ret
|
122
|
+
end
|
123
|
+
|
124
|
+
def eref_locality_stack1(ref, target, node, ret)
|
125
|
+
ref.elements.each_with_index do |rr, j|
|
126
|
+
l = eref_localities0(rr, j, target, node) or next
|
127
|
+
ret << l
|
128
|
+
ret << locality_delimiter(rr) unless j == ref.elements.size - 1
|
129
|
+
end
|
130
|
+
ret
|
131
|
+
end
|
132
|
+
|
133
|
+
def locality_delimiter(_loc)
|
134
|
+
", "
|
135
|
+
end
|
136
|
+
|
137
|
+
def eref_localities0(ref, _idx, target, node)
|
138
|
+
if ref["type"] == "whole" then @i18n.wholeoftext
|
139
|
+
else
|
140
|
+
eref_localities1({ target: target, type: ref["type"], number: "sg",
|
141
|
+
from: ref.at(ns("./referenceFrom"))&.text,
|
142
|
+
upto: ref.at(ns("./referenceTo"))&.text, node: node,
|
143
|
+
lang: @lang })
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# def eref_localities1_zh(_target, type, from, upto, node)
|
148
|
+
def eref_localities1_zh(opt)
|
149
|
+
ret = "第#{opt[:from]}" if opt[:from]
|
150
|
+
ret += "–#{opt[:upto]}" if opt[:upto]
|
151
|
+
loc = eref_locality_populate(opt[:type], opt[:node], "sg")
|
152
|
+
ret += " #{loc}" unless opt[:node]["droploc"] == "true"
|
153
|
+
ret
|
154
|
+
end
|
155
|
+
|
156
|
+
# def eref_localities1(target, type, from, upto, node, lang = "en")
|
157
|
+
def eref_localities1(opt)
|
158
|
+
return nil if opt[:type] == "anchor"
|
159
|
+
|
160
|
+
opt[:lang] == "zh" and
|
161
|
+
# return l10n(eref_localities1_zh(target, type, from, upto, node))
|
162
|
+
return l10n(eref_localities1_zh(opt))
|
163
|
+
ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
|
164
|
+
ret += " #{opt[:from]}" if opt[:from]
|
165
|
+
ret += "–#{opt[:upto]}" if opt[:upto]
|
166
|
+
l10n(ret)
|
167
|
+
end
|
168
|
+
|
169
|
+
def eref_locality_populate(type, node, number)
|
170
|
+
return "" if node["droploc"] == "true"
|
171
|
+
|
172
|
+
loc = type.sub(/^locality:/, "")
|
173
|
+
ret = @i18n.locality[loc] || loc
|
174
|
+
number == "pl" and ret = @i18n.inflect(ret, number: "pl")
|
175
|
+
ret = case node["case"]
|
176
|
+
when "lowercase" then ret.downcase
|
177
|
+
else Metanorma::Utils.strict_capitalize_first(ret)
|
178
|
+
end
|
179
|
+
" #{ret}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require "metanorma-utils"
|
2
|
-
require_relative "xrefs"
|
3
2
|
|
4
3
|
module IsoDoc
|
5
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
@@ -19,10 +18,19 @@ module IsoDoc
|
|
19
18
|
link, node)
|
20
19
|
non_locality_elems(node).each(&:remove)
|
21
20
|
node.add_child(cleanup_entities(link))
|
21
|
+
unnest_linkend(node)
|
22
22
|
end
|
23
23
|
# so not <origin bibitemid="ISO7301" citeas="ISO 7301">
|
24
24
|
# <locality type="section"><reference>3.1</reference></locality></origin>
|
25
25
|
|
26
|
+
def unnest_linkend(node)
|
27
|
+
return unless node.at(ns("./xref[@nested]"))
|
28
|
+
|
29
|
+
node.xpath(ns("./xref[@nested]")).each { |x| x.delete("nested") }
|
30
|
+
node.xpath(ns("./location | ./locationStack")).each(&:remove)
|
31
|
+
node.replace(node.children)
|
32
|
+
end
|
33
|
+
|
26
34
|
def xref_empty?(node)
|
27
35
|
c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
|
28
36
|
c1.empty?
|
@@ -30,169 +38,6 @@ module IsoDoc
|
|
30
38
|
|
31
39
|
def anchor_id_postprocess(node); end
|
32
40
|
|
33
|
-
def expand_citeas(text)
|
34
|
-
text.nil? and return text
|
35
|
-
HTMLEntities.new.decode(text.gsub(/&#x/, "&#"))
|
36
|
-
end
|
37
|
-
|
38
|
-
def erefstack1(elem)
|
39
|
-
locs = elem.xpath(ns("./eref")).map do |e|
|
40
|
-
[e["connective"], e.to_xml]
|
41
|
-
end.flatten
|
42
|
-
ret = resolve_eref_connectives(locs)
|
43
|
-
elem.replace(ret[1])
|
44
|
-
end
|
45
|
-
|
46
|
-
def eref_localities(refs, target, node)
|
47
|
-
if can_conflate_eref_rendering?(refs)
|
48
|
-
l10n(", #{eref_localities_conflated(refs, target, node)}")
|
49
|
-
else
|
50
|
-
ret = resolve_eref_connectives(eref_locality_stacks(refs, target, node))
|
51
|
-
l10n(ret.join)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def eref_localities_conflated(refs, target, node)
|
56
|
-
droploc = node["droploc"]
|
57
|
-
node["droploc"] = true
|
58
|
-
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
|
59
|
-
node))
|
60
|
-
node.delete("droploc") unless droploc
|
61
|
-
eref_localities1(target,
|
62
|
-
refs.first.at(ns("./locality/@type")).text,
|
63
|
-
l10n(ret[1..-1].join), nil, node, @lang)
|
64
|
-
end
|
65
|
-
|
66
|
-
def can_conflate_eref_rendering?(refs)
|
67
|
-
(refs.size > 1 &&
|
68
|
-
refs.all? { |r| r.name == "localityStack" } &&
|
69
|
-
refs.all? { |r| r.xpath(ns("./locality")).size == 1 }) or return false
|
70
|
-
|
71
|
-
first = refs.first.at(ns("./locality/@type")).text
|
72
|
-
refs.all? do |r|
|
73
|
-
r.at(ns("./locality/@type")).text == first
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def resolve_eref_connectives(locs)
|
78
|
-
locs = resolve_comma_connectives(locs)
|
79
|
-
locs = resolve_to_connectives(locs)
|
80
|
-
return locs if locs.size < 3
|
81
|
-
|
82
|
-
locs = locs.each_slice(2).with_object([]) do |a, m|
|
83
|
-
m << { conn: a[0], target: a[1] }
|
84
|
-
end
|
85
|
-
[", ", combine_conn(locs)]
|
86
|
-
end
|
87
|
-
|
88
|
-
def resolve_comma_connectives(locs)
|
89
|
-
locs1 = []
|
90
|
-
add = ""
|
91
|
-
until locs.empty?
|
92
|
-
if [", ", " "].include?(locs[1])
|
93
|
-
add += locs[0..2].join
|
94
|
-
locs.shift(3)
|
95
|
-
else
|
96
|
-
locs1 << add unless add.empty?
|
97
|
-
add = ""
|
98
|
-
locs1 << locs.shift
|
99
|
-
end
|
100
|
-
end
|
101
|
-
locs1 << add unless add.empty?
|
102
|
-
locs1
|
103
|
-
end
|
104
|
-
|
105
|
-
def resolve_to_connectives(locs)
|
106
|
-
locs1 = []
|
107
|
-
until locs.empty?
|
108
|
-
if locs[1] == "to"
|
109
|
-
locs1 << @i18n.chain_to.sub(/%1/, locs[0]).sub(/%2/, locs[2])
|
110
|
-
locs.shift(3)
|
111
|
-
else locs1 << locs.shift
|
112
|
-
end
|
113
|
-
end
|
114
|
-
locs1
|
115
|
-
end
|
116
|
-
|
117
|
-
def eref_locality_stacks(refs, target, node)
|
118
|
-
ret = refs.each_with_index.with_object([]) do |(r, i), m|
|
119
|
-
added = eref_locality_stack(r, i, target, node)
|
120
|
-
added.empty? and next
|
121
|
-
added.each { |a| m << a }
|
122
|
-
next if i == refs.size - 1
|
123
|
-
|
124
|
-
m << eref_locality_delimiter(r)
|
125
|
-
end
|
126
|
-
ret.empty? ? ret : [", "] + ret
|
127
|
-
end
|
128
|
-
|
129
|
-
def eref_locality_delimiter(ref)
|
130
|
-
if ref&.next_element&.name == "localityStack"
|
131
|
-
ref.next_element["connective"]
|
132
|
-
else locality_delimiter(ref)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def eref_locality_stack(ref, idx, target, node)
|
137
|
-
ret = []
|
138
|
-
if ref.name == "localityStack"
|
139
|
-
ref.elements.each_with_index do |rr, j|
|
140
|
-
l = eref_localities0(rr, j, target, node) or next
|
141
|
-
|
142
|
-
ret << l
|
143
|
-
ret << locality_delimiter(rr) unless j == ref.elements.size - 1
|
144
|
-
end
|
145
|
-
else
|
146
|
-
l = eref_localities0(ref, idx, target, node) and ret << l
|
147
|
-
end
|
148
|
-
ret[-1] == ", " and ret.pop
|
149
|
-
ret
|
150
|
-
end
|
151
|
-
|
152
|
-
def locality_delimiter(_loc)
|
153
|
-
", "
|
154
|
-
end
|
155
|
-
|
156
|
-
def eref_localities0(ref, _idx, target, node)
|
157
|
-
if ref["type"] == "whole" then @i18n.wholeoftext
|
158
|
-
else
|
159
|
-
eref_localities1(target, ref["type"],
|
160
|
-
ref&.at(ns("./referenceFrom"))&.text,
|
161
|
-
ref&.at(ns("./referenceTo"))&.text, node, @lang)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def eref_localities1_zh(_target, type, from, upto, node)
|
166
|
-
ret = "第#{from}" if from
|
167
|
-
ret += "–#{upto}" if upto
|
168
|
-
loc = eref_locality_populate(type, node)
|
169
|
-
ret += " #{loc}" unless node["droploc"] == "true"
|
170
|
-
ret
|
171
|
-
end
|
172
|
-
|
173
|
-
def eref_localities1(target, type, from, upto, node, lang = "en")
|
174
|
-
return nil if type == "anchor"
|
175
|
-
|
176
|
-
lang == "zh" and
|
177
|
-
return l10n(eref_localities1_zh(target, type, from, upto, node))
|
178
|
-
ret = eref_locality_populate(type, node)
|
179
|
-
ret += " #{from}" if from
|
180
|
-
ret += "–#{upto}" if upto
|
181
|
-
l10n(ret)
|
182
|
-
end
|
183
|
-
|
184
|
-
def eref_locality_populate(type, node)
|
185
|
-
return "" if node["droploc"] == "true"
|
186
|
-
|
187
|
-
loc = type.sub(/^locality:/, "")
|
188
|
-
ret = @i18n.locality[loc] || loc
|
189
|
-
ret = case node["case"]
|
190
|
-
when "lowercase" then loc.downcase
|
191
|
-
else Metanorma::Utils.strict_capitalize_first(ret)
|
192
|
-
end
|
193
|
-
" #{ret}"
|
194
|
-
end
|
195
|
-
|
196
41
|
def xref(docxml)
|
197
42
|
docxml.xpath(ns("//xref")).each { |f| xref1(f) }
|
198
43
|
docxml.xpath(ns("//xref//xref")).each { |f| f.replace(f.children) }
|
@@ -200,6 +45,7 @@ module IsoDoc
|
|
200
45
|
|
201
46
|
def eref(docxml)
|
202
47
|
docxml.xpath(ns("//eref")).each { |f| xref1(f) }
|
48
|
+
docxml.xpath(ns("//eref//xref")).each { |f| f.replace(f.children) }
|
203
49
|
docxml.xpath(ns("//erefstack")).each { |f| erefstack1(f) }
|
204
50
|
end
|
205
51
|
|
@@ -209,6 +55,9 @@ module IsoDoc
|
|
209
55
|
|
210
56
|
def quotesource(docxml)
|
211
57
|
docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
|
58
|
+
docxml.xpath(ns("//quote/source//xref")).each do |f|
|
59
|
+
f.replace(f.children)
|
60
|
+
end
|
212
61
|
end
|
213
62
|
|
214
63
|
def xref1(node)
|
@@ -20,7 +20,7 @@ module IsoDoc
|
|
20
20
|
d.remove_namespaces!
|
21
21
|
refs = d.xpath("//references/bibitem").each_with_object([]) do |b, m|
|
22
22
|
prep_for_rendering(b)
|
23
|
-
m << b
|
23
|
+
m << to_xml(b)
|
24
24
|
end.join
|
25
25
|
bibrenderer.render_all("<references>#{refs}</references>",
|
26
26
|
type: citestyle)
|
@@ -55,7 +55,7 @@ module IsoDoc
|
|
55
55
|
def annex1(elem)
|
56
56
|
lbl = @xrefs.anchor(elem["id"], :label)
|
57
57
|
if t = elem.at(ns("./title"))
|
58
|
-
t.children = "<strong>#{t.children
|
58
|
+
t.children = "<strong>#{to_xml(t.children)}</strong>"
|
59
59
|
end
|
60
60
|
prefix_name(elem, "<br/><br/>", lbl, "title")
|
61
61
|
end
|
@@ -54,8 +54,8 @@ module IsoDoc
|
|
54
54
|
return ref.remove if opts[:ref] == "false"
|
55
55
|
|
56
56
|
r = concept1_ref_content(ref)
|
57
|
-
ref = r.at("./descendant-or-self::xmlns:xref | "\
|
58
|
-
"./descendant-or-self::xmlns:eref | "\
|
57
|
+
ref = r.at("./descendant-or-self::xmlns:xref | " \
|
58
|
+
"./descendant-or-self::xmlns:eref | " \
|
59
59
|
"./descendant-or-self::xmlns:termref")
|
60
60
|
%w(xref eref).include? ref&.name and get_linkend(ref)
|
61
61
|
if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
|
@@ -68,8 +68,8 @@ module IsoDoc
|
|
68
68
|
!c.text? || /\S/.match(c)
|
69
69
|
end.empty?
|
70
70
|
ref.replace(@i18n.term_defined_in.sub(/%/,
|
71
|
-
ref
|
72
|
-
else ref.replace("[#{ref
|
71
|
+
to_xml(ref)))
|
72
|
+
else ref.replace("[#{to_xml(ref)}]")
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -82,10 +82,10 @@ module IsoDoc
|
|
82
82
|
ref = node.at(ns("./xref | ./eref | ./termref"))
|
83
83
|
label = @i18n.relatedterms[node["type"]].upcase
|
84
84
|
if p && ref
|
85
|
-
node.replace(l10n("<p><strong>#{label}:</strong> "\
|
86
|
-
"<em>#{p
|
85
|
+
node.replace(l10n("<p><strong>#{label}:</strong> " \
|
86
|
+
"<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>"))
|
87
87
|
else
|
88
|
-
node.replace(l10n("<p><strong>#{label}:</strong> "\
|
88
|
+
node.replace(l10n("<p><strong>#{label}:</strong> " \
|
89
89
|
"<strong>**RELATED TERM NOT FOUND**</strong></p>"))
|
90
90
|
end
|
91
91
|
end
|
@@ -110,7 +110,7 @@ module IsoDoc
|
|
110
110
|
if merge_preferred_eligible?(pref, second)
|
111
111
|
n1 = pref.at(ns("./expression/name"))
|
112
112
|
n2 = second.remove.at(ns("./expression/name"))
|
113
|
-
n1.children = l10n("#{n1.children
|
113
|
+
n1.children = l10n("#{to_xml(n1.children)}; #{Common::to_xml(n2.children)}")
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -125,7 +125,7 @@ module IsoDoc
|
|
125
125
|
|
126
126
|
def designation1(desgn)
|
127
127
|
s = desgn.at(ns("./termsource"))
|
128
|
-
name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
|
128
|
+
name = desgn.at(ns("./expression/name | ./letter-symbol/name | " \
|
129
129
|
"./graphical-symbol")) or return
|
130
130
|
|
131
131
|
designation_annotate(desgn, name)
|
@@ -150,7 +150,7 @@ module IsoDoc
|
|
150
150
|
|
151
151
|
def designation_field(desgn, name)
|
152
152
|
f = desgn.xpath(ns("./field-of-application | ./usage-info"))
|
153
|
-
&.map { |u| u.children
|
153
|
+
&.map { |u| to_xml(u.children) }&.join(", ")
|
154
154
|
return nil if f&.empty?
|
155
155
|
|
156
156
|
name << ", <#{f}>"
|
@@ -181,7 +181,7 @@ module IsoDoc
|
|
181
181
|
def designation_pronunciation(desgn, name)
|
182
182
|
f = desgn.at(ns("./expression/pronunciation")) or return
|
183
183
|
|
184
|
-
name << ", /#{f.children
|
184
|
+
name << ", /#{to_xml(f.children)}/"
|
185
185
|
end
|
186
186
|
|
187
187
|
def termexample(docxml)
|
@@ -214,9 +214,9 @@ module IsoDoc
|
|
214
214
|
|
215
215
|
def multidef(elem)
|
216
216
|
d = elem.at(ns("./definition"))
|
217
|
-
d = d.replace("<ol><li>#{d.children
|
217
|
+
d = d.replace("<ol><li>#{to_xml(d.children)}</li></ol>").first
|
218
218
|
elem.xpath(ns("./definition")).each do |f|
|
219
|
-
f = f.replace("<li>#{f.children
|
219
|
+
f = f.replace("<li>#{to_xml(f.children)}</li>").first
|
220
220
|
d << f
|
221
221
|
end
|
222
222
|
d.wrap("<definition></definition>")
|
@@ -242,9 +242,9 @@ module IsoDoc
|
|
242
242
|
|
243
243
|
def termsource1(elem)
|
244
244
|
while elem&.next_element&.name == "termsource"
|
245
|
-
elem << "; #{elem.next_element.remove.children
|
245
|
+
elem << "; #{to_xml(elem.next_element.remove.children)}"
|
246
246
|
end
|
247
|
-
elem.children = l10n("[#{@i18n.source}: #{elem.children.
|
247
|
+
elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]")
|
248
248
|
end
|
249
249
|
|
250
250
|
def termsource_modification(mod)
|
@@ -38,15 +38,20 @@ module IsoDoc
|
|
38
38
|
def anchor_xref(node, target)
|
39
39
|
x = @xrefs.anchor(target, :xref)
|
40
40
|
t = @xrefs.anchor(target, :title)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
case node["style"]
|
42
|
+
when "basic" then t || x
|
43
|
+
when "full" then t ? anchor_xref_full(x, t) : x
|
44
|
+
when "short", nil then x
|
45
|
+
else @xrefs.anchor(target, node[:style].to_sym)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
def anchor_xref_full(num, title)
|
50
|
+
l10n("#{num}, #{title}")
|
51
|
+
end
|
52
|
+
|
49
53
|
def prefix_container?(container, node)
|
54
|
+
node["style"] == "modspec" and return false # TODO: move to mn-requirements?
|
50
55
|
type = @xrefs.anchor(node["target"], :type)
|
51
56
|
container &&
|
52
57
|
get_note_container_id(node, type) != container &&
|
@@ -58,15 +63,20 @@ module IsoDoc
|
|
58
63
|
linkend = if can_conflate_xref_rendering?(locs)
|
59
64
|
combine_conflated_xref_locations(locs)
|
60
65
|
else
|
61
|
-
out = locs.each { |l| l[:
|
66
|
+
out = locs.each { |l| l[:label] = anchor_linkend1(l[:node]) }
|
62
67
|
l10n(combine_conn(out))
|
63
68
|
end
|
64
69
|
capitalise_xref(node, linkend, anchor_value(node["target"]))
|
65
70
|
end
|
66
71
|
|
67
72
|
def combine_conflated_xref_locations(locs)
|
68
|
-
out = locs.each { |l| l[:
|
69
|
-
|
73
|
+
out = locs.each { |l| l[:label] = anchor_value(l[:target]) }
|
74
|
+
label = @i18n.inflect(locs.first[:elem], number: "pl")
|
75
|
+
out[0][:label] = l10n("#{label} #{out[0][:label]}")
|
76
|
+
combine_conflated_xref_locations_container(locs, l10n(combine_conn(out)))
|
77
|
+
end
|
78
|
+
|
79
|
+
def combine_conflated_xref_locations_container(locs, ret)
|
70
80
|
container = @xrefs.anchor(locs.first[:node]["target"], :container,
|
71
81
|
false)
|
72
82
|
prefix_container?(container, locs.first[:node]) and
|
@@ -85,15 +95,23 @@ module IsoDoc
|
|
85
95
|
end
|
86
96
|
end
|
87
97
|
|
98
|
+
def loc2xref(entry)
|
99
|
+
if entry[:target]
|
100
|
+
"<xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</xref>"
|
101
|
+
else
|
102
|
+
entry[:label]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
88
106
|
def combine_conn(list)
|
89
|
-
return list.first[:
|
107
|
+
return list.first[:label] if list.size == 1
|
90
108
|
|
91
109
|
if list[1..-1].all? { |l| l[:conn] == "and" }
|
92
|
-
@i18n.boolean_conj(list.map { |l| l
|
110
|
+
@i18n.boolean_conj(list.map { |l| loc2xref(l) }, "and")
|
93
111
|
elsif list[1..-1].all? { |l| l[:conn] == "or" }
|
94
|
-
@i18n.boolean_conj(list.map { |l| l
|
112
|
+
@i18n.boolean_conj(list.map { |l| loc2xref(l) }, "or")
|
95
113
|
else
|
96
|
-
ret = list[0]
|
114
|
+
ret = loc2xref(list[0])
|
97
115
|
list[1..-1].each { |l| ret = i18n_chain_boolean(ret, l) }
|
98
116
|
ret
|
99
117
|
end
|
@@ -101,7 +119,7 @@ module IsoDoc
|
|
101
119
|
|
102
120
|
def i18n_chain_boolean(value, entry)
|
103
121
|
@i18n.send("chain_#{entry[:conn]}").sub(/%1/, value)
|
104
|
-
.sub(/%2/, entry
|
122
|
+
.sub(/%2/, loc2xref(entry))
|
105
123
|
end
|
106
124
|
|
107
125
|
def can_conflate_xref_rendering?(locs)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require_relative "presentation_function/block"
|
2
2
|
require_relative "presentation_function/terms"
|
3
|
+
require_relative "presentation_function/xrefs"
|
4
|
+
require_relative "presentation_function/erefs"
|
3
5
|
require_relative "presentation_function/inline"
|
4
6
|
require_relative "presentation_function/math"
|
5
7
|
require_relative "presentation_function/section"
|
@@ -83,11 +85,11 @@ module IsoDoc
|
|
83
85
|
end
|
84
86
|
|
85
87
|
def postprocess(result, filename, _dir)
|
86
|
-
|
88
|
+
to_xml_file(result, filename)
|
87
89
|
@files_to_delete.each { |f| FileUtils.rm_rf f }
|
88
90
|
end
|
89
91
|
|
90
|
-
def
|
92
|
+
def to_xml_file(result, filename)
|
91
93
|
File.open(filename, "w:UTF-8") { |f| f.write(result) }
|
92
94
|
end
|
93
95
|
end
|
data/lib/isodoc/version.rb
CHANGED
@@ -26,41 +26,33 @@ module IsoDoc
|
|
26
26
|
def insert_toc(intro, docxml, level)
|
27
27
|
toc = ""
|
28
28
|
toc += make_WordToC(docxml, level)
|
29
|
-
toc +=
|
30
|
-
toc +=
|
31
|
-
toc +=
|
29
|
+
toc += make_table_word_toc(docxml)
|
30
|
+
toc += make_figure_word_toc(docxml)
|
31
|
+
toc += make_recommendation_word_toc(docxml)
|
32
32
|
intro.sub(/WORDTOC/, toc)
|
33
33
|
end
|
34
34
|
|
35
35
|
def word_toc_entry(toclevel, heading)
|
36
36
|
bookmark = bookmarkid # Random.rand(1000000000)
|
37
37
|
<<~TOC
|
38
|
-
<p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
|
39
|
-
lang="EN-GB"
|
40
|
-
<a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
|
41
|
-
class="MsoTocTextSpan">
|
38
|
+
<p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span lang="EN-GB" style='mso-no-proof:yes'>
|
39
|
+
<a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB" class="MsoTocTextSpan">
|
42
40
|
<span style='mso-tab-count:1 dotted'>. </span>
|
43
41
|
</span><span lang="EN-GB" class="MsoTocTextSpan">
|
44
42
|
<span style='mso-element:field-begin'></span></span>
|
45
|
-
<span lang="EN-GB"
|
46
|
-
|
47
|
-
<span lang="EN-GB" class="MsoTocTextSpan"><span
|
48
|
-
style='mso-element:field-separator'></span></span><span
|
43
|
+
<span lang="EN-GB" class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
|
44
|
+
<span lang="EN-GB" class="MsoTocTextSpan"><span style='mso-element:field-separator'></span></span><span
|
49
45
|
lang="EN-GB" class="MsoTocTextSpan">1</span>
|
50
|
-
<span lang="EN-GB"
|
51
|
-
class="MsoTocTextSpan"></span
|
52
|
-
lang="EN-GB" class="MsoTocTextSpan"><span
|
53
|
-
style='mso-element:field-end'></span></span></a></span></span></p>
|
46
|
+
<span lang="EN-GB" class="MsoTocTextSpan"></span><span
|
47
|
+
lang="EN-GB" class="MsoTocTextSpan"><span style='mso-element:field-end'></span></span></a></span></span></p>
|
54
48
|
|
55
49
|
TOC
|
56
50
|
end
|
57
51
|
|
58
52
|
def word_toc_preface(level)
|
59
|
-
<<~TOC
|
60
|
-
<span lang="EN-GB"><span
|
61
|
-
style='mso-
|
62
|
-
style='mso-spacerun:yes'> </span>TOC
|
63
|
-
\\o "1-#{level}" \\h \\z \\u <span
|
53
|
+
<<~TOC
|
54
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span
|
55
|
+
style='mso-spacerun:yes'> </span>TOC \\o "1-#{level}" \\h \\z \\u <span
|
64
56
|
style='mso-element:field-separator'></span></span>
|
65
57
|
TOC
|
66
58
|
end
|
@@ -82,63 +74,96 @@ module IsoDoc
|
|
82
74
|
%{\\1#{word_toc_preface(level)}}) + WORD_TOC_SUFFIX1
|
83
75
|
end
|
84
76
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
77
|
+
# inheriting gems need to add native Word name of style, if different
|
78
|
+
# including both CSS style name and human readable style name.
|
79
|
+
# Any human readable style name needs to come first for the Word template
|
80
|
+
# to work in regenerating the ToC
|
81
|
+
def table_toc_class
|
82
|
+
%w(TableTitle tabletitle)
|
83
|
+
end
|
92
84
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
style='mso-spacerun:yes'> </span>TOC
|
97
|
-
\\h \\z \\t "TableTitle,tabletitle" <span
|
98
|
-
style='mso-element:field-separator'></span></span>
|
99
|
-
TOC
|
85
|
+
def figure_toc_class
|
86
|
+
%w(FigureTitle figuretitle)
|
87
|
+
end
|
100
88
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
\\h \\z \\t "FigureTitle,figuretitle" <span
|
106
|
-
style='mso-element:field-separator'></span></span>
|
107
|
-
TOC
|
89
|
+
def reqt_toc_class
|
90
|
+
%w(RecommendationTitle RecommendationTestTitle
|
91
|
+
recommendationtitle recommendationtesttitle)
|
92
|
+
end
|
108
93
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
94
|
+
def toc_word_class_list(classes)
|
95
|
+
classes.map do |x|
|
96
|
+
/ /.match?(x) ? %("#{x}") : x
|
97
|
+
end.join(",")
|
98
|
+
end
|
99
|
+
|
100
|
+
def word_toc_reqt_preface1
|
101
|
+
<<~TOC
|
102
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span
|
103
|
+
style='mso-spacerun:yes'> </span>TOC \\h \\z \\t #{toc_word_class_list reqt_toc_class}
|
104
|
+
<span style='mso-element:field-separator'></span></span>
|
105
|
+
TOC
|
106
|
+
end
|
107
|
+
|
108
|
+
def word_toc_table_preface1
|
109
|
+
<<~TOC
|
110
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span style='mso-spacerun:yes'> </span>TOC
|
111
|
+
\\h \\z \\t #{toc_word_class_list table_toc_class} <span style='mso-element:field-separator'></span></span>
|
112
|
+
TOC
|
113
|
+
end
|
114
|
+
|
115
|
+
def word_toc_figure_preface1
|
116
|
+
<<~TOC
|
117
|
+
<span lang="EN-GB"><span style='mso-element:field-begin'></span><span style='mso-spacerun:yes'> </span>TOC
|
118
|
+
\\h \\z \\t #{toc_word_class_list figure_toc_class} <span style='mso-element:field-separator'></span></span>
|
119
|
+
TOC
|
120
|
+
end
|
121
|
+
|
122
|
+
def table_toc_xpath
|
123
|
+
attr = table_toc_class.map { |x| "@class = '#{x}'" }
|
124
|
+
"//p[#{attr.join(' or ')}]"
|
125
|
+
end
|
126
|
+
|
127
|
+
def make_table_word_toc(docxml)
|
128
|
+
(docxml.at(table_toc_xpath) && @toctablestitle) or return ""
|
112
129
|
toc = %{<p class="TOCTitle">#{@toctablestitle}</p>}
|
113
|
-
docxml.xpath(
|
130
|
+
docxml.xpath(table_toc_xpath).each do |h|
|
114
131
|
toc += word_toc_entry(1, header_strip(h))
|
115
132
|
end
|
116
133
|
toc.sub(/(<p class="MsoToc1">)/,
|
117
|
-
%{\\1#{
|
134
|
+
%{\\1#{word_toc_table_preface1}}) + WORD_TOC_SUFFIX1
|
135
|
+
end
|
136
|
+
|
137
|
+
def figure_toc_xpath
|
138
|
+
attr = figure_toc_class.map { |x| "@class = '#{x}'" }
|
139
|
+
"//p[#{attr.join(' or ')}]"
|
118
140
|
end
|
119
141
|
|
120
|
-
def
|
121
|
-
(docxml.at(
|
122
|
-
return ""
|
142
|
+
def make_figure_word_toc(docxml)
|
143
|
+
(docxml.at(figure_toc_xpath) && @tocfigurestitle) or return ""
|
123
144
|
toc = %{<p class="TOCTitle">#{@tocfigurestitle}</p>}
|
124
|
-
docxml.xpath(
|
145
|
+
docxml.xpath(figure_toc_xpath).each do |h|
|
125
146
|
toc += word_toc_entry(1, header_strip(h))
|
126
147
|
end
|
127
148
|
toc.sub(/(<p class="MsoToc1">)/,
|
128
|
-
%{\\1#{
|
149
|
+
%{\\1#{word_toc_figure_preface1}}) + WORD_TOC_SUFFIX1
|
150
|
+
end
|
151
|
+
|
152
|
+
def reqt_toc_xpath
|
153
|
+
attr = reqt_toc_class.map { |x| "@class = '#{x}'" }
|
154
|
+
"//p[#{attr.join(' or ')}]"
|
129
155
|
end
|
130
156
|
|
131
|
-
def
|
132
|
-
(docxml.at(
|
133
|
-
@tocrecommendationstitle) or return ""
|
157
|
+
def make_recommendation_word_toc(docxml)
|
158
|
+
(docxml.at(reqt_toc_xpath) && @tocrecommendationstitle) or return ""
|
134
159
|
toc = %{<p class="TOCTitle">#{@tocrecommendationstitle}</p>}
|
135
|
-
docxml.xpath(
|
160
|
+
docxml.xpath(reqt_toc_xpath).sort_by do |h|
|
136
161
|
recommmendation_sort_key(h.text)
|
137
162
|
end.each do |h|
|
138
163
|
toc += word_toc_entry(1, header_strip(h))
|
139
164
|
end
|
140
165
|
toc.sub(/(<p class="MsoToc1">)/,
|
141
|
-
%{\\1#{
|
166
|
+
%{\\1#{word_toc_reqt_preface1}}) + WORD_TOC_SUFFIX1
|
142
167
|
end
|
143
168
|
|
144
169
|
def recommmendation_sort_key(header)
|
@@ -160,7 +185,7 @@ module IsoDoc
|
|
160
185
|
|
161
186
|
def authority_cleanup1(docxml, klass)
|
162
187
|
dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']")
|
163
|
-
auth = docxml.at("//div[@id = 'boilerplate-#{klass}' "\
|
188
|
+
auth = docxml.at("//div[@id = 'boilerplate-#{klass}' " \
|
164
189
|
"or @class = 'boilerplate-#{klass}']")
|
165
190
|
auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each(&:remove)
|
166
191
|
auth&.xpath(".//h1 | .//h2")&.each do |h|
|
@@ -218,7 +243,7 @@ module IsoDoc
|
|
218
243
|
docxml.xpath("//div[@class = '#{sect}']//br[@orientation]").reverse
|
219
244
|
.each_with_index do |br, i|
|
220
245
|
@landscapestyle +=
|
221
|
-
"\ndiv.#{sect}_#{i} {page:#{sect}"\
|
246
|
+
"\ndiv.#{sect}_#{i} {page:#{sect}" \
|
222
247
|
"#{br['orientation'] == 'landscape' ? 'L' : 'P'};}\n"
|
223
248
|
split_at_section_break(docxml, sect, br, i)
|
224
249
|
end
|
data/lib/isodoc/xref/xref_gen.rb
CHANGED
@@ -62,7 +62,7 @@ module IsoDoc
|
|
62
62
|
@anchors[n["id"]] =
|
63
63
|
{ label: termnote_label(c.print), type: "termnote",
|
64
64
|
value: c.print, elem: @labels["termnote"],
|
65
|
-
xref: l10n("#{anchor(t['id'], :xref)}, "\
|
65
|
+
xref: l10n("#{anchor(t['id'], :xref)}, " \
|
66
66
|
"#{@labels['note_xref']} #{c.print}") }
|
67
67
|
end
|
68
68
|
end
|
@@ -82,10 +82,10 @@ module IsoDoc
|
|
82
82
|
end
|
83
83
|
|
84
84
|
SECTIONS_XPATH =
|
85
|
-
"//foreword | //introduction | //acknowledgements | "\
|
86
|
-
"//preface/terms | preface/definitions | preface/references | "\
|
87
|
-
"//preface/clause | //sections/terms | //annex | "\
|
88
|
-
"//sections/clause | //sections/definitions | "\
|
85
|
+
"//foreword | //introduction | //acknowledgements | " \
|
86
|
+
"//preface/terms | preface/definitions | preface/references | " \
|
87
|
+
"//preface/clause | //sections/terms | //annex | " \
|
88
|
+
"//sections/clause | //sections/definitions | " \
|
89
89
|
"//bibliography/references | //bibliography/clause".freeze
|
90
90
|
|
91
91
|
def sections_xpath
|
@@ -93,8 +93,8 @@ module IsoDoc
|
|
93
93
|
end
|
94
94
|
|
95
95
|
CHILD_NOTES_XPATH =
|
96
|
-
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\
|
97
|
-
"not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:note | "\
|
96
|
+
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
|
97
|
+
"not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:note | " \
|
98
98
|
"./xmlns:note".freeze
|
99
99
|
|
100
100
|
def note_anchor_names(sections)
|
@@ -117,11 +117,11 @@ module IsoDoc
|
|
117
117
|
end
|
118
118
|
|
119
119
|
CHILD_EXAMPLES_XPATH =
|
120
|
-
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\
|
121
|
-
"not(self::xmlns:terms) and not(self::xmlns:definitions)]//"\
|
120
|
+
"./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and " \
|
121
|
+
"not(self::xmlns:terms) and not(self::xmlns:definitions)]//" \
|
122
122
|
"xmlns:example | ./xmlns:example".freeze
|
123
123
|
|
124
|
-
CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | "\
|
124
|
+
CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \
|
125
125
|
"./references".freeze
|
126
126
|
|
127
127
|
def example_anchor_names(sections)
|
@@ -205,7 +205,7 @@ module IsoDoc
|
|
205
205
|
label = dterm.dup
|
206
206
|
label.xpath(ns(".//p")).each { |x| x.replace(x.children) }
|
207
207
|
label.xpath(ns(".//index")).each(&:remove)
|
208
|
-
label.children
|
208
|
+
Common::to_xml(label.children)
|
209
209
|
end
|
210
210
|
|
211
211
|
def bookmark_anchor_names(xml)
|
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.4.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: 2022-
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciimath
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
131
|
+
version: 0.3.1
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
138
|
+
version: 0.3.1
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: relaton-cli
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -290,20 +290,6 @@ dependencies:
|
|
290
290
|
- - "~>"
|
291
291
|
- !ruby/object:Gem::Version
|
292
292
|
version: '13.0'
|
293
|
-
- !ruby/object:Gem::Dependency
|
294
|
-
name: rexml
|
295
|
-
requirement: !ruby/object:Gem::Requirement
|
296
|
-
requirements:
|
297
|
-
- - ">="
|
298
|
-
- !ruby/object:Gem::Version
|
299
|
-
version: '0'
|
300
|
-
type: :development
|
301
|
-
prerelease: false
|
302
|
-
version_requirements: !ruby/object:Gem::Requirement
|
303
|
-
requirements:
|
304
|
-
- - ">="
|
305
|
-
- !ruby/object:Gem::Version
|
306
|
-
version: '0'
|
307
293
|
- !ruby/object:Gem::Dependency
|
308
294
|
name: rspec
|
309
295
|
requirement: !ruby/object:Gem::Requirement
|
@@ -459,6 +445,7 @@ files:
|
|
459
445
|
- lib/isodoc/pdf_convert.rb
|
460
446
|
- lib/isodoc/presentation_function/bibdata.rb
|
461
447
|
- lib/isodoc/presentation_function/block.rb
|
448
|
+
- lib/isodoc/presentation_function/erefs.rb
|
462
449
|
- lib/isodoc/presentation_function/image.rb
|
463
450
|
- lib/isodoc/presentation_function/inline.rb
|
464
451
|
- lib/isodoc/presentation_function/math.rb
|
@@ -510,7 +497,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
510
497
|
- !ruby/object:Gem::Version
|
511
498
|
version: '0'
|
512
499
|
requirements: []
|
513
|
-
rubygems_version: 3.3.
|
500
|
+
rubygems_version: 3.3.26
|
514
501
|
signing_key:
|
515
502
|
specification_version: 4
|
516
503
|
summary: Convert documents in IsoDoc into Word and HTML in AsciiDoc.
|