isodoc 2.0.6 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3633136f121834056746917a4af6b5c6b917365ffb941b0561a0941d16ccfb3a
4
- data.tar.gz: d15461d2103ff7e43ee22c1afe80d4a4b4e0a240a76c3ee5afe11df47652ab72
3
+ metadata.gz: a7850182b408d69f4ae9de09a385c8813c366a2ffd15122596ac3cd95e1b62f6
4
+ data.tar.gz: 2920db0b8a2d7887a326ad5f58f23550c0eb949e33fdbcf7dd7601d805b08e8f
5
5
  SHA512:
6
- metadata.gz: 047f237237096490e9a6380675f96d46e1de721025f17eb60a3140face2cfe794d649fb31d992bca7a63e863c42c6d79cd42fa0810c77f6bc09518d905b55fbf
7
- data.tar.gz: 7cde47764db6a87866b4fe618550dc8412b85c32c90ea2e60a903083849b6e16325574d723dbb83948a8524062fa63b4c0eb19a50590f0fb3d46164962dc0368
6
+ metadata.gz: e80f26545cd13b3e3bab7624d140cf2844afdf3471a45a8b77102fdaf2ca633e4a80df7a315718f3b35a8e3b95b9706a1e03785a19afef1bb5cf47dcf22a9d0d
7
+ data.tar.gz: 4ccdbce4a6e6e854137a938ec3e26361952f355b0cffd3776e646109cff971e0514dd5e222add212be371771e85bd75df5c6a3852800d7b12a07c5a2112a45aa
data/isodoc.gemspec CHANGED
@@ -31,9 +31,10 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "asciimath"
32
32
  spec.add_dependency "html2doc", "~> 1.3.0"
33
33
  spec.add_dependency "htmlentities", "~> 4.3.4"
34
+ spec.add_dependency "isodoc-i18n", "~> 1.0.0"
34
35
  spec.add_dependency "liquid", "~> 4"
35
36
  # spec.add_dependency "metanorma", ">= 1.2.0"
36
- spec.add_dependency "emf2svg", "~> 1"
37
+ spec.add_dependency "emf2svg", "<= 1.3"
37
38
  spec.add_dependency "mathml2asciimath"
38
39
  spec.add_dependency "metanorma-utils"
39
40
  spec.add_dependency "nokogiri", "~> 1.12.0"
@@ -32,7 +32,7 @@ module IsoDoc
32
32
  def init_dir(filename, debug)
33
33
  dir = "#{filename}#{@tmpfilesdir_suffix}"
34
34
  unless debug
35
- Dir.mkdir(dir, 0o777) unless File.exists?(dir)
35
+ Dir.mkdir(dir, 0o777) unless File.exist?(dir)
36
36
  FileUtils.rm_rf "#{dir}/*"
37
37
  end
38
38
  dir
@@ -24,7 +24,7 @@ module IsoDoc
24
24
 
25
25
  def convert(filename, file = nil, debug = false, output_filename = nil)
26
26
  ret = super
27
- Dir.exists?(tmpimagedir) and Dir["#{tmpimagedir}/*"].empty? and
27
+ Dir.exist?(tmpimagedir) and Dir["#{tmpimagedir}/*"].empty? and
28
28
  FileUtils.rm_r tmpimagedir
29
29
  ret
30
30
  end
data/lib/isodoc/i18n.rb CHANGED
@@ -1,28 +1,9 @@
1
1
  require "yaml"
2
+ require "isodoc-i18n"
2
3
  require_relative "function/utils"
3
4
 
4
5
  module IsoDoc
5
6
  class I18n
6
- def load_yaml(lang, script, i18nyaml = nil)
7
- ret = load_yaml1(lang, script)
8
- return normalise_hash(ret.merge(YAML.load_file(i18nyaml))) if i18nyaml
9
-
10
- normalise_hash(ret)
11
- end
12
-
13
- def normalise_hash(ret)
14
- case ret
15
- when Hash
16
- ret.each do |k, v|
17
- ret[k] = normalise_hash(v)
18
- end
19
- ret
20
- when Array then ret.map { |n| normalise_hash(n) }
21
- when String then cleanup_entities(ret.unicode_normalize(:nfc))
22
- else ret
23
- end
24
- end
25
-
26
7
  def load_yaml1(lang, script)
27
8
  case lang
28
9
  when "en", "fr", "ru", "de", "es", "ar"
@@ -40,93 +21,5 @@ module IsoDoc
40
21
  YAML.load_file(File.join(File.dirname(__FILE__),
41
22
  "../isodoc-yaml/i18n-#{str}.yaml"))
42
23
  end
43
-
44
- def get
45
- @labels
46
- end
47
-
48
- def set(key, val)
49
- @labels[key] = val
50
- end
51
-
52
- def initialize(lang, script, i18nyaml = nil)
53
- @lang = lang
54
- @script = script
55
- y = load_yaml(lang, script, i18nyaml)
56
- @labels = y
57
- @labels["language"] = @lang
58
- @labels["script"] = @script
59
- @labels.each do |k, _v|
60
- self.class.send(:define_method, k.downcase) { get[k] }
61
- end
62
- end
63
-
64
- def self.l10n(text, lang = @lang, script = @script)
65
- l10n(text, lang, script)
66
- end
67
-
68
- # TODO: move to localization file
69
- # function localising spaces and punctuation.
70
- # Not clear if period needs to be localised for zh
71
- def l10n(text, lang = @lang, script = @script)
72
- if lang == "zh" && script == "Hans" then l10n_zh(text)
73
- else bidiwrap(text, lang, script)
74
- end
75
- end
76
-
77
- def bidiwrap(text, lang, script)
78
- my_script, my_rtl, outer_rtl = bidiwrap_vars(lang, script)
79
- if my_rtl && !outer_rtl
80
- mark = %w(Arab Aran).include?(my_script) ? "&#x61c;" : "&#x200f;"
81
- "#{mark}#{text}#{mark}"
82
- elsif !my_rtl && outer_rtl then "&#x200e;#{text}&#x200e;"
83
- else text
84
- end
85
- end
86
-
87
- def bidiwrap_vars(lang, script)
88
- my_script = script || Metanorma::Utils.default_script(lang)
89
- [my_script,
90
- Metanorma::Utils.rtl_script?(my_script),
91
- Metanorma::Utils.rtl_script?(@script || Metanorma::Utils
92
- .default_script(@lang))]
93
- end
94
-
95
- def l10n_zh(text)
96
- xml = Nokogiri::HTML::DocumentFragment.parse(text)
97
- xml.traverse do |n|
98
- next unless n.text?
99
-
100
- n.replace(cleanup_entities(n.text.gsub(/ /, "").gsub(/:/, ":")
101
- .gsub(/,/, "、").gsub(/\(/, "(").gsub(/\)/, ")")
102
- .gsub(/\[/, "【").gsub(/\]/, "】"), is_xml: false))
103
- end
104
- xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "")
105
- end
106
-
107
- def boolean_conj(list, conn)
108
- case list.size
109
- when 0 then ""
110
- when 1 then list.first
111
- when 2 then @labels["binary_#{conn}"].sub(/%1/, list[0])
112
- .sub(/%2/, list[1])
113
- else
114
- @labels["multiple_#{conn}"]
115
- .sub(/%1/, l10n(list[0..-2].join(", "), @lang, @script))
116
- .sub(/%2/, list[-1])
117
- end
118
- end
119
-
120
- # def multiple_and(names, andword)
121
- # return "" if names.empty?
122
- # return names[0] if names.length == 1
123
- #
124
- # (names.length == 2) &&
125
- # (return l10n("#{names[0]} #{andword} #{names[1]}", @lang, @script))
126
- # l10n(names[0..-2].join(", ") + " #{andword} #{names[-1]}", @lang, @script)
127
- # end
128
-
129
- include Function::Utils
130
- # module_function :l10n
131
24
  end
132
25
  end
@@ -29,8 +29,7 @@ module IsoDoc
29
29
  def figure1(elem)
30
30
  return sourcecode1(elem) if elem["class"] == "pseudocode" ||
31
31
  elem["type"] == "pseudocode"
32
- return if (labelled_ancestor(elem) && elem.ancestors("figure").empty?) ||
33
- (elem.at(ns("./figure")) && !elem.at(ns("./name")))
32
+ return if elem.at(ns("./figure")) && !elem.at(ns("./name"))
34
33
 
35
34
  lbl = @xrefs.anchor(elem["id"], :label, false) or return
36
35
  prefix_name(elem, "&nbsp;&mdash; ",
@@ -64,7 +63,7 @@ module IsoDoc
64
63
  def svg_to_emf(node)
65
64
  uri = svg_to_emf_uri(node)
66
65
  ret = svg_to_emf_filename(uri)
67
- File.exists?(ret) and return ret
66
+ File.exist?(ret) and return ret
68
67
  exe = inkscape_installed? or raise "Inkscape missing in PATH, unable" \
69
68
  "to convert EMF to SVG. Aborting."
70
69
  uri = Metanorma::Utils::external_path uri
@@ -76,16 +76,25 @@ module IsoDoc
76
76
  def bibliography_bibitem_number(docxml)
77
77
  i = 0
78
78
  docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
79
- next if bibliography_bibitem_number_skip(b)
80
-
81
- i += 1
82
- id = b.at(ns(".//docidentifier"))
83
- id.previous =
84
- "<docidentifier type='metanorma-ordinal'>[#{i}]</docidentifier>"
79
+ i = bibliography_bibitem_number1(b, i)
85
80
  end
86
81
  @xrefs.references docxml
87
82
  end
88
83
 
84
+ def bibliography_bibitem_number1(bibitem, idx)
85
+ if mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']"))
86
+ /^\[?\d\]?$/.match?(mn&.text) and
87
+ idx = mn.text.sub(/^\[/, "").sub(/\]$/, "").to_i
88
+ end
89
+ unless bibliography_bibitem_number_skip(bibitem)
90
+
91
+ idx += 1
92
+ bibitem.at(ns(".//docidentifier")).previous =
93
+ "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
94
+ end
95
+ idx
96
+ end
97
+
89
98
  def docid_prefixes(docxml)
90
99
  docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
91
100
  i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.0.6".freeze
2
+ VERSION = "2.0.8".freeze
3
3
  end
@@ -206,7 +206,7 @@ module IsoDoc
206
206
 
207
207
  out.p { |p| p << @i18n.where }
208
208
  parse(deflist, out)
209
- out.parent.at("./table")["class"] = "formula_dl"
209
+ t = out.parent.at("./table") and t["class"] = "formula_dl"
210
210
  end
211
211
 
212
212
  def formula_parse1(node, out)
@@ -25,7 +25,7 @@ module IsoDoc
25
25
  j = 0
26
26
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
27
27
  .each do |t|
28
- next if labelled_ancestor(t) && t.ancestors("figure").empty?
28
+ # next if labelled_ancestor(t) && t.ancestors("figure").empty?
29
29
 
30
30
  j = subfigure_increment(j, c, t)
31
31
  label = c.print + (j.zero? ? "" : "-#{j}")
@@ -111,7 +111,7 @@ module IsoDoc
111
111
  j = 0
112
112
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
113
113
  .each do |t|
114
- next if labelled_ancestor(t) && t.ancestors("figure").empty?
114
+ # next if labelled_ancestor(t) && t.ancestors("figure").empty?
115
115
 
116
116
  j = subfigure_increment(j, c, t)
117
117
  label = "#{num}#{hiersep}#{c.print}" +
@@ -34,9 +34,9 @@ internal_external_terms_boilerplate: |
34
34
  <p>% 界定的以及下列术语和定义适用于本文件。</p>
35
35
  term_defined_in: "〖术语于%中定义〗"
36
36
  binary_and: "%1和%2"
37
- multiple_and: "%1和%2"
37
+ multiple_and: "%1、和%2"
38
38
  binary_or: "%1或%2"
39
- multiple_or: "%1或%2"
39
+ multiple_or: "%1、或%2"
40
40
  chain_and: "%1和%2"
41
41
  chain_or: "%1或%2"
42
42
  chain_from: "%1从%2"
@@ -644,7 +644,7 @@ RSpec.describe IsoDoc do
644
644
  </introduction></preface><sections>
645
645
  <clause id="D" obligation="normative" type="scope" displayorder="3">
646
646
  <title depth="1">1.<tab/>Scope</title>
647
- <p id="E"><eref type="inline" bibitemid="ISO712"><locality type="table"><referenceFrom>1</referenceFrom><referenceTo>1</referenceTo></locality>ISO 712&#x3001;&#x7B2C;1&#x2013;1&#x8868;</eref></p>
647
+ <p id="E"><eref type="inline" bibitemid="ISO712"><locality type="table"><referenceFrom>1</referenceFrom><referenceTo>1</referenceTo></locality>ISO 712, &#x7B2C;1&#x2013;1 &#x8868;</eref></p>
648
648
  </clause>
649
649
  <clause id="H" obligation="normative" displayorder="5"><title depth="1">3.<tab/>Terms, definitions, symbols and abbreviated terms</title><terms id="I" obligation="normative">
650
650
  <title depth="2">3.1.<tab/>Normal Terms</title>
@@ -722,7 +722,7 @@ RSpec.describe IsoDoc do
722
722
  <div id="D">
723
723
  <h1>1.&#12288;Scope</h1>
724
724
  <p id="E">
725
- <a href='#ISO712'>ISO 712&#12289;&#31532;1&#8211;1&#34920;</a>
725
+ <a href='#ISO712'>ISO 712, &#31532;1&#8211;1 &#34920;</a>
726
726
  </p>
727
727
  </div>
728
728
  <div>
@@ -1158,7 +1158,6 @@ RSpec.describe IsoDoc do
1158
1158
  .to be_equivalent_to xmlpp(presxml)
1159
1159
  end
1160
1160
 
1161
-
1162
1161
  it "inserts toc metadata" do
1163
1162
  input = <<~INPUT
1164
1163
  <iso-standard xmlns="http://riboseinc.com/isoxml">
@@ -1194,7 +1193,7 @@ RSpec.describe IsoDoc do
1194
1193
  end
1195
1194
 
1196
1195
  it "processes multiple-target xrefs" do
1197
- input = <<~INPUT
1196
+ input = <<~INPUT
1198
1197
  <iso-standard xmlns="http://riboseinc.com/isoxml">
1199
1198
  <bibdata/>
1200
1199
  <sections>
@@ -1295,6 +1294,72 @@ RSpec.describe IsoDoc do
1295
1294
  .to be_equivalent_to xmlpp(presxml)
1296
1295
  end
1297
1296
 
1297
+ it "captions embedded figures" do
1298
+ input = <<~INPUT
1299
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
1300
+ <bibdata/>
1301
+ <sections>
1302
+ <clause id="A" inline-header="false" obligation="normative">
1303
+ <title>Section</title>
1304
+ <figure id="B1">
1305
+ <name>First</name>
1306
+ </figure>
1307
+ <example id="C1">
1308
+ <figure id="B2">
1309
+ <name>Second</name>
1310
+ </figure>
1311
+ </example>
1312
+ <example id="C2">
1313
+ <figure id="B4" unnumbered="true">
1314
+ <name>Unnamed</name>
1315
+ </figure>
1316
+ </example>
1317
+ <figure id="B3">
1318
+ <name>Third</name>
1319
+ </figure>
1320
+ </clause>
1321
+ </sections>
1322
+ </iso-standard>
1323
+ INPUT
1324
+ presxml = <<~OUTPUT
1325
+ <iso-standard xmlns='http://riboseinc.com/isoxml' type='presentation'>
1326
+ <bibdata/>
1327
+
1328
+ <sections>
1329
+ <clause id='A' inline-header='false' obligation='normative' displayorder='1'>
1330
+ <title depth='1'>
1331
+ 1.
1332
+ <tab/>
1333
+ Section
1334
+ </title>
1335
+ <figure id='B1'>
1336
+ <name>Figure 1&#xA0;&#x2014; First</name>
1337
+ </figure>
1338
+ <example id='C1'>
1339
+ <name>EXAMPLE 1</name>
1340
+ <figure id='B2'>
1341
+ <name>Figure 2&#xA0;&#x2014; Second</name>
1342
+ </figure>
1343
+ </example>
1344
+ <example id='C2'>
1345
+ <name>EXAMPLE 2</name>
1346
+ <figure id='B4' unnumbered='true'>
1347
+ <name>Unnamed</name>
1348
+ </figure>
1349
+ </example>
1350
+ <figure id='B3'>
1351
+ <name>Figure 3&#xA0;&#x2014; Third</name>
1352
+ </figure>
1353
+ </clause>
1354
+ </sections>
1355
+ </iso-standard>
1356
+ OUTPUT
1357
+ expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
1358
+ .convert("test", input, true))
1359
+ .sub(%r{<localized-strings>.*</localized-strings>}m, ""))
1360
+ .to be_equivalent_to xmlpp(presxml)
1361
+ end
1362
+
1298
1363
  private
1299
1364
 
1300
1365
  def mock_symbols
@@ -854,4 +854,52 @@ RSpec.describe IsoDoc do
854
854
  .to be_equivalent_to xmlpp(presxml)
855
855
  end
856
856
 
857
+ it "enforces consistent metanorma-ordinal numbering" do
858
+ input = <<~INPUT
859
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
860
+ <bibdata>
861
+ <language>en</language>
862
+ </bibdata>
863
+ <bibliography><references id="_normative_references" obligation="informative" normative="false"><title>Bibliography</title>
864
+ <bibitem id="ref1" type="standard">
865
+ <title format="text/plain">Cereals or cereal products</title>
866
+ <docidentifier type="IEC">IEC 217</docidentifier>
867
+ </bibitem>
868
+ <bibitem id="ref2" type="standard">
869
+ <title format="text/plain">Cereals or cereal products</title>
870
+ <docidentifier type="metanorma">[3]</docidentifier>
871
+ </bibitem>
872
+ <bibitem id="ref3" type="standard">
873
+ <title format="text/plain">Cereals or cereal products</title>
874
+ <docidentifier>ABC</docidentifier>
875
+ </bibitem>
876
+ </references></bibliography></iso-standard>
877
+ INPUT
878
+ presxml = <<~PRESXML
879
+ <bibliography>
880
+ <references id='_normative_references' obligation='informative' normative='false' displayorder='1'>
881
+ <title depth='1'>Bibliography</title>
882
+ <bibitem id='ref1' type='standard'>
883
+ <title format='text/plain'>Cereals or cereal products</title>
884
+ <docidentifier type='metanorma-ordinal'>[1]</docidentifier>
885
+ <docidentifier type='IEC'>IEC 217</docidentifier>
886
+ </bibitem>
887
+ <bibitem id='ref2' type='standard'>
888
+ <title format='text/plain'>Cereals or cereal products</title>
889
+ <docidentifier type='metanorma'>[3]</docidentifier>
890
+ </bibitem>
891
+ <bibitem id='ref3' type='standard'>
892
+ <title format='text/plain'>Cereals or cereal products</title>
893
+ <docidentifier type='metanorma-ordinal'>[4]</docidentifier>
894
+ <docidentifier>ABC</docidentifier>
895
+ </bibitem>
896
+ </references>
897
+ </bibliography>
898
+ PRESXML
899
+ expect(xmlpp(Nokogiri::XML(
900
+ IsoDoc::PresentationXMLConvert.new({})
901
+ .convert("test", input, true),
902
+ ).at("//xmlns:bibliography").to_xml))
903
+ .to be_equivalent_to xmlpp(presxml)
904
+ end
857
905
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.8
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-03-21 00:00:00.000000000 Z
11
+ date: 2022-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 4.3.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: isodoc-i18n
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: liquid
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +84,16 @@ dependencies:
70
84
  name: emf2svg
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - "<="
74
88
  - !ruby/object:Gem::Version
75
- version: '1'
89
+ version: '1.3'
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - "<="
81
95
  - !ruby/object:Gem::Version
82
- version: '1'
96
+ version: '1.3'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: mathml2asciimath
85
99
  requirement: !ruby/object:Gem::Requirement