metanorma-un 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor/un/converter.rb +43 -26
- data/lib/asciidoctor/un/isodoc.rng +12 -6
- data/lib/asciidoctor/un/validate.rb +2 -1
- data/lib/isodoc/un/base_convert.rb +3 -58
- data/lib/isodoc/un/html_convert.rb +9 -21
- data/lib/isodoc/un/i18n-en.yaml +2 -0
- data/lib/isodoc/un/i18n.rb +11 -0
- data/lib/isodoc/un/init.rb +29 -0
- data/lib/isodoc/un/metadata.rb +23 -12
- data/lib/isodoc/un/presentation_xml_convert.rb +44 -1
- data/lib/isodoc/un/un.plenary-attachment.xsl +1186 -1854
- data/lib/isodoc/un/un.plenary.xsl +1186 -1854
- data/lib/isodoc/un/un.recommendation.xsl +1271 -11416
- data/lib/isodoc/un/word_convert.rb +17 -23
- data/lib/isodoc/un/xref.rb +7 -8
- data/lib/metanorma/un/version.rb +1 -1
- data/metanorma-unece.gemspec +2 -4
- metadata +9 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84ac6004180fc5b55f02c08ce72d19b4b2e0de5f5b406f4c6796fe5595edeee6
|
4
|
+
data.tar.gz: 0d742071c23c5455cca3ddcd9a13dcdcf45ad781478dfad4a4297510697e5f70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d3b23e08336a19b8000792d0facbb9e7311f77ef014e5931503027b5dd9e54fa84e6135c4e38535a8bc0a75d476f5b8ac95443cda73b1e9c4cb19a3d5b3571
|
7
|
+
data.tar.gz: 88d72ed256d4c45d0c1873c42423fcc6449a99b0a3efa8d842f9d33fcf63dc823a102fac228b4c3fb9a82f737e20cd3befeb6a43e59c7b13884a4c7f301216b6
|
@@ -5,10 +5,6 @@ require_relative "validate"
|
|
5
5
|
|
6
6
|
module Asciidoctor
|
7
7
|
module UN
|
8
|
-
|
9
|
-
# A {Converter} implementation that generates RSD output, and a document
|
10
|
-
# schema encapsulation of the document for validation
|
11
|
-
#
|
12
8
|
class Converter < Standoc::Converter
|
13
9
|
XML_ROOT_TAG = "un-standard".freeze
|
14
10
|
XML_NAMESPACE = "https://www.metanorma.org/ns/un".freeze
|
@@ -49,14 +45,20 @@ module Asciidoctor
|
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
48
|
+
def asciidoc_sub(text)
|
49
|
+
Asciidoctor::Standoc::Utils::asciidoc_sub(text)
|
50
|
+
end
|
51
|
+
|
52
52
|
def title(node, xml)
|
53
53
|
["en"].each do |lang|
|
54
|
-
xml.title **{ type: "main", language: lang,
|
55
|
-
|
54
|
+
xml.title **{ type: "main", language: lang,
|
55
|
+
format: "text/plain" } do |t|
|
56
|
+
t << (asciidoc_sub(node.attr("title")) || node.title)
|
56
57
|
end
|
57
58
|
node.attr("subtitle") and
|
58
|
-
xml.title **{ type: "subtitle", language: lang,
|
59
|
-
|
59
|
+
xml.title **{ type: "subtitle", language: lang,
|
60
|
+
format: "text/plain" } do |t|
|
61
|
+
t << asciidoc_sub(node.attr("subtitle"))
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -64,7 +66,8 @@ module Asciidoctor
|
|
64
66
|
def metadata_id(node, xml)
|
65
67
|
dn = node.attr("docnumber")
|
66
68
|
if docstatus = node.attr("status")
|
67
|
-
abbr = IsoDoc::UN::Metadata.new("en", "Latn",
|
69
|
+
abbr = IsoDoc::UN::Metadata.new("en", "Latn", @i18n)
|
70
|
+
.stage_abbr(docstatus)
|
68
71
|
dn = "#{dn}(#{abbr})" unless abbr.empty?
|
69
72
|
end
|
70
73
|
xml.docidentifier { |i| i << dn }
|
@@ -92,17 +95,26 @@ module Asciidoctor
|
|
92
95
|
xml.session do |session|
|
93
96
|
session.number node.attr("session") if node.attr("session")
|
94
97
|
session.date node.attr("session-date") if node.attr("session-date")
|
95
|
-
node&.attr("item-number")&.split(/,[ ]*/)&.each
|
96
|
-
|
97
|
-
|
98
|
-
|
98
|
+
node&.attr("item-number")&.split(/,[ ]*/)&.each do |i|
|
99
|
+
session.item_number i
|
100
|
+
end
|
101
|
+
node&.attr("item-name")&.split(/,[ ]*/)&.each do |i|
|
102
|
+
session.item_name i
|
103
|
+
end
|
104
|
+
node&.attr("subitem-name")&.split(/,[ ]*/)&.each do |i|
|
105
|
+
session.subitem_name i
|
106
|
+
end
|
107
|
+
node.attr("collaborator") and
|
108
|
+
session.collaborator node.attr("collaborator")
|
99
109
|
session.id node.attr("agenda-id") if node.attr("agenda-id")
|
100
|
-
|
110
|
+
node.attr("item-footnote") and
|
111
|
+
session.item_footnote node.attr("item-footnote")
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
104
115
|
def metadata_language(node, xml)
|
105
|
-
languages = node&.attr("language")&.split(/,[ ]*/) ||
|
116
|
+
languages = node&.attr("language")&.split(/,[ ]*/) ||
|
117
|
+
%w(ar ru en fr zh es)
|
106
118
|
languages.each { |l| xml.language l }
|
107
119
|
end
|
108
120
|
|
@@ -124,15 +136,19 @@ module Asciidoctor
|
|
124
136
|
|
125
137
|
def makexml(node)
|
126
138
|
@draft = node.attributes.has_key?("draft")
|
127
|
-
@no_number_subheadings =
|
139
|
+
@no_number_subheadings =
|
140
|
+
node.attributes.has_key?("do-not-number-subheadings")
|
128
141
|
super
|
129
142
|
end
|
130
143
|
|
131
144
|
def doctype(node)
|
132
145
|
d = node.attr("doctype")
|
133
|
-
unless %w{plenary recommendation addendum communication corrigendum
|
134
|
-
agenda budgetary sec-gen-notes expert-report resolution
|
135
|
-
|
146
|
+
unless %w{plenary recommendation addendum communication corrigendum
|
147
|
+
reissue agenda budgetary sec-gen-notes expert-report resolution
|
148
|
+
plenary-attachment}.include? d
|
149
|
+
@log.add(
|
150
|
+
"Document Attributes", nil,
|
151
|
+
"#{d} is not a legal document type: reverting to 'recommendation'")
|
136
152
|
d = "recommendation"
|
137
153
|
end
|
138
154
|
d
|
@@ -141,9 +157,12 @@ module Asciidoctor
|
|
141
157
|
def outputs(node, ret)
|
142
158
|
File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
|
143
159
|
presentation_xml_converter(node).convert(@filename + ".xml")
|
144
|
-
html_converter(node).convert(@filename + ".presentation.xml",
|
145
|
-
|
146
|
-
|
160
|
+
html_converter(node).convert(@filename + ".presentation.xml",
|
161
|
+
nil, false, "#{@filename}.html")
|
162
|
+
doc_converter(node).convert(@filename + ".presentation.xml",
|
163
|
+
nil, false, "#{@filename}.doc")
|
164
|
+
pdf_converter(node)&.convert(@filename + ".presentation.xml",
|
165
|
+
nil, false, "#{@filename}.pdf")
|
147
166
|
end
|
148
167
|
|
149
168
|
def validate(doc)
|
@@ -217,10 +236,8 @@ module Asciidoctor
|
|
217
236
|
end
|
218
237
|
|
219
238
|
def admonition_attrs(node)
|
220
|
-
attr_code(super.merge(
|
221
|
-
"
|
222
|
-
"subsequence": node.attr("subsequence"),
|
223
|
-
))
|
239
|
+
attr_code(super.merge("unnumbered": node.option?("unnumbered"),
|
240
|
+
"subsequence": node.attr("subsequence")))
|
224
241
|
end
|
225
242
|
|
226
243
|
def sectiontype_streamline(ret)
|
@@ -922,6 +922,9 @@
|
|
922
922
|
<optional>
|
923
923
|
<attribute name="script"/>
|
924
924
|
</optional>
|
925
|
+
<optional>
|
926
|
+
<attribute name="type"/>
|
927
|
+
</optional>
|
925
928
|
<optional>
|
926
929
|
<attribute name="obligation">
|
927
930
|
<choice>
|
@@ -961,9 +964,6 @@
|
|
961
964
|
</define>
|
962
965
|
<define name="content-subsection">
|
963
966
|
<element name="clause">
|
964
|
-
<optional>
|
965
|
-
<attribute name="type"/>
|
966
|
-
</optional>
|
967
967
|
<ref name="Content-Section"/>
|
968
968
|
</element>
|
969
969
|
</define>
|
@@ -992,6 +992,9 @@
|
|
992
992
|
</choice>
|
993
993
|
</attribute>
|
994
994
|
</optional>
|
995
|
+
<optional>
|
996
|
+
<attribute name="type"/>
|
997
|
+
</optional>
|
995
998
|
<optional>
|
996
999
|
<ref name="section-title"/>
|
997
1000
|
</optional>
|
@@ -1011,9 +1014,6 @@
|
|
1011
1014
|
</define>
|
1012
1015
|
<define name="clause">
|
1013
1016
|
<element name="clause">
|
1014
|
-
<optional>
|
1015
|
-
<attribute name="type"/>
|
1016
|
-
</optional>
|
1017
1017
|
<ref name="Clause-Section"/>
|
1018
1018
|
</element>
|
1019
1019
|
</define>
|
@@ -1042,6 +1042,9 @@
|
|
1042
1042
|
</choice>
|
1043
1043
|
</attribute>
|
1044
1044
|
</optional>
|
1045
|
+
<optional>
|
1046
|
+
<attribute name="type"/>
|
1047
|
+
</optional>
|
1045
1048
|
<optional>
|
1046
1049
|
<ref name="section-title"/>
|
1047
1050
|
</optional>
|
@@ -1180,6 +1183,9 @@
|
|
1180
1183
|
<optional>
|
1181
1184
|
<attribute name="script"/>
|
1182
1185
|
</optional>
|
1186
|
+
<optional>
|
1187
|
+
<attribute name="type"/>
|
1188
|
+
</optional>
|
1183
1189
|
<optional>
|
1184
1190
|
<attribute name="obligation">
|
1185
1191
|
<choice>
|
@@ -14,7 +14,8 @@ module Asciidoctor
|
|
14
14
|
stage = xmldoc&.at("//bibdata/status/stage")&.text
|
15
15
|
%w(proposal working-draft committee-draft draft-standard final-draft
|
16
16
|
published withdrawn).include? stage or
|
17
|
-
@log.add("Document Attributes", nil,
|
17
|
+
@log.add("Document Attributes", nil,
|
18
|
+
"#{stage} is not a recognised status")
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -1,52 +1,12 @@
|
|
1
|
-
require_relative "metadata"
|
2
|
-
require_relative "xref"
|
3
1
|
require "fileutils"
|
4
2
|
|
5
3
|
module IsoDoc
|
6
4
|
module UN
|
7
5
|
module BaseConvert
|
8
|
-
def metadata_init(lang, script, labels)
|
9
|
-
@meta = Metadata.new(lang, script, labels)
|
10
|
-
@meta.set(:toc, @toc)
|
11
|
-
end
|
12
|
-
|
13
|
-
def xref_init(lang, script, klass, labels, options)
|
14
|
-
@xrefs = Xref.new(lang, script, klass, labels, options)
|
15
|
-
end
|
16
|
-
|
17
|
-
def annex_name(annex, name, div)
|
18
|
-
div.h1 **{ class: "Annex" } do |t|
|
19
|
-
t << "#{@xrefs.anchor(annex['id'], :label)}"
|
20
|
-
t.br
|
21
|
-
t.b do |b|
|
22
|
-
name&.children&.each { |c2| parse(c2, b) }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def i18n_init(lang, script)
|
28
|
-
super
|
29
|
-
@admonition_lbl = "Box"
|
30
|
-
@abstract_lbl = "Summary"
|
31
|
-
end
|
32
|
-
|
33
|
-
def fileloc(loc)
|
34
|
-
File.join(File.dirname(__FILE__), loc)
|
35
|
-
end
|
36
|
-
|
37
6
|
def middle_clause
|
38
7
|
"//clause[parent::sections]"
|
39
8
|
end
|
40
9
|
|
41
|
-
def admonition_name_parse(node, div, name)
|
42
|
-
div.p **{ class: "AdmonitionTitle", style: "text-align:center;" } do |p|
|
43
|
-
lbl = @xrefs.anchor(node['id'], :label)
|
44
|
-
lbl.nil? or p << l10n("#{@admonition_lbl} #{lbl}")
|
45
|
-
name and !lbl.nil? and p << " — "
|
46
|
-
name and name.children.each { |n| parse(n, div) }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
10
|
def admonition_parse(node, out)
|
51
11
|
name = node.at(ns("./name"))
|
52
12
|
out.div **admonition_attrs(node) do |t|
|
@@ -57,13 +17,10 @@ def xref_init(lang, script, klass, labels, options)
|
|
57
17
|
end
|
58
18
|
end
|
59
19
|
|
60
|
-
def inline_header_title(out, node,
|
20
|
+
def inline_header_title(out, node, title)
|
61
21
|
out.span **{ class: "zzMoveToFollowing" } do |s|
|
62
|
-
|
63
|
-
|
64
|
-
insert_tab(s, 1)
|
65
|
-
end
|
66
|
-
c1&.children&.each { |c2| parse(c2, s) }
|
22
|
+
title&.children&.each { |c2| parse(c2, s) }
|
23
|
+
clausedelimspace(out) if /\S/.match(title&.text)
|
67
24
|
end
|
68
25
|
end
|
69
26
|
|
@@ -73,18 +30,6 @@ def xref_init(lang, script, klass, labels, options)
|
|
73
30
|
return true if docxml&.at(ns("//bibdata/ext/session/*"))
|
74
31
|
false
|
75
32
|
end
|
76
|
-
|
77
|
-
def note_label(node)
|
78
|
-
n = @xrefs.get[node["id"]]
|
79
|
-
lbl = case node["type"]
|
80
|
-
when "source" then "Source"
|
81
|
-
when "abbreviation" then "Abbreviations"
|
82
|
-
else
|
83
|
-
@note_lbl
|
84
|
-
end
|
85
|
-
return "#{lbl}:" # if n.nil? || n[:label].nil? || n[:label].empty?
|
86
|
-
#l10n("#{lbl} #{n[:label]}:")
|
87
|
-
end
|
88
33
|
end
|
89
34
|
end
|
90
35
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "base_convert"
|
2
|
+
require_relative "init"
|
2
3
|
require "isodoc"
|
3
4
|
|
4
5
|
module IsoDoc
|
@@ -48,8 +49,10 @@ module IsoDoc
|
|
48
49
|
|
49
50
|
def make_body(xml, docxml)
|
50
51
|
plenary = is_plenary?(docxml)
|
51
|
-
body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72",
|
52
|
-
|
52
|
+
body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72",
|
53
|
+
"xml:lang": "EN-US", class: "container" }
|
54
|
+
if plenary &&
|
55
|
+
@htmlcoverpage == html_doc_path("html_unece_titlepage.html")
|
53
56
|
@htmlcoverpage = html_doc_path("html_unece_plenary_titlepage.html")
|
54
57
|
end
|
55
58
|
xml.body **body_attr do |body|
|
@@ -80,26 +83,11 @@ module IsoDoc
|
|
80
83
|
bibliography isoxml, out
|
81
84
|
end
|
82
85
|
|
83
|
-
def clause_parse_title(node, div, c1, out)
|
84
|
-
if node["inline-header"] == "true"
|
85
|
-
inline_header_title(out, node, c1)
|
86
|
-
else
|
87
|
-
div.send "h#{@xrefs.anchor(node['id'], :level, false) || '1'}" do |h|
|
88
|
-
lbl = @xrefs.anchor(node['id'], :label, false)
|
89
|
-
h << "#{lbl}. " if lbl && !@suppressheadingnumbers
|
90
|
-
insert_tab(h, 1) if lbl && !@suppressheadingnumbers
|
91
|
-
c1&.children&.each { |c2| parse(c2, h) }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
86
|
def introduction(isoxml, out)
|
97
87
|
f = isoxml.at(ns("//introduction")) || return
|
98
88
|
page_break(out)
|
99
89
|
out.div **{ class: "Section3", id: f["id"] } do |div|
|
100
|
-
|
101
|
-
h1 << @introduction_lbl
|
102
|
-
end
|
90
|
+
clause_name(nil, f.at(ns("./title")), div, { class: "IntroTitle" })
|
103
91
|
f.elements.each do |e|
|
104
92
|
parse(e, div) unless e.name == "title"
|
105
93
|
end
|
@@ -110,14 +98,14 @@ module IsoDoc
|
|
110
98
|
f = isoxml.at(ns("//foreword")) || return
|
111
99
|
page_break(out)
|
112
100
|
out.div **attr_code(id: f["id"]) do |s|
|
113
|
-
|
114
|
-
|
115
|
-
end
|
101
|
+
clause_name(nil, f.at(ns("./title")) || @i18n.foreword, s,
|
102
|
+
class: "ForewordTitle")
|
116
103
|
f.elements.each { |e| parse(e, s) unless e.name == "title" }
|
117
104
|
end
|
118
105
|
end
|
119
106
|
|
120
107
|
include BaseConvert
|
108
|
+
include Init
|
121
109
|
end
|
122
110
|
end
|
123
111
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "isodoc"
|
2
|
+
require_relative "metadata"
|
3
|
+
require_relative "xref"
|
4
|
+
require_relative "i18n"
|
5
|
+
|
6
|
+
module IsoDoc
|
7
|
+
module UN
|
8
|
+
module Init
|
9
|
+
def metadata_init(lang, script, labels)
|
10
|
+
@meta = Metadata.new(lang, script, labels)
|
11
|
+
@meta.set(:toc, @toc)
|
12
|
+
end
|
13
|
+
|
14
|
+
def xref_init(lang, script, klass, labels, options)
|
15
|
+
html = HtmlConvert.new(language: lang, script: script)
|
16
|
+
@xrefs = Xref.new(lang, script, html, labels, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def i18n_init(lang, script, i18nyaml = nil)
|
20
|
+
@i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fileloc(loc)
|
24
|
+
File.join(File.dirname(__FILE__), loc)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/isodoc/un/metadata.rb
CHANGED
@@ -13,12 +13,14 @@ module IsoDoc
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def title(isoxml, _out)
|
16
|
-
main = isoxml&.at(ns("//bibdata/title
|
16
|
+
main = isoxml&.at(ns("//bibdata/title"\
|
17
|
+
"[@language='en' and @type='main']"))&.text
|
17
18
|
set(:doctitle, main)
|
18
19
|
end
|
19
20
|
|
20
21
|
def subtitle(isoxml, _out)
|
21
|
-
main = isoxml&.at(ns("//bibdata/title
|
22
|
+
main = isoxml&.at(ns("//bibdata/title"\
|
23
|
+
"[@language='en' and @type='subtitle']"))&.text
|
22
24
|
set(:docsubtitle, main)
|
23
25
|
end
|
24
26
|
|
@@ -36,8 +38,10 @@ module IsoDoc
|
|
36
38
|
set(:tc, tc.text) if tc
|
37
39
|
set(:distribution, isoxml&.at(ns("//bibdata/ext/distribution"))&.text)
|
38
40
|
lgs = extract_languages(isoxml.xpath(ns("//bibdata/language")))
|
39
|
-
lgs
|
40
|
-
|
41
|
+
lgs.sort == %w(English French Arabic Chinese Russian Spanish).sort and
|
42
|
+
lgs = []
|
43
|
+
slgs = extract_languages(isoxml.xpath(ns("//bibdata/ext/"\
|
44
|
+
"submissionlanguage")))
|
41
45
|
lgs = [] if slgs.size == 1
|
42
46
|
set(:doclanguage, lgs) unless lgs.empty?
|
43
47
|
set(:submissionlanguage, slgs) unless slgs.empty?
|
@@ -52,25 +56,32 @@ module IsoDoc
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def session(isoxml, _out)
|
55
|
-
set(:session_number, isoxml&.at(ns("//bibdata/ext/session/number"))&.
|
56
|
-
localize&.
|
59
|
+
set(:session_number, isoxml&.at(ns("//bibdata/ext/session/number"))&.
|
60
|
+
text&.to_i&.localize&.
|
61
|
+
to_rbnf_s("SpelloutRules", "spellout-ordinal")&.capitalize)
|
57
62
|
set(:session_date, isoxml&.at(ns("//bibdata/ext/session/date"))&.text)
|
58
|
-
set(:session_collaborator,
|
63
|
+
set(:session_collaborator,
|
64
|
+
isoxml&.at(ns("//bibdata/ext/session/collaborator"))&.text)
|
59
65
|
sid = isoxml&.at(ns("//bibdata/ext/session/id"))&.text
|
60
66
|
set(:session_id, sid)
|
61
67
|
set(:session_id_head, sid&.sub(%r{/.*$}, ""))
|
62
68
|
set(:session_id_tail, sid&.sub(%r{^[^/]+}, ""))
|
63
|
-
set(:item_footnote,
|
64
|
-
|
65
|
-
set(:
|
66
|
-
|
69
|
+
set(:item_footnote,
|
70
|
+
isoxml&.at(ns("//bibdata/ext/session/item-footnote"))&.text)
|
71
|
+
set(:session_itemnumber,
|
72
|
+
multival(isoxml, "//bibdata/ext/session/item-number"))
|
73
|
+
set(:session_itemname,
|
74
|
+
multival(isoxml, "//bibdata/ext/session/item-name"))
|
75
|
+
set(:session_subitemname,
|
76
|
+
multival(isoxml, "//bibdata/ext/session/subitem-name"))
|
67
77
|
end
|
68
78
|
|
69
79
|
def docid(isoxml, _out)
|
70
80
|
dn = isoxml.at(ns("//bibdata/docidentifier"))&.text
|
71
81
|
set(:docnumber, dn)
|
72
82
|
type = isoxml&.at(ns("//bibdata/ext/doctype"))&.text
|
73
|
-
set(:formatted_docnumber, type == "recommendation" ?
|
83
|
+
set(:formatted_docnumber, type == "recommendation" ?
|
84
|
+
"UN/CEFACT Recommendation #{dn}" : dn)
|
74
85
|
end
|
75
86
|
|
76
87
|
def stage_abbr(status)
|