isodoc 1.7.7 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +1 -1
- data/lib/isodoc/function/cleanup.rb +4 -0
- data/lib/isodoc/presentation_function/block.rb +0 -36
- data/lib/isodoc/presentation_function/inline.rb +2 -3
- data/lib/isodoc/presentation_function/terms.rb +179 -0
- data/lib/isodoc/presentation_xml_convert.rb +11 -4
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/postprocess.rb +184 -176
- data/lib/isodoc/xslfo_convert.rb +9 -6
- data/lib/isodoc-yaml/i18n-ar.yaml +22 -0
- data/lib/isodoc-yaml/i18n-de.yaml +20 -0
- data/lib/isodoc-yaml/i18n-en.yaml +20 -0
- data/lib/isodoc-yaml/i18n-es.yaml +20 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +20 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +21 -1
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +21 -0
- data/lib/metanorma/output/xslfo.rb +4 -11
- data/spec/isodoc/i18n_spec.rb +5 -5
- data/spec/isodoc/inline_spec.rb +78 -0
- data/spec/isodoc/section_spec.rb +11 -10
- data/spec/isodoc/terms_spec.rb +354 -34
- data/spec/isodoc/xref_spec.rb +4 -4
- data/spec/isodoc/xslfo_convert_spec.rb +20 -7
- metadata +6 -6
- data/lib/isodoc/presentation_function/concept.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e798df14fbf858fd0540d3fb2837774ec6a1924d5590ad4a628699888eff8425
|
4
|
+
data.tar.gz: 8f3e143a4c3cbcba0c4c349c315c6bf7b067164cd4cc22bd06a85dce71268e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a0fbbabc25df62e19eeefecbf3369188194e28348ac6758f59024b58c0e4e23695440e41263c049455a12b1ce210e602c58e6142e9b8b95ac79d2fa8a64d341
|
7
|
+
data.tar.gz: 888429742fbf4ee0ab902b1a34d5edb8d7657b2fb561ecf3fe872fe48de14267e0e7edcae1e27c86ed5b36dc8d0becccd0ca6f96f6f1239936fb1bd287dc0130
|
data/isodoc.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
30
30
|
|
31
31
|
spec.add_dependency "asciimath"
|
32
|
-
spec.add_dependency "html2doc", "~> 1.
|
32
|
+
spec.add_dependency "html2doc", "~> 1.2.0"
|
33
33
|
spec.add_dependency "htmlentities", "~> 4.3.4"
|
34
34
|
spec.add_dependency "liquid", "~> 4"
|
35
35
|
# spec.add_dependency "metanorma", ">= 1.2.0"
|
@@ -165,6 +165,10 @@ module IsoDoc
|
|
165
165
|
t << a.remove
|
166
166
|
end
|
167
167
|
end
|
168
|
+
table_footnote_cleanup_propagate(docxml)
|
169
|
+
end
|
170
|
+
|
171
|
+
def table_footnote_cleanup_propagate(docxml)
|
168
172
|
docxml.xpath("//p[not(self::*[@class])]"\
|
169
173
|
"[ancestor::*[@class = 'TableFootnote']]").each do |p|
|
170
174
|
p["class"] = "TableFootnote"
|
@@ -54,12 +54,6 @@ module IsoDoc
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
def termexample(docxml)
|
58
|
-
docxml.xpath(ns("//termexample")).each do |f|
|
59
|
-
example1(f)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
57
|
def example1(elem)
|
64
58
|
n = @xrefs.get[elem["id"]]
|
65
59
|
lbl = if n.nil? || n[:label].nil? || n[:label].empty?
|
@@ -89,36 +83,6 @@ module IsoDoc
|
|
89
83
|
prefix_name(elem, "", lbl, "name")
|
90
84
|
end
|
91
85
|
|
92
|
-
def termnote(docxml)
|
93
|
-
docxml.xpath(ns("//termnote")).each do |f|
|
94
|
-
termnote1(f)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# introduce name element
|
99
|
-
def termnote1(elem)
|
100
|
-
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
|
101
|
-
prefix_name(elem, "", lower2cap(lbl), "name")
|
102
|
-
end
|
103
|
-
|
104
|
-
def termdefinition(docxml)
|
105
|
-
docxml.xpath(ns("//term[definition]")).each do |f|
|
106
|
-
termdefinition1(f)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def termdefinition1(elem)
|
111
|
-
return unless elem.xpath(ns("./definition")).size > 1
|
112
|
-
|
113
|
-
d = elem.at(ns("./definition"))
|
114
|
-
d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
|
115
|
-
elem.xpath(ns("./definition")).each do |f|
|
116
|
-
f = f.replace("<li>#{f.children.to_xml}</li>").first
|
117
|
-
d << f
|
118
|
-
end
|
119
|
-
d.wrap("<definition></definition>")
|
120
|
-
end
|
121
|
-
|
122
86
|
def recommendation(docxml)
|
123
87
|
docxml.xpath(ns("//recommendation")).each do |f|
|
124
88
|
recommendation1(f, lower2cap(@i18n.recommendation))
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require "metanorma-utils"
|
2
|
-
require_relative "./concept"
|
3
2
|
|
4
3
|
module IsoDoc
|
5
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
@@ -35,8 +34,8 @@ module IsoDoc
|
|
35
34
|
|
36
35
|
def capitalise_xref(node, linkend, label)
|
37
36
|
linktext = linkend.gsub(/<[^>]+>/, "")
|
38
|
-
(label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext) ||
|
39
|
-
|
37
|
+
(label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) ||
|
38
|
+
linktext[0, 1].match?(/\p{Upper}/) and return linkend
|
40
39
|
node["case"] and
|
41
40
|
return Common::case_with_markup(linkend, node["case"], @script)
|
42
41
|
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
|
+
def concept(docxml)
|
4
|
+
docxml.xpath(ns("//concept")).each { |f| concept1(f) }
|
5
|
+
end
|
6
|
+
|
7
|
+
def concept1(node)
|
8
|
+
xref = node&.at(ns("./xref/@target"))&.text or
|
9
|
+
return concept_render(node, ital: node["ital"] || "true",
|
10
|
+
ref: node["ref"] || "true",
|
11
|
+
linkref: node["linkref"] || "true",
|
12
|
+
linkmention: node["linkmention"] || "false")
|
13
|
+
if node.at(ns("//definitions//dt[@id = '#{xref}']"))
|
14
|
+
concept_render(node, ital: node["ital"] || "false",
|
15
|
+
ref: node["ref"] || "false",
|
16
|
+
linkref: node["linkref"] || "true",
|
17
|
+
linkmention: node["linkmention"] || "false")
|
18
|
+
else concept_render(node, ital: node["ital"] || "true",
|
19
|
+
ref: node["ref"] || "true",
|
20
|
+
linkref: node["linkref"] || "true",
|
21
|
+
linkmention: node["linkmention"] || "false")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def concept_render(node, opts)
|
26
|
+
node&.at(ns("./refterm"))&.remove
|
27
|
+
r = node.at(ns("./renderterm"))
|
28
|
+
ref = node.at(ns("./xref | ./eref | ./termref"))
|
29
|
+
ref && opts[:ref] != "false" and r&.next = " "
|
30
|
+
opts[:ital] == "true" and r&.name = "em"
|
31
|
+
if opts[:linkmention] == "true" && !r.nil? && !ref.nil?
|
32
|
+
ref2 = ref.clone
|
33
|
+
r2 = r.clone
|
34
|
+
r.replace(ref2).children = r2
|
35
|
+
end
|
36
|
+
concept1_ref(node, ref, opts)
|
37
|
+
if opts[:ital] == "false"
|
38
|
+
r = node.at(ns(".//renderterm"))
|
39
|
+
r&.replace(r&.children)
|
40
|
+
end
|
41
|
+
node.replace(node.children)
|
42
|
+
end
|
43
|
+
|
44
|
+
def concept1_ref(_node, ref, opts)
|
45
|
+
ref.nil? and return
|
46
|
+
return ref.remove if opts[:ref] == "false"
|
47
|
+
|
48
|
+
r = concept1_ref_content(ref)
|
49
|
+
ref = r.at("./descendant-or-self::xmlns:xref | "\
|
50
|
+
"./descendant-or-self::xmlns:eref | "\
|
51
|
+
"./descendant-or-self::xmlns:termref")
|
52
|
+
%w(xref eref).include? ref&.name and get_linkend(ref)
|
53
|
+
if opts[:linkref] == "false" && %w(xref eref).include?(ref&.name)
|
54
|
+
ref.replace(ref.children)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def concept1_ref_content(ref)
|
59
|
+
if non_locality_elems(ref).select do |c|
|
60
|
+
!c.text? || /\S/.match(c)
|
61
|
+
end.empty?
|
62
|
+
ref.replace(@i18n.term_defined_in.sub(/%/,
|
63
|
+
ref.to_xml))
|
64
|
+
else ref.replace("[#{ref.to_xml}]")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def related(docxml)
|
69
|
+
docxml.xpath(ns("//related")).each { |f| related1(f) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def related1(node)
|
73
|
+
p = node.at(ns("./preferred"))
|
74
|
+
ref = node.at(ns("./xref | ./eref | ./termref"))
|
75
|
+
label = @i18n.relatedterms[node["type"]].upcase
|
76
|
+
node.replace(l10n("<p><strong>#{label}:</strong> "\
|
77
|
+
"<em>#{p.to_xml}</em> (#{ref.to_xml})</p>"))
|
78
|
+
end
|
79
|
+
|
80
|
+
def designation(docxml)
|
81
|
+
docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
|
82
|
+
designation1(p)
|
83
|
+
end
|
84
|
+
docxml.xpath(ns("//term")).each do |t|
|
85
|
+
merge_second_preferred(t)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def merge_second_preferred(term)
|
90
|
+
pref = nil
|
91
|
+
term.xpath(ns("./preferred")).each_with_index do |p, i|
|
92
|
+
if i.zero? then pref = p
|
93
|
+
else
|
94
|
+
pref << l10n("; #{p.children.to_xml}")
|
95
|
+
p.remove
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def designation1(desgn)
|
101
|
+
s = desgn.at(ns("./termsource"))
|
102
|
+
name = desgn.at(ns("./expression/name | ./letter-symbol/name | "\
|
103
|
+
"./graphical-symbol")) or return
|
104
|
+
|
105
|
+
g = desgn.at(ns("./expression/grammar")) and
|
106
|
+
name << " #{designation_grammar(g).join(', ')}"
|
107
|
+
desgn.children = name.children
|
108
|
+
s and desgn.next = s
|
109
|
+
end
|
110
|
+
|
111
|
+
def designation_grammar(grammar)
|
112
|
+
ret = []
|
113
|
+
grammar.xpath(ns("./gender")).each do |x|
|
114
|
+
ret << @i18n.grammar_abbrevs[x.text]
|
115
|
+
end
|
116
|
+
%w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
|
117
|
+
.each do |x|
|
118
|
+
grammar.at(ns("./#{x}[text() = 'true']")) and
|
119
|
+
ret << @i18n.grammar_abbrevs[x]
|
120
|
+
end
|
121
|
+
ret
|
122
|
+
end
|
123
|
+
|
124
|
+
def definition1(elem)
|
125
|
+
nodes = Nokogiri::XML::NodeSet.new(elem.document)
|
126
|
+
v = elem&.at(ns("./verbaldefinition"))&.children and nodes += v
|
127
|
+
n = elem&.at(ns("./nonverbalrepresentation"))&.children and nodes += n
|
128
|
+
elem.children = nodes
|
129
|
+
end
|
130
|
+
|
131
|
+
def termexample(docxml)
|
132
|
+
docxml.xpath(ns("//termexample")).each do |f|
|
133
|
+
example1(f)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def termnote(docxml)
|
138
|
+
docxml.xpath(ns("//termnote")).each do |f|
|
139
|
+
termnote1(f)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# introduce name element
|
144
|
+
def termnote1(elem)
|
145
|
+
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
|
146
|
+
prefix_name(elem, "", lower2cap(lbl), "name")
|
147
|
+
end
|
148
|
+
|
149
|
+
def termdefinition(docxml)
|
150
|
+
docxml.xpath(ns("//term[definition]")).each do |f|
|
151
|
+
termdefinition1(f)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def termdefinition1(elem)
|
156
|
+
unwrap_definition(elem)
|
157
|
+
multidef(elem) if elem.xpath(ns("./definition")).size > 1
|
158
|
+
end
|
159
|
+
|
160
|
+
def multidef(elem)
|
161
|
+
d = elem.at(ns("./definition"))
|
162
|
+
d = d.replace("<ol><li>#{d.children.to_xml}</li></ol>").first
|
163
|
+
elem.xpath(ns("./definition")).each do |f|
|
164
|
+
f = f.replace("<li>#{f.children.to_xml}</li>").first
|
165
|
+
d << f
|
166
|
+
end
|
167
|
+
d.wrap("<definition></definition>")
|
168
|
+
end
|
169
|
+
|
170
|
+
def unwrap_definition(elem)
|
171
|
+
elem.xpath(ns("./definition")).each do |d|
|
172
|
+
nodes = Nokogiri::XML::NodeSet.new(elem.document)
|
173
|
+
v = d&.at(ns("./verbaldefinition"))&.children and nodes += v
|
174
|
+
n = d&.at(ns("./nonverbalrepresentation"))&.children and nodes += n
|
175
|
+
d.children = nodes
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "presentation_function/block"
|
2
|
+
require_relative "presentation_function/terms"
|
2
3
|
require_relative "presentation_function/inline"
|
3
4
|
require_relative "presentation_function/math"
|
4
5
|
require_relative "presentation_function/section"
|
@@ -25,6 +26,7 @@ module IsoDoc
|
|
25
26
|
@xrefs.parse docxml
|
26
27
|
section docxml
|
27
28
|
block docxml
|
29
|
+
terms docxml
|
28
30
|
inline docxml
|
29
31
|
end
|
30
32
|
|
@@ -46,17 +48,13 @@ module IsoDoc
|
|
46
48
|
sourcecode docxml
|
47
49
|
formula docxml
|
48
50
|
example docxml
|
49
|
-
termexample docxml
|
50
51
|
note docxml
|
51
|
-
termnote docxml
|
52
|
-
termdefinition docxml
|
53
52
|
permission docxml
|
54
53
|
requirement docxml
|
55
54
|
recommendation docxml
|
56
55
|
end
|
57
56
|
|
58
57
|
def inline(docxml)
|
59
|
-
concept docxml
|
60
58
|
xref docxml
|
61
59
|
eref docxml
|
62
60
|
origin docxml
|
@@ -65,6 +63,15 @@ module IsoDoc
|
|
65
63
|
variant docxml
|
66
64
|
end
|
67
65
|
|
66
|
+
def terms(docxml)
|
67
|
+
termexample docxml
|
68
|
+
termnote docxml
|
69
|
+
termdefinition docxml
|
70
|
+
designation docxml
|
71
|
+
concept docxml
|
72
|
+
related docxml
|
73
|
+
end
|
74
|
+
|
68
75
|
def postprocess(result, filename, _dir)
|
69
76
|
toXML(result, filename)
|
70
77
|
@files_to_delete.each { |f| FileUtils.rm_rf f }
|
data/lib/isodoc/version.rb
CHANGED