isodoc 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -1
- data/.rubocop.yml +6 -2
- data/Gemfile +2 -2
- data/isodoc.gemspec +11 -11
- 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/convert.rb +28 -15
- data/lib/isodoc/css.rb +14 -4
- data/lib/isodoc/function/blocks.rb +4 -0
- data/lib/isodoc/function/inline.rb +31 -10
- data/lib/isodoc/function/references.rb +1 -1
- data/lib/isodoc/function/to_word_html.rb +19 -8
- data/lib/isodoc/function/utils.rb +1 -0
- data/lib/isodoc/html_function/postprocess.rb +8 -5
- data/lib/isodoc/pdf_convert.rb +1 -3
- data/lib/isodoc/presentation_function/block.rb +11 -5
- data/lib/isodoc/presentation_function/inline.rb +42 -38
- data/lib/isodoc/presentation_function/section.rb +1 -1
- data/lib/isodoc/presentation_xml_convert.rb +1 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/inline.rb +6 -0
- data/lib/isodoc/word_function/postprocess.rb +16 -6
- data/lib/isodoc/xref.rb +1 -1
- data/lib/isodoc/xref/xref_gen.rb +16 -15
- 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 +87 -0
- data/spec/isodoc/footnotes_spec.rb +1 -16
- data/spec/isodoc/inline_spec.rb +38 -1
- data/spec/isodoc/postproc_spec.rb +42 -14
- data/spec/isodoc/presentation_xml_spec.rb +345 -338
- 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 +2990 -2987
- data/spec/isodoc/xslfo_convert_spec.rb +39 -0
- data/spec/spec_helper.rb +30 -29
- metadata +71 -69
- data/.rubocop.ribose.yml +0 -65
- data/.rubocop.tb.yml +0 -650
data/lib/isodoc/css.rb
CHANGED
@@ -14,11 +14,22 @@ module IsoDoc
|
|
14
14
|
compiled_path
|
15
15
|
end
|
16
16
|
|
17
|
+
def localpath(path)
|
18
|
+
return path if %r{^[A-Z]:|^/|^file:/}.match(path)
|
19
|
+
return path unless (@sourcedir || @localdir) && path
|
20
|
+
File.expand_path(File.join((@sourcedir || @localdir), path))
|
21
|
+
end
|
22
|
+
|
17
23
|
# run this after @meta is populated
|
18
24
|
def populate_css
|
19
|
-
@htmlstylesheet = generate_css(@htmlstylesheet_name, true)
|
20
|
-
@wordstylesheet = generate_css(@wordstylesheet_name, false)
|
21
|
-
@standardstylesheet =
|
25
|
+
@htmlstylesheet = generate_css(localpath(@htmlstylesheet_name), true)
|
26
|
+
@wordstylesheet = generate_css(localpath(@wordstylesheet_name), false)
|
27
|
+
@standardstylesheet =
|
28
|
+
generate_css(localpath(@standardstylesheet_name), false)
|
29
|
+
@htmlstylesheet_override_name and @htmlstylesheet_override =
|
30
|
+
File.open(localpath(@htmlstylesheet_override_name))
|
31
|
+
@wordstylesheet_override_name and @wordstylesheet_override =
|
32
|
+
File.open(localpath(@wordstylesheet_override_name))
|
22
33
|
end
|
23
34
|
|
24
35
|
def default_fonts(_options)
|
@@ -77,7 +88,6 @@ module IsoDoc
|
|
77
88
|
# stripwordcss if HTML stylesheet, !stripwordcss if DOC stylesheet
|
78
89
|
def generate_css(filename, stripwordcss)
|
79
90
|
return nil if filename.nil?
|
80
|
-
|
81
91
|
filename = precompiled_style_or_original(filename)
|
82
92
|
stylesheet = File.read(filename, encoding: 'UTF-8')
|
83
93
|
stylesheet = populate_template(stylesheet, :word)
|
@@ -23,21 +23,26 @@ module IsoDoc::Function
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def xref_parse(node, out)
|
26
|
-
target = /#/.match(node["target"])
|
27
|
-
|
28
|
-
|
26
|
+
target = if /#/.match?(node["target"])
|
27
|
+
node["target"].sub(/#/, ".html#")
|
28
|
+
else
|
29
|
+
"##{node['target']}"
|
30
|
+
end
|
31
|
+
out.a(**{ "href": target }) { |l| no_locality_parse(node, l) }
|
29
32
|
end
|
30
33
|
|
31
34
|
def suffix_url(url)
|
32
|
-
return url if %r{^
|
35
|
+
return url if %r{^https?://}.match?(url)
|
36
|
+
|
33
37
|
url.sub(/#{File.extname(url)}$/, ".html")
|
34
38
|
end
|
35
39
|
|
36
40
|
def eref_target(node)
|
37
|
-
href = "
|
41
|
+
href = "##{node['bibitemid']}"
|
38
42
|
url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
|
39
43
|
"uri[@type = 'citation']"))
|
40
44
|
return href unless url
|
45
|
+
|
41
46
|
href = suffix_url(url.text)
|
42
47
|
anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
|
43
48
|
anchor and href += "##{anchor}"
|
@@ -68,10 +73,11 @@ module IsoDoc::Function
|
|
68
73
|
end
|
69
74
|
|
70
75
|
def stem_parse(node, out)
|
71
|
-
ooml =
|
76
|
+
ooml = case node["type"]
|
77
|
+
when "AsciiMath"
|
72
78
|
"#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
|
73
79
|
"#{@closemathdelim}"
|
74
|
-
|
80
|
+
when "MathML" then node.first_element_child.to_s
|
75
81
|
else
|
76
82
|
HTMLEntities.new.encode(node.text)
|
77
83
|
end
|
@@ -93,7 +99,7 @@ module IsoDoc::Function
|
|
93
99
|
height: node["height"] || "auto",
|
94
100
|
width: node["width"] || "auto",
|
95
101
|
title: node["title"],
|
96
|
-
alt: node["alt"]
|
102
|
+
alt: node["alt"] }
|
97
103
|
out.img **attr_code(attrs)
|
98
104
|
image_title_parse(out, caption)
|
99
105
|
end
|
@@ -106,12 +112,27 @@ module IsoDoc::Function
|
|
106
112
|
|
107
113
|
def text_parse(node, out)
|
108
114
|
return if node.nil? || node.text.nil?
|
115
|
+
|
109
116
|
text = node.to_s
|
110
|
-
|
111
|
-
gsub(
|
117
|
+
if in_sourcecode
|
118
|
+
text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/> ")
|
119
|
+
.gsub(/ (?= )/, " ")
|
120
|
+
end
|
112
121
|
out << text
|
113
122
|
end
|
114
123
|
|
124
|
+
def add_parse(node, out)
|
125
|
+
out.span **{class: "addition"} do |e|
|
126
|
+
node.children.each { |n| parse(n, e) }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def del_parse(node, out)
|
131
|
+
out.span **{class: "deletion"} do |e|
|
132
|
+
node.children.each { |n| parse(n, e) }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
115
136
|
def error_parse(node, out)
|
116
137
|
text = node.to_xml.gsub(/</, "<").gsub(/>/, ">")
|
117
138
|
out.para do |p|
|
@@ -87,7 +87,7 @@ module IsoDoc::Function
|
|
87
87
|
|
88
88
|
def omit_docid_prefix(prefix)
|
89
89
|
return true if prefix.nil? || prefix.empty?
|
90
|
-
return %w(ISO IEC ITU W3C metanorma).include? prefix
|
90
|
+
return %w(ISO IEC IEV ITU W3C csd metanorma rfc-anchor).include? prefix
|
91
91
|
end
|
92
92
|
|
93
93
|
def date_note_process(b, ref)
|
@@ -19,14 +19,21 @@ module IsoDoc::Function
|
|
19
19
|
def init_file(filename, debug)
|
20
20
|
filepath = Pathname.new(filename)
|
21
21
|
filename = filepath.sub_ext('').sub(/\.presentation$/, "").to_s
|
22
|
+
dir = init_dir(filename, debug)
|
23
|
+
@filename = filename
|
24
|
+
@localdir = filepath.parent.to_s + '/'
|
25
|
+
@sourcedir = @localdir
|
26
|
+
@sourcefilename and @sourcedir = Pathname.new(@sourcefilename).parent.to_s + '/'
|
27
|
+
[filename, dir]
|
28
|
+
end
|
29
|
+
|
30
|
+
def init_dir(filename, debug)
|
22
31
|
dir = "#{filename}_files"
|
23
32
|
unless debug
|
24
33
|
Dir.mkdir(dir, 0777) unless File.exists?(dir)
|
25
34
|
FileUtils.rm_rf "#{dir}/*"
|
26
35
|
end
|
27
|
-
|
28
|
-
@localdir = filepath.parent.to_s + '/'
|
29
|
-
[filename, dir]
|
36
|
+
dir
|
30
37
|
end
|
31
38
|
|
32
39
|
# tmp image dir is same directory as @filename
|
@@ -44,15 +51,16 @@ module IsoDoc::Function
|
|
44
51
|
if @standardstylesheet
|
45
52
|
head.style do |style|
|
46
53
|
@standardstylesheet.open
|
47
|
-
stylesheet = @standardstylesheet.read.
|
48
|
-
|
54
|
+
stylesheet = @standardstylesheet.read.gsub(
|
55
|
+
"FILENAME", File.basename(filename).sub(/\.presentation$/, "")
|
56
|
+
)
|
49
57
|
style.comment "\n#{stylesheet}\n"
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
54
62
|
def body_attr
|
55
|
-
{ lang:
|
63
|
+
{ lang: @lang.to_s }
|
56
64
|
end
|
57
65
|
|
58
66
|
def make_body(xml, docxml)
|
@@ -125,7 +133,7 @@ module IsoDoc::Function
|
|
125
133
|
i = scope isoxml, out, 0
|
126
134
|
i = norm_ref isoxml, out, i
|
127
135
|
i = terms_defs isoxml, out, i
|
128
|
-
|
136
|
+
symbols_abbrevs isoxml, out, i
|
129
137
|
clause isoxml, out
|
130
138
|
annex isoxml, out
|
131
139
|
bibliography isoxml, out
|
@@ -133,7 +141,7 @@ module IsoDoc::Function
|
|
133
141
|
|
134
142
|
def boilerplate(node, out)
|
135
143
|
boilerplate = node.at(ns("//boilerplate")) or return
|
136
|
-
out.div **{class: "authority"} do |s|
|
144
|
+
out.div **{ class: "authority" } do |s|
|
137
145
|
boilerplate.children.each do |n|
|
138
146
|
if n.name == "title"
|
139
147
|
s.h1 do |h|
|
@@ -225,6 +233,9 @@ module IsoDoc::Function
|
|
225
233
|
when "passthrough" then passthrough_parse(node, out)
|
226
234
|
when "amend" then amend_parse(node, out)
|
227
235
|
when "tab" then clausedelimspace(out) # in Presentation XML only
|
236
|
+
when "svg" then svg_parse(node, out) # in Presentation XML only
|
237
|
+
when "add" then add_parse(node, out)
|
238
|
+
when "del" then del_parse(node, out)
|
228
239
|
else
|
229
240
|
error_parse(node, out)
|
230
241
|
end
|
@@ -123,6 +123,7 @@ module IsoDoc::Function
|
|
123
123
|
h1 = to_xhtml_fragment(h.dup)
|
124
124
|
h1.traverse do |x|
|
125
125
|
x.replace(' ') if x.name == 'span' && /mso-tab-count/.match(x['style'])
|
126
|
+
x.remove if x.name == 'img'
|
126
127
|
x.remove if x.name == 'span' && x['class'] == 'MsoCommentReference'
|
127
128
|
x.remove if x.name == 'a' && x['class'] == 'FootnoteRef'
|
128
129
|
x.remove if x.name == 'span' && /mso-bookmark/.match(x['style'])
|
@@ -44,12 +44,14 @@ module IsoDoc::HtmlFunction
|
|
44
44
|
IsoDoc::HtmlFunction::MathvariantToPlain.new(docxml).convert
|
45
45
|
end
|
46
46
|
|
47
|
-
def htmlstylesheet
|
48
|
-
|
49
|
-
|
47
|
+
def htmlstylesheet(file)
|
48
|
+
return if file.nil?
|
49
|
+
file.open if file.is_a?(Tempfile)
|
50
|
+
stylesheet = file.read
|
50
51
|
xml = Nokogiri::XML("<style/>")
|
51
52
|
xml.children.first << Nokogiri::XML::Comment.new(xml, "\n#{stylesheet}\n")
|
52
|
-
|
53
|
+
file.close
|
54
|
+
file.unlink if file.is_a?(Tempfile)
|
53
55
|
xml.root.to_s
|
54
56
|
end
|
55
57
|
|
@@ -57,7 +59,8 @@ module IsoDoc::HtmlFunction
|
|
57
59
|
return docxml unless @htmlstylesheet
|
58
60
|
title = docxml.at("//*[local-name() = 'head']/*[local-name() = 'title']")
|
59
61
|
head = docxml.at("//*[local-name() = 'head']")
|
60
|
-
head << htmlstylesheet
|
62
|
+
head << htmlstylesheet(@htmlstylesheet)
|
63
|
+
s = htmlstylesheet(@htmlstylesheet_override) and head << s
|
61
64
|
docxml
|
62
65
|
end
|
63
66
|
|
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,3 +1,5 @@
|
|
1
|
+
require "base64"
|
2
|
+
|
1
3
|
module IsoDoc
|
2
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
5
|
def lower2cap(s)
|
@@ -6,9 +8,8 @@ module IsoDoc
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def figure(docxml)
|
9
|
-
docxml.xpath(ns("//
|
10
|
-
|
11
|
-
end
|
11
|
+
docxml.xpath(ns("//image")).each { |f| svg_extract(f) }
|
12
|
+
docxml.xpath(ns("//figure")).each { |f| figure1(f) }
|
12
13
|
docxml.xpath(ns("//svgmap")).each do |s|
|
13
14
|
if f = s.at(ns("./figure")) then s.replace(f)
|
14
15
|
else
|
@@ -17,9 +18,14 @@ module IsoDoc
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def svg_extract(f)
|
22
|
+
return unless %r{^data:image/svg\+xml;base64,}.match(f["src"])
|
23
|
+
svg = Base64.strict_decode64(f["src"].sub(%r{^data:image/svg\+xml;base64,}, ""))
|
24
|
+
f.replace(svg.sub(/<\?xml[^>]*>/, ""))
|
25
|
+
end
|
26
|
+
|
20
27
|
def figure1(f)
|
21
|
-
return sourcecode1(f) if f["class"] == "pseudocode" ||
|
22
|
-
f["type"] == "pseudocode"
|
28
|
+
return sourcecode1(f) if f["class"] == "pseudocode" || f["type"] == "pseudocode"
|
23
29
|
return if labelled_ancestor(f) && f.ancestors("figure").empty?
|
24
30
|
return if f.at(ns("./figure")) and !f.at(ns("./name"))
|
25
31
|
lbl = @xrefs.anchor(f['id'], :label, false) or return
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "twitter_cldr"
|
2
|
+
require "bigdecimal"
|
2
3
|
|
3
4
|
module IsoDoc
|
4
5
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
@@ -10,8 +11,7 @@ module IsoDoc
|
|
10
11
|
if node["citeas"].nil? && node["bibitemid"]
|
11
12
|
return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
|
12
13
|
elsif node["target"] && node["droploc"]
|
13
|
-
return @xrefs.anchor(node["target"], :value) ||
|
14
|
-
@xrefs.anchor(node["target"], :label) ||
|
14
|
+
return @xrefs.anchor(node["target"], :value) || @xrefs.anchor(node["target"], :label) ||
|
15
15
|
@xrefs.anchor(node["target"], :xref) || "???"
|
16
16
|
elsif node["target"] && !/.#./.match(node["target"])
|
17
17
|
linkend = anchor_linkend1(node)
|
@@ -22,9 +22,8 @@ module IsoDoc
|
|
22
22
|
def anchor_linkend1(node)
|
23
23
|
linkend = @xrefs.anchor(node["target"], :xref)
|
24
24
|
container = @xrefs.anchor(node["target"], :container, false)
|
25
|
-
(container && get_note_container_id(node) != container &&
|
26
|
-
|
27
|
-
linkend = prefix_container(container, linkend, node["target"])
|
25
|
+
(container && get_note_container_id(node) != container && @xrefs.get[node["target"]]) &&
|
26
|
+
linkend = prefix_container(container, linkend, node["target"])
|
28
27
|
capitalise_xref(node, linkend)
|
29
28
|
end
|
30
29
|
|
@@ -35,13 +34,11 @@ module IsoDoc
|
|
35
34
|
return linkend if linkend[0,1].match(/\p{Upper}/)
|
36
35
|
prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
|
37
36
|
node.xpath("./preceding::text()")
|
38
|
-
(prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ?
|
39
|
-
linkend&.capitalize : linkend
|
37
|
+
(prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ? linkend&.capitalize : linkend
|
40
38
|
end
|
41
39
|
|
42
40
|
def nearest_block_parent(node)
|
43
|
-
until %w(p title td th name formula
|
44
|
-
li dt dd sourcecode pre).include?(node.name)
|
41
|
+
until %w(p title td th name formula li dt dd sourcecode pre).include?(node.name)
|
45
42
|
node = node.parent
|
46
43
|
end
|
47
44
|
node
|
@@ -53,69 +50,79 @@ module IsoDoc
|
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
|
-
def get_linkend(
|
57
|
-
contents = non_locality_elems(
|
53
|
+
def get_linkend(node)
|
54
|
+
contents = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
|
58
55
|
return unless contents.empty?
|
59
|
-
link = anchor_linkend(
|
60
|
-
link += eref_localities(
|
61
|
-
non_locality_elems(
|
62
|
-
|
56
|
+
link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
|
57
|
+
link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link, node)
|
58
|
+
non_locality_elems(node).each { |n| n.remove }
|
59
|
+
node.add_child(link)
|
63
60
|
end
|
64
61
|
# so not <origin bibitemid="ISO7301" citeas="ISO 7301">
|
65
62
|
# <locality type="section"><reference>3.1</reference></locality></origin>
|
66
63
|
|
67
|
-
def eref_localities(refs, target)
|
64
|
+
def eref_localities(refs, target, n)
|
68
65
|
ret = ""
|
69
66
|
refs.each_with_index do |r, i|
|
70
67
|
delim = ","
|
71
68
|
delim = ";" if r.name == "localityStack" && i>0
|
72
|
-
ret = eref_locality_stack(r, i, target, delim, ret)
|
69
|
+
ret = eref_locality_stack(r, i, target, delim, ret, n)
|
73
70
|
end
|
74
71
|
ret
|
75
72
|
end
|
76
73
|
|
77
|
-
def eref_locality_stack(r, i, target, delim, ret)
|
74
|
+
def eref_locality_stack(r, i, target, delim, ret, n)
|
78
75
|
if r.name == "localityStack"
|
79
76
|
r.elements.each_with_index do |rr, j|
|
80
|
-
ret += eref_localities0(rr, j, target, delim)
|
77
|
+
ret += eref_localities0(rr, j, target, delim, n)
|
81
78
|
delim = ","
|
82
79
|
end
|
83
80
|
else
|
84
|
-
ret += eref_localities0(r, i, target, delim)
|
81
|
+
ret += eref_localities0(r, i, target, delim, n)
|
85
82
|
end
|
86
83
|
ret
|
87
84
|
end
|
88
85
|
|
89
|
-
def eref_localities0(r, i, target, delim)
|
86
|
+
def eref_localities0(r, i, target, delim, n)
|
90
87
|
if r["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
|
91
88
|
else
|
92
89
|
eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
|
93
|
-
r.at(ns("./referenceTo")), delim, @lang)
|
90
|
+
r.at(ns("./referenceTo")), delim, n, @lang)
|
94
91
|
end
|
95
92
|
end
|
96
93
|
|
97
94
|
# TODO: move to localization file
|
98
|
-
def eref_localities1_zh(target, type, from, to, delim)
|
95
|
+
def eref_localities1_zh(target, type, from, to, n, delim)
|
99
96
|
ret = "#{delim} 第#{from.text}" if from
|
100
97
|
ret += "–#{to.text}" if to
|
101
98
|
loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize )
|
102
|
-
ret += " #{loc}"
|
99
|
+
ret += " #{loc}" unless n["droploc"] == "true"
|
103
100
|
ret
|
104
101
|
end
|
105
102
|
|
106
103
|
# TODO: move to localization file
|
107
|
-
def eref_localities1(target, type, from, to, delim, lang = "en")
|
104
|
+
def eref_localities1(target, type, from, to, delim, n, lang = "en")
|
108
105
|
return "" if type == "anchor"
|
109
|
-
lang == "zh" and
|
110
|
-
return l10n(eref_localities1_zh(target, type, from, to, delim))
|
106
|
+
lang == "zh" and return l10n(eref_localities1_zh(target, type, from, to, n, delim))
|
111
107
|
ret = delim
|
112
|
-
|
113
|
-
ret += " #{loc}"
|
108
|
+
ret += eref_locality_populate(type, n)
|
114
109
|
ret += " #{from.text}" if from
|
115
110
|
ret += "–#{to.text}" if to
|
116
111
|
l10n(ret)
|
117
112
|
end
|
118
113
|
|
114
|
+
def eref_locality_populate(type, n)
|
115
|
+
return "" if n["droploc"] == "true"
|
116
|
+
loc = @i18n.locality[type] || type.sub(/^locality:/, "")
|
117
|
+
loc = case n["case"]
|
118
|
+
when "capital" then loc.capitalize
|
119
|
+
when "lowercase" then loc.downcase
|
120
|
+
else
|
121
|
+
loc.capitalize
|
122
|
+
end
|
123
|
+
" #{loc}"
|
124
|
+
end
|
125
|
+
|
119
126
|
def xref(docxml)
|
120
127
|
docxml.xpath(ns("//xref")).each { |f| xref1(f) }
|
121
128
|
end
|
@@ -163,23 +170,22 @@ module IsoDoc
|
|
163
170
|
# TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
|
164
171
|
def localize_maths(f, locale)
|
165
172
|
f.xpath(".//m:mn", MATHML).each do |x|
|
166
|
-
num =
|
173
|
+
num = BigDecimal(x.text)
|
167
174
|
precision = /\./.match(x.text) ? x.text.sub(/^.*\./, "").size : 0
|
168
175
|
x.children = localized_number(num, locale, precision)
|
169
176
|
end
|
170
177
|
end
|
171
178
|
|
172
|
-
# By itself
|
179
|
+
# By itself twitter-cldr does not support fraction part digits grouping
|
173
180
|
# and custom delimeter, will decorate fraction part manually
|
174
181
|
def localized_number(num, locale, precision)
|
175
|
-
localized = precision == 0 ? num.localize(locale).to_s :
|
182
|
+
localized = (precision == 0) ? num.localize(locale).to_s :
|
176
183
|
num.localize(locale).to_decimal.to_s(:precision => precision)
|
177
184
|
twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
|
178
185
|
return localized unless twitter_cldr_reader_symbols[:decimal]
|
179
186
|
integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal])
|
180
187
|
return localized if fraction.nil? || fraction.length.zero?
|
181
|
-
[integer, decorate_fraction_part(fraction, locale)].
|
182
|
-
join(twitter_cldr_reader_symbols[:decimal])
|
188
|
+
[integer, decorate_fraction_part(fraction, locale)].join(twitter_cldr_reader_symbols[:decimal])
|
183
189
|
end
|
184
190
|
|
185
191
|
def decorate_fraction_part(fract, locale)
|
@@ -229,8 +235,7 @@ module IsoDoc
|
|
229
235
|
end
|
230
236
|
|
231
237
|
def variant1(node)
|
232
|
-
if (!node["lang"] || node["lang"] == @lang) &&
|
233
|
-
(!node["script"] || node["script"] == @script)
|
238
|
+
if (!node["lang"] || node["lang"] == @lang) && (!node["script"] || node["script"] == @script)
|
234
239
|
elsif found_matching_variant_sibling(node)
|
235
240
|
node["remove"] = "true"
|
236
241
|
else
|
@@ -243,8 +248,7 @@ module IsoDoc
|
|
243
248
|
foll = node.xpath("./following-sibling::xmlns:variant")
|
244
249
|
found = false
|
245
250
|
(prev + foll).each do |n|
|
246
|
-
found = true if n["lang"] == @lang &&
|
247
|
-
(!n["script"] || n["script"] == @script)
|
251
|
+
found = true if n["lang"] == @lang && (!n["script"] || n["script"] == @script)
|
248
252
|
end
|
249
253
|
found
|
250
254
|
end
|