metanorma-standoc 1.3.13 → 1.3.14
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/macos.yml +5 -1
- data/.github/workflows/ubuntu.yml +5 -1
- data/.github/workflows/windows.yml +5 -1
- data/lib/asciidoctor/standoc/base.rb +1 -0
- data/lib/asciidoctor/standoc/basicdoc.rng +20 -6
- data/lib/asciidoctor/standoc/cleanup.rb +13 -110
- data/lib/asciidoctor/standoc/cleanup_block.rb +5 -108
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup_inline.rb +125 -0
- data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -73
- data/lib/asciidoctor/standoc/cleanup_section.rb +195 -0
- data/lib/asciidoctor/standoc/front.rb +1 -88
- data/lib/asciidoctor/standoc/front_contributor.rb +99 -0
- data/lib/asciidoctor/standoc/isodoc.rng +532 -18
- data/lib/asciidoctor/standoc/macros.rb +79 -45
- data/lib/asciidoctor/standoc/reqt.rb +3 -1
- data/lib/asciidoctor/standoc/reqt.rng +2 -2
- data/lib/asciidoctor/standoc/validate.rb +4 -4
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- data/spec/asciidoctor-standoc/base_spec.rb +2 -2
- data/spec/asciidoctor-standoc/blocks_spec.rb +10 -9
- data/spec/asciidoctor-standoc/cleanup_spec.rb +13 -11
- data/spec/asciidoctor-standoc/inline_spec.rb +1 -1
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +4 -2
- data/spec/asciidoctor-standoc/macros_spec.rb +140 -2
- data/spec/asciidoctor-standoc/refs_spec.rb +4 -0
- data/spec/asciidoctor-standoc/section_spec.rb +14 -14
- data/spec/asciidoctor-standoc/validate_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -1
- metadata +7 -4
@@ -0,0 +1,195 @@
|
|
1
|
+
require "date"
|
2
|
+
require "nokogiri"
|
3
|
+
require "htmlentities"
|
4
|
+
require "json"
|
5
|
+
require "pathname"
|
6
|
+
require "open-uri"
|
7
|
+
|
8
|
+
module Asciidoctor
|
9
|
+
module Standoc
|
10
|
+
module Cleanup
|
11
|
+
def make_preface(x, s)
|
12
|
+
if x.at("//foreword | //introduction")
|
13
|
+
preface = s.add_previous_sibling("<preface/>").first
|
14
|
+
foreword = x.at("//foreword")
|
15
|
+
preface.add_child foreword.remove if foreword
|
16
|
+
introduction = x.at("//introduction")
|
17
|
+
preface.add_child introduction.remove if introduction
|
18
|
+
end
|
19
|
+
make_abstract(x, s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_abstract(x, s)
|
23
|
+
if x.at("//abstract[not(ancestor::bibitem)]")
|
24
|
+
preface = s.at("//preface") || s.add_previous_sibling("<preface/>").first
|
25
|
+
abstract = x.at("//abstract[not(ancestor::bibitem)]").remove
|
26
|
+
preface.prepend_child abstract.remove
|
27
|
+
bibabstract = bibabstract_location(x)
|
28
|
+
dupabstract = abstract.dup
|
29
|
+
dupabstract.traverse { |n| n.remove_attribute("id") }
|
30
|
+
dupabstract.remove_attribute("language")
|
31
|
+
dupabstract.remove_attribute("script")
|
32
|
+
bibabstract.next = dupabstract
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def bibabstract_location(x)
|
37
|
+
bibabstract = x.at("//bibdata/script") || x.at("//bibdata/language") ||
|
38
|
+
x.at("//bibdata/contributor[not(following-sibling::contributor)]") ||
|
39
|
+
x.at("//bibdata/date[not(following-sibling::date)]") ||
|
40
|
+
x.at("//docnumber") ||
|
41
|
+
x.at("//bibdata/docidentifier[not(following-sibling::docidentifier)]") ||
|
42
|
+
x.at("//bibdata/uri[not(following-sibling::uri)]") ||
|
43
|
+
x.at("//bibdata/title[not(following-sibling::title)]")
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_bibliography(x, s)
|
47
|
+
if x.at("//sections/references")
|
48
|
+
biblio = s.add_next_sibling("<bibliography/>").first
|
49
|
+
x.xpath("//sections/references").each do |r|
|
50
|
+
biblio.add_child r.remove
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def sections_order_cleanup(x)
|
56
|
+
s = x.at("//sections")
|
57
|
+
make_preface(x, s)
|
58
|
+
make_bibliography(x, s)
|
59
|
+
x.xpath("//sections/annex").reverse_each { |r| s.next = r.remove }
|
60
|
+
end
|
61
|
+
|
62
|
+
def maxlevel(x)
|
63
|
+
max = 5
|
64
|
+
x.xpath("//clause[@level]").each do |c|
|
65
|
+
max = c["level"].to_i if max < c["level"].to_i
|
66
|
+
end
|
67
|
+
max
|
68
|
+
end
|
69
|
+
|
70
|
+
def sections_level_cleanup(x)
|
71
|
+
m = maxlevel(x)
|
72
|
+
return if m < 6
|
73
|
+
m.downto(6).each do |l|
|
74
|
+
x.xpath("//clause[@level = '#{l}']").each do |c|
|
75
|
+
c.delete("level")
|
76
|
+
c.previous_element << c.remove
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def sections_cleanup(x)
|
82
|
+
sections_order_cleanup(x)
|
83
|
+
sections_level_cleanup(x)
|
84
|
+
end
|
85
|
+
|
86
|
+
def obligations_cleanup(x)
|
87
|
+
obligations_cleanup_info(x)
|
88
|
+
obligations_cleanup_norm(x)
|
89
|
+
obligations_cleanup_inherit(x)
|
90
|
+
end
|
91
|
+
|
92
|
+
def obligations_cleanup_info(x)
|
93
|
+
(s = x.at("//foreword")) && s["obligation"] = "informative"
|
94
|
+
(s = x.at("//introduction")) && s["obligation"] = "informative"
|
95
|
+
x.xpath("//references").each { |r| r["obligation"] = "informative" }
|
96
|
+
end
|
97
|
+
|
98
|
+
def obligations_cleanup_norm(x)
|
99
|
+
(s = x.at("//clause[title = 'Scope']")) && s["obligation"] = "normative"
|
100
|
+
(s = x.at("//clause[title = 'Symbols and Abbreviated Terms']")) &&
|
101
|
+
s["obligation"] = "normative"
|
102
|
+
x.xpath("//terms").each { |r| r["obligation"] = "normative" }
|
103
|
+
x.xpath("//symbols-abbrevs").each { |r| r["obligation"] = "normative" }
|
104
|
+
end
|
105
|
+
|
106
|
+
def obligations_cleanup_inherit(x)
|
107
|
+
x.xpath("//annex | //clause").each do |r|
|
108
|
+
r["obligation"] = "normative" unless r["obligation"]
|
109
|
+
end
|
110
|
+
x.xpath(Utils::SUBCLAUSE_XPATH).each do |r|
|
111
|
+
r["obligation"] = r.at("./ancestor::*/@obligation").text
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def termdef_stem_cleanup(xmldoc)
|
116
|
+
xmldoc.xpath("//term/p/stem").each do |a|
|
117
|
+
if a.parent.elements.size == 1 # para contains just a stem expression
|
118
|
+
t = Nokogiri::XML::Element.new("admitted", xmldoc)
|
119
|
+
parent = a.parent
|
120
|
+
t.children = a.remove
|
121
|
+
parent.replace(t)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def termdomain_cleanup(xmldoc)
|
127
|
+
xmldoc.xpath("//p/domain").each do |a|
|
128
|
+
prev = a.parent.previous
|
129
|
+
prev.next = a.remove
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def termdomain1_cleanup(xmldoc)
|
134
|
+
xmldoc.xpath("//domain").each do |d|
|
135
|
+
defn = d.at("../definition") and
|
136
|
+
defn.previous = d.remove
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def termdefinition_cleanup(xmldoc)
|
141
|
+
xmldoc.xpath("//term").each do |d|
|
142
|
+
first_child = d.at("./p | ./figure | ./formula") || next
|
143
|
+
t = Nokogiri::XML::Element.new("definition", xmldoc)
|
144
|
+
first_child.replace(t)
|
145
|
+
t << first_child.remove
|
146
|
+
d.xpath("./p | ./figure | ./formula").each { |n| t << n.remove }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def termdef_unnest_cleanup(xmldoc)
|
151
|
+
# release termdef tags from surrounding paras
|
152
|
+
nodes = xmldoc.xpath("//p/admitted | //p/deprecates")
|
153
|
+
while !nodes.empty?
|
154
|
+
nodes[0].parent.replace(nodes[0].parent.children)
|
155
|
+
nodes = xmldoc.xpath("//p/admitted | //p/deprecates")
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def termdef_boilerplate_cleanup(xmldoc)
|
160
|
+
xmldoc.xpath("//terms/p | //terms/ul").each(&:remove)
|
161
|
+
end
|
162
|
+
|
163
|
+
def termdef_subclause_cleanup(xmldoc)
|
164
|
+
xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
|
165
|
+
end
|
166
|
+
|
167
|
+
def termdocsource_cleanup(xmldoc)
|
168
|
+
f = xmldoc.at("//preface | //sections")
|
169
|
+
xmldoc.xpath("//termdocsource").each do |s|
|
170
|
+
f.previous = s.remove
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def term_children_cleanup(xmldoc)
|
175
|
+
xmldoc.xpath("//term").each do |t|
|
176
|
+
t.xpath("./termnote").each { |n| t << n.remove }
|
177
|
+
t.xpath("./termexample").each { |n| t << n.remove }
|
178
|
+
t.xpath("./termsource").each { |n| t << n.remove }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def termdef_cleanup(xmldoc)
|
183
|
+
termdef_unnest_cleanup(xmldoc)
|
184
|
+
termdef_stem_cleanup(xmldoc)
|
185
|
+
termdomain_cleanup(xmldoc)
|
186
|
+
termdefinition_cleanup(xmldoc)
|
187
|
+
termdomain1_cleanup(xmldoc)
|
188
|
+
termdef_boilerplate_cleanup(xmldoc)
|
189
|
+
termdef_subclause_cleanup(xmldoc)
|
190
|
+
term_children_cleanup(xmldoc)
|
191
|
+
termdocsource_cleanup(xmldoc)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
@@ -3,6 +3,7 @@ require "nokogiri"
|
|
3
3
|
require "htmlentities"
|
4
4
|
require "pathname"
|
5
5
|
require "open-uri"
|
6
|
+
require_relative "./front_contributor.rb"
|
6
7
|
|
7
8
|
module Asciidoctor
|
8
9
|
module Standoc
|
@@ -24,94 +25,6 @@ module Asciidoctor
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
def committee_component(compname, node, out)
|
28
|
-
out.send compname.gsub(/-/, "_"), node.attr(compname),
|
29
|
-
**attr_code(number: node.attr("#{compname}-number"),
|
30
|
-
type: node.attr("#{compname}-type"))
|
31
|
-
i = 2
|
32
|
-
while node.attr(compname+"_#{i}") do
|
33
|
-
out.send compname.gsub(/-/, "_"), node.attr(compname+"_#{i}"),
|
34
|
-
**attr_code(number: node.attr("#{compname}-number_#{i}"),
|
35
|
-
type: node.attr("#{compname}-type_#{i}"))
|
36
|
-
i += 1
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def organization(org, orgname)
|
41
|
-
org.name orgname
|
42
|
-
end
|
43
|
-
|
44
|
-
def metadata_author(node, xml)
|
45
|
-
(node.attr("publisher") || "").split(/,[ ]?/).each do |p|
|
46
|
-
xml.contributor do |c|
|
47
|
-
c.role **{ type: "author" }
|
48
|
-
c.organization { |a| organization(a, p) }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
personal_author(node, xml)
|
52
|
-
end
|
53
|
-
|
54
|
-
def personal_author(node, xml)
|
55
|
-
(node.attr("fullname") || node.attr("surname")) and
|
56
|
-
personal_author1(node, xml, "")
|
57
|
-
i = 2
|
58
|
-
while node.attr("fullname_#{i}") || node.attr("surname_#{i}")
|
59
|
-
personal_author1(node, xml, "_#{i}")
|
60
|
-
i += 1
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def personal_author1(node, xml, suffix)
|
65
|
-
xml.contributor do |c|
|
66
|
-
c.role **{ type: node.attr("role#{suffix}")&.downcase || "author" }
|
67
|
-
c.person do |p|
|
68
|
-
person_name(node, xml, suffix, p)
|
69
|
-
person_affiliation(node, xml, suffix, p)
|
70
|
-
node.attr("phone#{suffix}") and p.phone node.attr("phone#{suffix}")
|
71
|
-
node.attr("fax#{suffix}") and
|
72
|
-
p.phone node.attr("fax#{suffix}"), **{type: "fax"}
|
73
|
-
node.attr("email#{suffix}") and p.email node.attr("email#{suffix}")
|
74
|
-
node.attr("contributor-uri#{suffix}") and
|
75
|
-
p.uri node.attr("contributor-uri#{suffix}")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def person_name(node, xml, suffix, p)
|
81
|
-
p.name do |n|
|
82
|
-
if node.attr("fullname#{suffix}")
|
83
|
-
n.completename node.attr("fullname#{suffix}")
|
84
|
-
else
|
85
|
-
n.forename node.attr("givenname#{suffix}")
|
86
|
-
n.initial node.attr("initials#{suffix}")
|
87
|
-
n.surname node.attr("surname#{suffix}")
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def person_affiliation(node, xml, suffix, p)
|
93
|
-
node.attr("affiliation#{suffix}") and p.affiliation do |a|
|
94
|
-
a.organization do |o|
|
95
|
-
o.name node.attr("affiliation#{suffix}")
|
96
|
-
abbr = node.attr("affiliation_abbrev#{suffix}") and
|
97
|
-
o.abbreviation abbr
|
98
|
-
node.attr("address#{suffix}") and o.address do |ad|
|
99
|
-
ad.formattedAddress node.attr("address#{suffix}")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def metadata_publisher(node, xml)
|
106
|
-
publishers = node.attr("publisher") || return
|
107
|
-
publishers.split(/,[ ]?/).each do |p|
|
108
|
-
xml.contributor do |c|
|
109
|
-
c.role **{ type: "publisher" }
|
110
|
-
c.organization { |a| organization(a, p) }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
28
|
def metadata_copyright(node, xml)
|
116
29
|
publishers = node.attr("publisher") || " "
|
117
30
|
publishers.split(/,[ ]?/).each do |p|
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require "date"
|
2
|
+
require "nokogiri"
|
3
|
+
require "htmlentities"
|
4
|
+
require "pathname"
|
5
|
+
require "open-uri"
|
6
|
+
|
7
|
+
module Asciidoctor
|
8
|
+
module Standoc
|
9
|
+
module Front
|
10
|
+
def committee_component(compname, node, out)
|
11
|
+
out.send compname.gsub(/-/, "_"), node.attr(compname),
|
12
|
+
**attr_code(number: node.attr("#{compname}-number"),
|
13
|
+
type: node.attr("#{compname}-type"))
|
14
|
+
i = 2
|
15
|
+
while node.attr(compname+"_#{i}") do
|
16
|
+
out.send compname.gsub(/-/, "_"), node.attr(compname+"_#{i}"),
|
17
|
+
**attr_code(number: node.attr("#{compname}-number_#{i}"),
|
18
|
+
type: node.attr("#{compname}-type_#{i}"))
|
19
|
+
i += 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def organization(org, orgname)
|
24
|
+
org.name orgname
|
25
|
+
end
|
26
|
+
|
27
|
+
def metadata_author(node, xml)
|
28
|
+
(node.attr("publisher") || "").split(/,[ ]?/).each do |p|
|
29
|
+
xml.contributor do |c|
|
30
|
+
c.role **{ type: "author" }
|
31
|
+
c.organization { |a| organization(a, p) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
personal_author(node, xml)
|
35
|
+
end
|
36
|
+
|
37
|
+
def personal_author(node, xml)
|
38
|
+
(node.attr("fullname") || node.attr("surname")) and
|
39
|
+
personal_author1(node, xml, "")
|
40
|
+
i = 2
|
41
|
+
while node.attr("fullname_#{i}") || node.attr("surname_#{i}")
|
42
|
+
personal_author1(node, xml, "_#{i}")
|
43
|
+
i += 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def personal_author1(node, xml, suffix)
|
48
|
+
xml.contributor do |c|
|
49
|
+
c.role **{ type: node.attr("role#{suffix}")&.downcase || "author" }
|
50
|
+
c.person do |p|
|
51
|
+
person_name(node, xml, suffix, p)
|
52
|
+
person_affiliation(node, xml, suffix, p)
|
53
|
+
node.attr("phone#{suffix}") and p.phone node.attr("phone#{suffix}")
|
54
|
+
node.attr("fax#{suffix}") and
|
55
|
+
p.phone node.attr("fax#{suffix}"), **{type: "fax"}
|
56
|
+
node.attr("email#{suffix}") and p.email node.attr("email#{suffix}")
|
57
|
+
node.attr("contributor-uri#{suffix}") and
|
58
|
+
p.uri node.attr("contributor-uri#{suffix}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def person_name(node, xml, suffix, p)
|
64
|
+
p.name do |n|
|
65
|
+
if node.attr("fullname#{suffix}")
|
66
|
+
n.completename node.attr("fullname#{suffix}")
|
67
|
+
else
|
68
|
+
n.forename node.attr("givenname#{suffix}")
|
69
|
+
n.initial node.attr("initials#{suffix}")
|
70
|
+
n.surname node.attr("surname#{suffix}")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def person_affiliation(node, xml, suffix, p)
|
76
|
+
node.attr("affiliation#{suffix}") and p.affiliation do |a|
|
77
|
+
a.organization do |o|
|
78
|
+
o.name node.attr("affiliation#{suffix}")
|
79
|
+
abbr = node.attr("affiliation_abbrev#{suffix}") and
|
80
|
+
o.abbreviation abbr
|
81
|
+
node.attr("address#{suffix}") and o.address do |ad|
|
82
|
+
ad.formattedAddress node.attr("address#{suffix}")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def metadata_publisher(node, xml)
|
89
|
+
publishers = node.attr("publisher") || return
|
90
|
+
publishers.split(/,[ ]?/).each do |p|
|
91
|
+
xml.contributor do |c|
|
92
|
+
c.role **{ type: "publisher" }
|
93
|
+
c.organization { |a| organization(a, p) }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|