isodoc 1.5.3 → 1.6.2
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/.github/workflows/rake.yml +1 -1
- data/.rubocop.yml +6 -4
- data/Gemfile +2 -2
- data/bin/rspec +1 -2
- data/isodoc.gemspec +11 -11
- data/lib/isodoc-yaml/i18n-ar.yaml +152 -0
- data/lib/isodoc-yaml/i18n-de.yaml +149 -0
- data/lib/isodoc-yaml/i18n-es.yaml +151 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +154 -0
- data/lib/isodoc/base_style/all.css +7 -0
- data/lib/isodoc/base_style/metanorma_word.css +7 -0
- data/lib/isodoc/base_style/metanorma_word.scss +8 -0
- data/lib/isodoc/base_style/reset.css +7 -0
- data/lib/isodoc/base_style/reset.scss +9 -0
- data/lib/isodoc/base_style/scripts.html +187 -0
- data/lib/isodoc/class_utils.rb +6 -5
- data/lib/isodoc/common.rb +2 -0
- data/lib/isodoc/convert.rb +30 -17
- data/lib/isodoc/css.rb +42 -28
- data/lib/isodoc/function/blocks.rb +25 -4
- data/lib/isodoc/function/blocks_example_note.rb +2 -2
- data/lib/isodoc/function/cleanup.rb +1 -2
- data/lib/isodoc/function/form.rb +51 -0
- data/lib/isodoc/function/inline.rb +32 -10
- data/lib/isodoc/function/references.rb +55 -42
- data/lib/isodoc/function/table.rb +1 -0
- data/lib/isodoc/function/to_word_html.rb +29 -27
- data/lib/isodoc/function/utils.rb +41 -38
- data/lib/isodoc/gem_tasks.rb +30 -31
- data/lib/isodoc/html_convert.rb +6 -4
- data/lib/isodoc/html_function/form.rb +62 -0
- data/lib/isodoc/html_function/postprocess.rb +35 -76
- data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
- data/lib/isodoc/i18n.rb +33 -31
- data/lib/isodoc/pdf_convert.rb +1 -3
- data/lib/isodoc/presentation_function/block.rb +26 -11
- data/lib/isodoc/presentation_function/inline.rb +60 -111
- data/lib/isodoc/presentation_function/math.rb +84 -0
- data/lib/isodoc/presentation_xml_convert.rb +2 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +28 -24
- data/lib/isodoc/word_function/footnotes.rb +22 -15
- data/lib/isodoc/word_function/inline.rb +6 -0
- data/lib/isodoc/word_function/postprocess.rb +16 -6
- data/lib/isodoc/xref.rb +10 -11
- data/lib/isodoc/xref/xref_counter.rb +31 -15
- data/lib/isodoc/xref/xref_gen.rb +28 -22
- data/lib/isodoc/xref/xref_sect_gen.rb +22 -20
- data/lib/isodoc/xslfo_convert.rb +36 -25
- data/spec/assets/html_override.css +1 -0
- data/spec/assets/word_override.css +1 -0
- data/spec/isodoc/blocks_spec.rb +2599 -2503
- data/spec/isodoc/cleanup_spec.rb +1107 -1109
- data/spec/isodoc/footnotes_spec.rb +1 -16
- data/spec/isodoc/form_spec.rb +156 -0
- data/spec/isodoc/i18n_spec.rb +984 -972
- data/spec/isodoc/inline_spec.rb +984 -920
- data/spec/isodoc/lists_spec.rb +316 -315
- data/spec/isodoc/postproc_spec.rb +1692 -1538
- data/spec/isodoc/presentation_xml_spec.rb +345 -338
- data/spec/isodoc/ref_spec.rb +718 -723
- data/spec/isodoc/section_spec.rb +910 -902
- data/spec/isodoc/table_spec.rb +566 -556
- data/spec/isodoc/terms_spec.rb +252 -256
- data/spec/isodoc/xref_spec.rb +3040 -2985
- data/spec/isodoc/xslfo_convert_spec.rb +39 -0
- data/spec/spec_helper.rb +30 -29
- metadata +80 -69
- data/.rubocop.ribose.yml +0 -65
- data/.rubocop.tb.yml +0 -650
data/lib/isodoc/i18n.rb
CHANGED
@@ -5,44 +5,47 @@ module IsoDoc
|
|
5
5
|
def load_yaml(lang, script, i18nyaml = nil)
|
6
6
|
ret = load_yaml1(lang, script)
|
7
7
|
return normalise_hash(ret.merge(YAML.load_file(i18nyaml))) if i18nyaml
|
8
|
+
|
8
9
|
normalise_hash(ret)
|
9
10
|
end
|
10
11
|
|
11
12
|
def normalise_hash(ret)
|
12
|
-
|
13
|
+
case ret
|
14
|
+
when Hash
|
13
15
|
ret.each do |k, v|
|
14
16
|
ret[k] = normalise_hash(v)
|
15
17
|
end
|
16
18
|
ret
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
ret
|
19
|
+
when Array then ret.map { |n| normalise_hash(n) }
|
20
|
+
when String then ret.unicode_normalize(:nfc)
|
21
|
+
else ret
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def load_yaml1(lang, script)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
YAML.load_file(File.join(File.dirname(__FILE__),
|
33
|
-
"../isodoc-yaml/i18n-zh-Hans.yaml"))
|
26
|
+
case lang
|
27
|
+
when "en", "fr", "ru", "de", "es", "ar"
|
28
|
+
load_yaml2(lang)
|
29
|
+
when "zh"
|
30
|
+
if script == "Hans" then load_yaml2("zh-Hans")
|
31
|
+
else load_yaml2("en")
|
32
|
+
end
|
34
33
|
else
|
35
|
-
|
36
|
-
"../isodoc-yaml/i18n-en.yaml"))
|
34
|
+
load_yaml2("en")
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
38
|
+
def load_yaml2(str)
|
39
|
+
YAML.load_file(File.join(File.dirname(__FILE__),
|
40
|
+
"../isodoc-yaml/i18n-#{str}.yaml"))
|
41
|
+
end
|
42
|
+
|
40
43
|
def get
|
41
44
|
@labels
|
42
45
|
end
|
43
46
|
|
44
|
-
def set(
|
45
|
-
@labels[
|
47
|
+
def set(key, val)
|
48
|
+
@labels[key] = val
|
46
49
|
end
|
47
50
|
|
48
51
|
def initialize(lang, script, i18nyaml = nil)
|
@@ -57,37 +60,36 @@ module IsoDoc
|
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
60
|
-
def self.l10n(
|
61
|
-
l10n(
|
63
|
+
def self.l10n(text, lang = @lang, script = @script)
|
64
|
+
l10n(text, lang, script)
|
62
65
|
end
|
63
66
|
|
64
67
|
# TODO: move to localization file
|
65
68
|
# function localising spaces and punctuation.
|
66
69
|
# Not clear if period needs to be localised for zh
|
67
|
-
def l10n(
|
70
|
+
def l10n(text, lang = @lang, script = @script)
|
68
71
|
if lang == "zh" && script == "Hans"
|
69
|
-
xml = Nokogiri::HTML::DocumentFragment.parse(
|
72
|
+
xml = Nokogiri::HTML::DocumentFragment.parse(text)
|
70
73
|
xml.traverse do |n|
|
71
74
|
next unless n.text?
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
+
|
76
|
+
n.replace(n.text.gsub(/ /, "").gsub(/:/, ":").gsub(/,/, "、")
|
77
|
+
.gsub(/\(/, "(").gsub(/\)/, ")").gsub(/\[/, "【").gsub(/\]/, "】"))
|
75
78
|
end
|
76
79
|
xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
|
77
|
-
else
|
78
|
-
x
|
80
|
+
else text
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
84
|
def multiple_and(names, andword)
|
83
|
-
return
|
85
|
+
return "" if names.empty?
|
84
86
|
return names[0] if names.length == 1
|
87
|
+
|
85
88
|
(names.length == 2) &&
|
86
89
|
(return l10n("#{names[0]} #{andword} #{names[1]}", @lang, @script))
|
87
|
-
l10n(names[0..-2].join(
|
90
|
+
l10n(names[0..-2].join(", ") + " #{andword} #{names[-1]}", @lang, @script)
|
88
91
|
end
|
89
92
|
|
90
|
-
#module_function :l10n
|
91
|
-
|
93
|
+
# module_function :l10n
|
92
94
|
end
|
93
95
|
end
|
data/lib/isodoc/pdf_convert.rb
CHANGED
@@ -42,9 +42,7 @@ module IsoDoc
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def xref_parse(node, out)
|
45
|
-
|
46
|
-
"##{node["target"]}"
|
47
|
-
out.a(**{ "href": target }) { |l| l << get_linkend(node) }
|
45
|
+
out.a(**{ "href": target_pdf(node) }) { |l| l << get_linkend(node) }
|
48
46
|
end
|
49
47
|
end
|
50
48
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
require "base64"
|
2
|
+
|
1
3
|
module IsoDoc
|
2
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
5
|
def lower2cap(s)
|
4
|
-
return s if /^[[:upper:]][[:upper:]]/.match(s)
|
6
|
+
return s if /^[[:upper:]][[:upper:]]/.match?(s)
|
7
|
+
|
5
8
|
s.capitalize
|
6
9
|
end
|
7
10
|
|
8
11
|
def figure(docxml)
|
9
|
-
docxml.xpath(ns("//
|
10
|
-
|
11
|
-
end
|
12
|
+
docxml.xpath(ns("//image")).each { |f| svg_extract(f) }
|
13
|
+
docxml.xpath(ns("//figure")).each { |f| figure1(f) }
|
12
14
|
docxml.xpath(ns("//svgmap")).each do |s|
|
13
15
|
if f = s.at(ns("./figure")) then s.replace(f)
|
14
16
|
else
|
@@ -17,17 +19,27 @@ module IsoDoc
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
22
|
+
def svg_extract(f)
|
23
|
+
return unless %r{^data:image/svg\+xml;base64,}.match?(f["src"])
|
24
|
+
|
25
|
+
svg = Base64.strict_decode64(f["src"]
|
26
|
+
.sub(%r{^data:image/svg\+xml;base64,}, ""))
|
27
|
+
f.replace(svg.sub(/<\?xml[^>]*>/, ""))
|
28
|
+
end
|
29
|
+
|
20
30
|
def figure1(f)
|
21
|
-
return sourcecode1(f) if f["class"] == "pseudocode" ||
|
22
|
-
f["type"] == "pseudocode"
|
31
|
+
return sourcecode1(f) if f["class"] == "pseudocode" || f["type"] == "pseudocode"
|
23
32
|
return if labelled_ancestor(f) && f.ancestors("figure").empty?
|
24
33
|
return if f.at(ns("./figure")) and !f.at(ns("./name"))
|
34
|
+
|
25
35
|
lbl = @xrefs.anchor(f['id'], :label, false) or return
|
26
|
-
prefix_name(f, " — ",
|
36
|
+
prefix_name(f, " — ",
|
37
|
+
l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
|
27
38
|
end
|
28
39
|
|
29
40
|
def prefix_name(f, delim, number, elem)
|
30
41
|
return if number.nil? || number.empty?
|
42
|
+
|
31
43
|
unless name = f.at(ns("./#{elem}"))
|
32
44
|
f.children.empty? and f.add_child("<#{elem}></#{elem}>") or
|
33
45
|
f.children.first.previous = "<#{elem}></#{elem}>"
|
@@ -46,6 +58,7 @@ module IsoDoc
|
|
46
58
|
def sourcecode1(f)
|
47
59
|
return if labelled_ancestor(f)
|
48
60
|
return unless f.ancestors("example").empty?
|
61
|
+
|
49
62
|
lbl = @xrefs.anchor(f['id'], :label, false) or return
|
50
63
|
prefix_name(f, " — ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
|
51
64
|
end
|
@@ -90,6 +103,7 @@ module IsoDoc
|
|
90
103
|
# introduce name element
|
91
104
|
def note1(f)
|
92
105
|
return if f.parent.name == "bibitem"
|
106
|
+
|
93
107
|
n = @xrefs.get[f["id"]]
|
94
108
|
lbl = (@i18n.note if n.nil? || n[:label].nil? || n[:label].empty?) ?
|
95
109
|
@i18n.note: l10n("#{@i18n.note} #{n[:label]}")
|
@@ -104,7 +118,7 @@ module IsoDoc
|
|
104
118
|
|
105
119
|
# introduce name element
|
106
120
|
def termnote1(f)
|
107
|
-
lbl = l10n(@xrefs.anchor(f[
|
121
|
+
lbl = l10n(@xrefs.anchor(f["id"], :label) || "???")
|
108
122
|
prefix_name(f, "", lower2cap(lbl), "name")
|
109
123
|
end
|
110
124
|
|
@@ -128,7 +142,7 @@ module IsoDoc
|
|
128
142
|
|
129
143
|
# introduce name element
|
130
144
|
def recommendation1(f, type)
|
131
|
-
n = @xrefs.anchor(f[
|
145
|
+
n = @xrefs.anchor(f["id"], :label, false)
|
132
146
|
lbl = (n.nil? ? type : l10n("#{type} #{n}"))
|
133
147
|
prefix_name(f, "", lbl, "name")
|
134
148
|
end
|
@@ -142,7 +156,8 @@ module IsoDoc
|
|
142
156
|
def table1(f)
|
143
157
|
return if labelled_ancestor(f)
|
144
158
|
return if f["unnumbered"] && !f.at(ns("./name"))
|
145
|
-
|
159
|
+
|
160
|
+
n = @xrefs.anchor(f["id"], :label, false)
|
146
161
|
prefix_name(f, " — ", l10n("#{lower2cap @i18n.table} #{n}"), "name")
|
147
162
|
end
|
148
163
|
|
@@ -154,7 +169,7 @@ module IsoDoc
|
|
154
169
|
end
|
155
170
|
|
156
171
|
def amend1(f)
|
157
|
-
f.xpath(ns("./autonumber")).each
|
172
|
+
f.xpath(ns("./autonumber")).each(&:remove)
|
158
173
|
f.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
|
159
174
|
f.xpath(ns("./description")).each { |a| a.replace(a.children) }
|
160
175
|
f.replace(f.children)
|
@@ -1,14 +1,12 @@
|
|
1
|
-
require "twitter_cldr"
|
2
|
-
|
3
1
|
module IsoDoc
|
4
2
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
5
3
|
def prefix_container(container, linkend, _target)
|
6
|
-
l10n(@xrefs.anchor(container, :xref)
|
4
|
+
l10n("#{@xrefs.anchor(container, :xref)}, #{linkend}")
|
7
5
|
end
|
8
6
|
|
9
7
|
def anchor_linkend(node, linkend)
|
10
8
|
if node["citeas"].nil? && node["bibitemid"]
|
11
|
-
return @xrefs.anchor(node["bibitemid"]
|
9
|
+
return @xrefs.anchor(node["bibitemid"], :xref) || "???"
|
12
10
|
elsif node["target"] && node["droploc"]
|
13
11
|
return @xrefs.anchor(node["target"], :value) ||
|
14
12
|
@xrefs.anchor(node["target"], :label) ||
|
@@ -16,6 +14,7 @@ module IsoDoc
|
|
16
14
|
elsif node["target"] && !/.#./.match(node["target"])
|
17
15
|
linkend = anchor_linkend1(node)
|
18
16
|
end
|
17
|
+
|
19
18
|
linkend || "???"
|
20
19
|
end
|
21
20
|
|
@@ -23,8 +22,8 @@ module IsoDoc
|
|
23
22
|
linkend = @xrefs.anchor(node["target"], :xref)
|
24
23
|
container = @xrefs.anchor(node["target"], :container, false)
|
25
24
|
(container && get_note_container_id(node) != container &&
|
26
|
-
@xrefs.get[node["target"]])
|
27
|
-
|
25
|
+
@xrefs.get[node["target"]]) and
|
26
|
+
linkend = prefix_container(container, linkend, node["target"])
|
28
27
|
capitalise_xref(node, linkend)
|
29
28
|
end
|
30
29
|
|
@@ -32,90 +31,108 @@ module IsoDoc
|
|
32
31
|
return linkend unless %w(Latn Cyrl Grek).include? @script
|
33
32
|
return linkend&.capitalize if node["case"] == "capital"
|
34
33
|
return linkend&.downcase if node["case"] == "lowercase"
|
35
|
-
return linkend if linkend[0,1].match(/\p{Upper}/)
|
34
|
+
return linkend if linkend[0, 1].match?(/\p{Upper}/)
|
35
|
+
|
36
36
|
prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
|
37
37
|
node.xpath("./preceding::text()")
|
38
|
-
|
39
|
-
linkend&.capitalize
|
38
|
+
if prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map(&:text).join)
|
39
|
+
linkend&.capitalize
|
40
|
+
else linkend
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
def nearest_block_parent(node)
|
43
|
-
until %w(p title td th name formula
|
44
|
-
|
45
|
-
|
45
|
+
until %w(p title td th name formula li dt dd sourcecode pre)
|
46
|
+
.include?(node.name)
|
47
|
+
node = node.parent
|
46
48
|
end
|
47
49
|
node
|
48
50
|
end
|
49
51
|
|
50
52
|
def non_locality_elems(node)
|
51
|
-
node.children.
|
52
|
-
|
53
|
+
node.children.reject do |c|
|
54
|
+
%w{locality localityStack}.include? c.name
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
def get_linkend(
|
57
|
-
|
58
|
-
return unless
|
59
|
-
|
60
|
-
link
|
61
|
-
|
62
|
-
|
58
|
+
def get_linkend(node)
|
59
|
+
c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
|
60
|
+
return unless c1.empty?
|
61
|
+
|
62
|
+
link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
|
63
|
+
link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
|
64
|
+
link, node)
|
65
|
+
non_locality_elems(node).each(&:remove)
|
66
|
+
node.add_child(link)
|
63
67
|
end
|
64
68
|
# so not <origin bibitemid="ISO7301" citeas="ISO 7301">
|
65
69
|
# <locality type="section"><reference>3.1</reference></locality></origin>
|
66
70
|
|
67
|
-
def eref_localities(refs, target)
|
71
|
+
def eref_localities(refs, target, n)
|
68
72
|
ret = ""
|
69
73
|
refs.each_with_index do |r, i|
|
70
74
|
delim = ","
|
71
|
-
delim = ";" if r.name == "localityStack" && i
|
72
|
-
ret = eref_locality_stack(r, i, target, delim, ret)
|
75
|
+
delim = ";" if r.name == "localityStack" && i.positive?
|
76
|
+
ret = eref_locality_stack(r, i, target, delim, ret, n)
|
73
77
|
end
|
74
78
|
ret
|
75
79
|
end
|
76
80
|
|
77
|
-
def eref_locality_stack(r,
|
81
|
+
def eref_locality_stack(r, idx, target, delim, ret, n)
|
78
82
|
if r.name == "localityStack"
|
79
83
|
r.elements.each_with_index do |rr, j|
|
80
|
-
ret += eref_localities0(rr, j, target, delim)
|
84
|
+
ret += eref_localities0(rr, j, target, delim, n)
|
81
85
|
delim = ","
|
82
86
|
end
|
83
87
|
else
|
84
|
-
ret += eref_localities0(r,
|
88
|
+
ret += eref_localities0(r, idx, target, delim, n)
|
85
89
|
end
|
86
90
|
ret
|
87
91
|
end
|
88
92
|
|
89
|
-
def eref_localities0(r,
|
93
|
+
def eref_localities0(r, _i, target, delim, n)
|
90
94
|
if r["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
|
91
95
|
else
|
92
96
|
eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
|
93
|
-
r.at(ns("./referenceTo")), delim, @lang)
|
97
|
+
r.at(ns("./referenceTo")), delim, n, @lang)
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
97
101
|
# TODO: move to localization file
|
98
|
-
def eref_localities1_zh(
|
102
|
+
def eref_localities1_zh(_target, type, from, to, n, delim)
|
99
103
|
ret = "#{delim} 第#{from.text}" if from
|
100
104
|
ret += "–#{to.text}" if to
|
101
|
-
loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize
|
102
|
-
ret += " #{loc}"
|
105
|
+
loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize)
|
106
|
+
ret += " #{loc}" unless n["droploc"] == "true"
|
103
107
|
ret
|
104
108
|
end
|
105
109
|
|
106
110
|
# TODO: move to localization file
|
107
|
-
def eref_localities1(target, type, from, to, delim, lang = "en")
|
111
|
+
def eref_localities1(target, type, from, to, delim, n, lang = "en")
|
108
112
|
return "" if type == "anchor"
|
113
|
+
|
109
114
|
lang == "zh" and
|
110
|
-
return l10n(eref_localities1_zh(target, type, from, to, delim))
|
115
|
+
return l10n(eref_localities1_zh(target, type, from, to, n, delim))
|
111
116
|
ret = delim
|
112
|
-
|
113
|
-
ret += " #{loc}"
|
117
|
+
ret += eref_locality_populate(type, n)
|
114
118
|
ret += " #{from.text}" if from
|
115
119
|
ret += "–#{to.text}" if to
|
116
120
|
l10n(ret)
|
117
121
|
end
|
118
122
|
|
123
|
+
def eref_locality_populate(type, node)
|
124
|
+
return "" if node["droploc"] == "true"
|
125
|
+
|
126
|
+
loc = @i18n.locality[type] || type.sub(/^locality:/, "")
|
127
|
+
loc = case node["case"]
|
128
|
+
when "capital" then loc.capitalize
|
129
|
+
when "lowercase" then loc.downcase
|
130
|
+
else
|
131
|
+
loc.capitalize
|
132
|
+
end
|
133
|
+
" #{loc}"
|
134
|
+
end
|
135
|
+
|
119
136
|
def xref(docxml)
|
120
137
|
docxml.xpath(ns("//xref")).each { |f| xref1(f) }
|
121
138
|
end
|
@@ -132,8 +149,8 @@ module IsoDoc
|
|
132
149
|
docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
|
133
150
|
end
|
134
151
|
|
135
|
-
def xref1(
|
136
|
-
get_linkend(
|
152
|
+
def xref1(node)
|
153
|
+
get_linkend(node)
|
137
154
|
end
|
138
155
|
|
139
156
|
def concept(docxml)
|
@@ -144,85 +161,17 @@ module IsoDoc
|
|
144
161
|
content = node.first_element_child.children.select do |c|
|
145
162
|
!%w{locality localityStack}.include? c.name
|
146
163
|
end.select { |c| !c.text? || /\S/.match(c) }
|
147
|
-
node.replace content.empty? ?
|
164
|
+
node.replace content.empty? ?
|
148
165
|
@i18n.term_defined_in.sub(/%/, node.first_element_child.to_xml) :
|
149
166
|
"<em>#{node.children.to_xml}</em>"
|
150
167
|
end
|
151
168
|
|
152
|
-
|
153
|
-
MATHML = { "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
|
154
|
-
|
155
|
-
def mathml(docxml)
|
156
|
-
locale = twitter_cldr_localiser()
|
157
|
-
docxml.xpath("//m:math", MATHML).each do |f|
|
158
|
-
mathml1(f, locale)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# symbols is merged into
|
163
|
-
# TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
|
164
|
-
def localize_maths(f, locale)
|
165
|
-
f.xpath(".//m:mn", MATHML).each do |x|
|
166
|
-
num = /\./.match(x.text) ? x.text.to_f : x.text.to_i
|
167
|
-
precision = /\./.match(x.text) ? x.text.sub(/^.*\./, "").size : 0
|
168
|
-
x.children = localized_number(num, locale, precision)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
# By itself twiiter cldr does not support fraction part digits grouping
|
173
|
-
# and custom delimeter, will decorate fraction part manually
|
174
|
-
def localized_number(num, locale, precision)
|
175
|
-
localized = precision == 0 ? num.localize(locale).to_s :
|
176
|
-
num.localize(locale).to_decimal.to_s(:precision => precision)
|
177
|
-
twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
|
178
|
-
return localized unless twitter_cldr_reader_symbols[:decimal]
|
179
|
-
integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal])
|
180
|
-
return localized if fraction.nil? || fraction.length.zero?
|
181
|
-
[integer, decorate_fraction_part(fraction, locale)].
|
182
|
-
join(twitter_cldr_reader_symbols[:decimal])
|
183
|
-
end
|
184
|
-
|
185
|
-
def decorate_fraction_part(fract, locale)
|
186
|
-
result = []
|
187
|
-
twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
|
188
|
-
fract = fract.slice(0..(twitter_cldr_reader_symbols[:precision] || -1))
|
189
|
-
fr_group_digits = twitter_cldr_reader_symbols[:fraction_group_digits] || 1
|
190
|
-
until fract.empty?
|
191
|
-
result.push(fract.slice!(0, fr_group_digits))
|
192
|
-
end
|
193
|
-
result.join(twitter_cldr_reader_symbols[:fraction_group].to_s)
|
194
|
-
end
|
195
|
-
|
196
|
-
def twitter_cldr_localiser_symbols
|
197
|
-
{}
|
198
|
-
end
|
199
|
-
|
200
|
-
def twitter_cldr_reader(locale)
|
201
|
-
num = TwitterCldr::DataReaders::NumberDataReader.new(locale)
|
202
|
-
num.symbols.merge!(twitter_cldr_localiser_symbols)
|
203
|
-
end
|
204
|
-
|
205
|
-
def twitter_cldr_localiser()
|
206
|
-
locale = TwitterCldr.supported_locale?(@lang.to_sym) ? @lang.to_sym : :en
|
207
|
-
twitter_cldr_reader(locale)
|
208
|
-
locale
|
209
|
-
end
|
210
|
-
|
211
|
-
def mathml1(f, locale)
|
212
|
-
localize_maths(f, locale)
|
213
|
-
return unless f.elements.size == 1 && f.elements.first.name == "mn"
|
214
|
-
if f.parent.name == "stem"
|
215
|
-
f.parent.replace(f.at("./m:mn", MATHML).children)
|
216
|
-
else
|
217
|
-
f.replace(f.at("./m:mn", MATHML).children)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
169
|
def variant(docxml)
|
222
170
|
docxml.xpath(ns("//variant")).each { |f| variant1(f) }
|
223
|
-
docxml.xpath(ns("//variant[@remove = 'true']")).each
|
171
|
+
docxml.xpath(ns("//variant[@remove = 'true']")).each(&:remove)
|
224
172
|
docxml.xpath(ns("//variant")).each do |v|
|
225
173
|
next unless v&.next&.name == "variant"
|
174
|
+
|
226
175
|
v.next = "/"
|
227
176
|
end
|
228
177
|
docxml.xpath(ns("//variant")).each { |f| f.replace(f.children) }
|
@@ -233,11 +182,11 @@ module IsoDoc
|
|
233
182
|
(!node["script"] || node["script"] == @script)
|
234
183
|
elsif found_matching_variant_sibling(node)
|
235
184
|
node["remove"] = "true"
|
236
|
-
else
|
237
|
-
#return unless !node.at("./preceding-sibling::xmlns:variant")
|
238
185
|
end
|
239
186
|
end
|
240
187
|
|
188
|
+
private
|
189
|
+
|
241
190
|
def found_matching_variant_sibling(node)
|
242
191
|
prev = node.xpath("./preceding-sibling::xmlns:variant")
|
243
192
|
foll = node.xpath("./following-sibling::xmlns:variant")
|