metanorma-standoc 1.9.0 → 1.10.0
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 +3 -13
- data/.hound.yml +3 -1
- data/.rubocop.yml +4 -8
- data/lib/asciidoctor/standoc/base.rb +31 -35
- data/lib/asciidoctor/standoc/biblio.rng +1 -0
- data/lib/asciidoctor/standoc/blocks.rb +25 -9
- data/lib/asciidoctor/standoc/blocks_notes.rb +41 -24
- data/lib/asciidoctor/standoc/cleanup.rb +59 -84
- data/lib/asciidoctor/standoc/cleanup_block.rb +63 -85
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +28 -15
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +117 -77
- data/lib/asciidoctor/standoc/cleanup_maths.rb +36 -27
- data/lib/asciidoctor/standoc/cleanup_ref.rb +31 -15
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +47 -0
- data/lib/asciidoctor/standoc/cleanup_section.rb +77 -135
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +19 -18
- data/lib/asciidoctor/standoc/converter.rb +7 -2
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +67 -66
- data/lib/asciidoctor/standoc/front.rb +35 -18
- data/lib/asciidoctor/standoc/front_contributor.rb +70 -45
- data/lib/asciidoctor/standoc/inline.rb +45 -34
- data/lib/asciidoctor/standoc/isodoc.rng +209 -4
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +11 -11
- data/lib/asciidoctor/standoc/macros_form.rb +63 -0
- data/lib/asciidoctor/standoc/macros_plantuml.rb +19 -21
- data/lib/asciidoctor/standoc/macros_terms.rb +33 -23
- data/lib/asciidoctor/standoc/ref.rb +87 -112
- data/lib/asciidoctor/standoc/ref_date_id.rb +62 -0
- data/lib/asciidoctor/standoc/ref_sect.rb +20 -17
- data/lib/asciidoctor/standoc/section.rb +3 -1
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +40 -27
- data/lib/asciidoctor/standoc/terms.rb +25 -18
- data/lib/asciidoctor/standoc/utils.rb +35 -9
- data/lib/asciidoctor/standoc/validate.rb +48 -33
- data/lib/metanorma-standoc.rb +0 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/asciidoctor/base_spec.rb +701 -508
- data/spec/asciidoctor/blocks_spec.rb +831 -738
- data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
- data/spec/asciidoctor/cleanup_spec.rb +889 -682
- data/spec/asciidoctor/inline_spec.rb +62 -14
- data/spec/asciidoctor/isobib_cache_spec.rb +404 -358
- data/spec/asciidoctor/lists_spec.rb +149 -137
- data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
- data/spec/asciidoctor/macros_spec.rb +923 -503
- data/spec/asciidoctor/macros_yaml2text_spec.rb +1 -1
- data/spec/asciidoctor/refs_dl_spec.rb +4 -4
- data/spec/asciidoctor/refs_spec.rb +1528 -1533
- data/spec/asciidoctor/section_spec.rb +405 -299
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +342 -304
- data/spec/spec_helper.rb +13 -9
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +54 -54
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +37 -37
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
- metadata +16 -15
- data/lib/liquid/custom_blocks/key_iterator.rb +0 -21
- data/lib/liquid/custom_blocks/with_json_nested_context.rb +0 -18
- data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +0 -19
- data/lib/liquid/custom_filters/values.rb +0 -7
@@ -3,36 +3,39 @@ require "pathname"
|
|
3
3
|
require "open-uri"
|
4
4
|
require "html2doc"
|
5
5
|
require "asciimath2unitsml"
|
6
|
-
require_relative "./cleanup_block
|
7
|
-
require_relative "./cleanup_footnotes
|
8
|
-
require_relative "./cleanup_ref
|
9
|
-
require_relative "./cleanup_ref_dl
|
10
|
-
require_relative "./cleanup_boilerplate
|
11
|
-
require_relative "./cleanup_section
|
12
|
-
require_relative "./cleanup_terms
|
13
|
-
require_relative "./cleanup_inline
|
14
|
-
require_relative "./cleanup_amend
|
6
|
+
require_relative "./cleanup_block"
|
7
|
+
require_relative "./cleanup_footnotes"
|
8
|
+
require_relative "./cleanup_ref"
|
9
|
+
require_relative "./cleanup_ref_dl"
|
10
|
+
require_relative "./cleanup_boilerplate"
|
11
|
+
require_relative "./cleanup_section"
|
12
|
+
require_relative "./cleanup_terms"
|
13
|
+
require_relative "./cleanup_inline"
|
14
|
+
require_relative "./cleanup_amend"
|
15
15
|
require "relaton_iev"
|
16
16
|
|
17
17
|
module Asciidoctor
|
18
18
|
module Standoc
|
19
19
|
module Cleanup
|
20
20
|
def asciimath2mathml(text)
|
21
|
-
text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do
|
22
|
+
"<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
|
23
|
+
end
|
24
|
+
text = Html2Doc.asciimath_to_mathml(text,
|
25
|
+
["<amathstem>", "</amathstem>"])
|
26
|
+
x = Nokogiri::XML(text)
|
27
|
+
x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
|
28
|
+
y.wrap("<stem type='MathML'></stem>")
|
29
|
+
end
|
30
|
+
x.to_xml
|
30
31
|
end
|
31
32
|
|
32
33
|
def xml_unescape_mathml(x)
|
33
34
|
return if x.children.any? { |y| y.element? }
|
34
|
-
|
35
|
-
|
35
|
+
|
36
|
+
math = x.text.gsub(/</, "<").gsub(/>/, ">")
|
37
|
+
.gsub(/"/, '"').gsub(/'/, "'").gsub(/&/, "&")
|
38
|
+
.gsub(/<[^: \r\n\t\/]+:/, "<").gsub(/<\/[^ \r\n\t:]+:/, "</")
|
36
39
|
x.children = math
|
37
40
|
end
|
38
41
|
|
@@ -40,12 +43,13 @@ module Asciidoctor
|
|
40
43
|
|
41
44
|
def mathml_preserve_space(m)
|
42
45
|
m.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
|
43
|
-
x.children = x.children.to_xml
|
46
|
+
x.children = x.children.to_xml
|
47
|
+
.gsub(/^\s/, " ").gsub(/\s$/, " ")
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
47
51
|
def mathml_namespace(stem)
|
48
|
-
stem.xpath("./math"
|
52
|
+
stem.xpath("./math").each { |x| x.default_namespace = MATHML_NS }
|
49
53
|
end
|
50
54
|
|
51
55
|
def mathml_mi_italics
|
@@ -55,7 +59,8 @@ module Asciidoctor
|
|
55
59
|
|
56
60
|
# presuppose multichar mi upright, singlechar mi MathML default italic
|
57
61
|
def mathml_italicise(x)
|
58
|
-
x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]",
|
62
|
+
x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]",
|
63
|
+
"m" => MATHML_NS).each do |i|
|
59
64
|
char = HTMLEntities.new.decode(i.text)
|
60
65
|
i["mathvariant"] = "normal" if mi_italicise?(char)
|
61
66
|
end
|
@@ -63,10 +68,11 @@ module Asciidoctor
|
|
63
68
|
|
64
69
|
def mi_italicise?(c)
|
65
70
|
return false if c.length > 1
|
66
|
-
|
71
|
+
|
72
|
+
if /\p{Greek}/.match?(c)
|
67
73
|
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowergreek] ||
|
68
74
|
/\p{Upper}/.match(c) && !mathml_mi_italics[:uppergreek]
|
69
|
-
elsif /\p{Latin}/.match(c)
|
75
|
+
elsif /\p{Latin}/.match?(c)
|
70
76
|
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowerroman] ||
|
71
77
|
/\p{Upper}/.match(c) && !mathml_mi_italics[:upperroman]
|
72
78
|
else
|
@@ -87,6 +93,7 @@ module Asciidoctor
|
|
87
93
|
|
88
94
|
def mathml_unitsML(xmldoc)
|
89
95
|
return unless xmldoc.at(".//m:*", "m" => UNITSML_NS)
|
96
|
+
|
90
97
|
misc = add_misc_container(xmldoc)
|
91
98
|
unitsml = misc.add_child("<UnitsML xmlns='#{UNITSML_NS}'/>").first
|
92
99
|
%w(Unit CountedItem Quantity Dimension Prefix).each do |t|
|
@@ -95,12 +102,14 @@ module Asciidoctor
|
|
95
102
|
end
|
96
103
|
|
97
104
|
def gather_unitsml(unitsml, xmldoc, t)
|
98
|
-
tags = xmldoc.xpath(".//m:#{t}", "m" => UNITSML_NS)
|
105
|
+
tags = xmldoc.xpath(".//m:#{t}", "m" => UNITSML_NS)
|
106
|
+
.each_with_object({}) do |x, m|
|
99
107
|
m[x["id"]] = x.remove
|
100
108
|
end
|
101
109
|
return if tags.empty?
|
110
|
+
|
102
111
|
set = unitsml.add_child("<#{t}Set/>").first
|
103
|
-
tags.
|
112
|
+
tags.each_value { |v| set << v }
|
104
113
|
end
|
105
114
|
|
106
115
|
def asciimath2unitsml_options
|
@@ -14,9 +14,10 @@ module Asciidoctor
|
|
14
14
|
fold_notes_into_biblio(refs)
|
15
15
|
bib = sort_biblio(refs.xpath("./bibitem"))
|
16
16
|
insert = refs&.at("./bibitem")&.previous_element
|
17
|
-
refs.xpath("./bibitem").each
|
17
|
+
refs.xpath("./bibitem").each(&:remove)
|
18
18
|
bib.reverse.each do |b|
|
19
|
-
insert and insert.next = b.to_xml or
|
19
|
+
insert and insert.next = b.to_xml or
|
20
|
+
refs.children.first.add_previous_sibling b.to_xml
|
20
21
|
end
|
21
22
|
extract_notes_from_biblio(refs)
|
22
23
|
refs.xpath("./references").each { |r| biblio_reorder1(r) }
|
@@ -24,7 +25,7 @@ module Asciidoctor
|
|
24
25
|
|
25
26
|
def fold_notes_into_biblio(refs)
|
26
27
|
refs.xpath("./bibitem").each do |r|
|
27
|
-
while r&.next_element&.name == "note"
|
28
|
+
while r&.next_element&.name == "note"
|
28
29
|
r.next_element["appended"] = true
|
29
30
|
r << r.next_element.remove
|
30
31
|
end
|
@@ -49,12 +50,15 @@ module Asciidoctor
|
|
49
50
|
# only numeric references are renumbered
|
50
51
|
def biblio_renumber(xmldoc)
|
51
52
|
i = 0
|
52
|
-
xmldoc.xpath("//bibliography//references | //clause//references |
|
53
|
+
xmldoc.xpath("//bibliography//references | //clause//references | "\
|
54
|
+
"//annex//references").each do |r|
|
53
55
|
next if r["normative"] == "true"
|
56
|
+
|
54
57
|
r.xpath("./bibitem").each do |b|
|
55
58
|
i += 1
|
56
59
|
next unless docid = b.at("./docidentifier[@type = 'metanorma']")
|
57
|
-
next unless
|
60
|
+
next unless /^\[\d+\]$/.match?(docid.text)
|
61
|
+
|
58
62
|
docid.children = "[#{i}]"
|
59
63
|
end
|
60
64
|
end
|
@@ -70,9 +74,10 @@ module Asciidoctor
|
|
70
74
|
|
71
75
|
def normref_cleanup(xmldoc)
|
72
76
|
r = xmldoc.at(self.class::NORM_REF) || return
|
73
|
-
preface = r.xpath("./title/following-sibling::*") & # intersection
|
74
|
-
|
75
|
-
|
77
|
+
preface = ((r.xpath("./title/following-sibling::*") & # intersection
|
78
|
+
r.xpath("./bibitem[1]/preceding-sibling::*")) -
|
79
|
+
r.xpath("./note[@type = 'boilerplate']/descendant-or-self::*"))
|
80
|
+
preface.each(&:remove)
|
76
81
|
end
|
77
82
|
|
78
83
|
def biblio_cleanup(xmldoc)
|
@@ -92,6 +97,7 @@ module Asciidoctor
|
|
92
97
|
def format_ref(ref, type)
|
93
98
|
return @isodoc.docid_prefix(type, ref) if type != "metanorma"
|
94
99
|
return "[#{ref}]" if /^\d+$/.match(ref) && !/^\[.*\]$/.match(ref)
|
100
|
+
|
95
101
|
ref
|
96
102
|
end
|
97
103
|
|
@@ -103,7 +109,7 @@ module Asciidoctor
|
|
103
109
|
|
104
110
|
def reference_names(xmldoc)
|
105
111
|
xmldoc.xpath("//bibitem[not(ancestor::bibitem)]").each do |ref|
|
106
|
-
isopub = ref.at(ISO_PUBLISHER_XPATH)
|
112
|
+
# isopub = ref.at(ISO_PUBLISHER_XPATH)
|
107
113
|
docid = ref.at("./docidentifier[@type = 'metanorma']") ||
|
108
114
|
ref.at("./docidentifier[not(@type = 'DOI')]") or next
|
109
115
|
reference = format_ref(docid.text, docid["type"])
|
@@ -111,18 +117,20 @@ module Asciidoctor
|
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
114
|
-
def fetch_termbase(
|
120
|
+
def fetch_termbase(_termbase, _id)
|
115
121
|
""
|
116
122
|
end
|
117
123
|
|
118
124
|
def read_local_bibitem(uri)
|
119
|
-
return nil if %r{^
|
120
|
-
|
121
|
-
|
125
|
+
return nil if %r{^https?://}.match?(uri)
|
126
|
+
|
127
|
+
file = "#{@localdir}#{uri}.rxl"
|
128
|
+
File.file?(file) or file = "#{@localdir}#{uri}.xml"
|
122
129
|
File.file?(file) or return nil
|
123
130
|
xml = Nokogiri::XML(File.read(file, encoding: "utf-8"))
|
124
131
|
ret = xml.at("//*[local-name() = 'bibdata']") or return nil
|
125
|
-
ret = Nokogiri::XML(ret.to_xml
|
132
|
+
ret = Nokogiri::XML(ret.to_xml
|
133
|
+
.sub(%r{(<bibdata[^>]*?) xmlns=("[^"]+"|'[^']+')}, "\\1")).root
|
126
134
|
ret.name = "bibitem"
|
127
135
|
ins = ret.at("./*[local-name() = 'docidentifier']") or return nil
|
128
136
|
ins.previous = %{<uri type="citation">#{uri}</uri>}
|
@@ -132,7 +140,8 @@ module Asciidoctor
|
|
132
140
|
|
133
141
|
# if citation uri points to local file, get bibitem from it
|
134
142
|
def fetch_local_bibitem(xmldoc)
|
135
|
-
xmldoc.xpath("//bibitem[formattedref][uri[@type = 'citation']]")
|
143
|
+
xmldoc.xpath("//bibitem[formattedref][uri[@type = 'citation']]")
|
144
|
+
.each do |b|
|
136
145
|
uri = b&.at("./uri[@type = 'citation']")&.text
|
137
146
|
bibitem = read_local_bibitem(uri) or next
|
138
147
|
bibitem["id"] = b["id"]
|
@@ -140,7 +149,14 @@ module Asciidoctor
|
|
140
149
|
end
|
141
150
|
end
|
142
151
|
|
152
|
+
def bibitem_nested_id(xmldoc)
|
153
|
+
xmldoc.xpath("//bibitem//bibitem").each do |b|
|
154
|
+
b.delete("id")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
143
158
|
def bibitem_cleanup(xmldoc)
|
159
|
+
bibitem_nested_id(xmldoc)
|
144
160
|
ref_dl_cleanup(xmldoc)
|
145
161
|
fetch_local_bibitem(xmldoc)
|
146
162
|
end
|
@@ -8,7 +8,7 @@ module Asciidoctor
|
|
8
8
|
xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
|
9
9
|
bib = dl_bib_extract(c) or next
|
10
10
|
validate_ref_dl(bib, c)
|
11
|
-
bibitemxml = RelatonBib::BibliographicItem.
|
11
|
+
bibitemxml = RelatonBib::BibliographicItem.from_hash(bib).to_xml or next
|
12
12
|
bibitem = Nokogiri::XML(bibitemxml)
|
13
13
|
bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
|
14
14
|
c.replace(bibitem.root)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
3
|
+
module Cleanup
|
4
|
+
def requirement_cleanup(reqt)
|
5
|
+
requirement_descriptions(reqt)
|
6
|
+
requirement_inherit(reqt)
|
7
|
+
end
|
8
|
+
|
9
|
+
def requirement_inherit(reqt)
|
10
|
+
reqt.xpath("//requirement | //recommendation | //permission")
|
11
|
+
.each do |r|
|
12
|
+
ins = r.at("./classification") ||
|
13
|
+
r.at("./description | ./measurementtarget | ./specification | "\
|
14
|
+
"./verification | ./import | ./description | ./requirement | "\
|
15
|
+
"./recommendation | ./permission")
|
16
|
+
r.xpath("./*//inherit").each { |i| ins.previous = i }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def requirement_descriptions(reqt)
|
21
|
+
reqt.xpath("//requirement | //recommendation | //permission")
|
22
|
+
.each do |r|
|
23
|
+
r.children.each do |e|
|
24
|
+
unless e.element? && (reqt_subpart(e.name) ||
|
25
|
+
%w(requirement recommendation permission).include?(e.name))
|
26
|
+
t = Nokogiri::XML::Element.new("description", reqt)
|
27
|
+
e.before(t)
|
28
|
+
t.children = e.remove
|
29
|
+
end
|
30
|
+
end
|
31
|
+
requirement_cleanup1(r)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def requirement_cleanup1(reqt)
|
36
|
+
while d = reqt.at("./description[following-sibling::*[1]"\
|
37
|
+
"[self::description]]")
|
38
|
+
n = d.next.remove
|
39
|
+
d << n.children
|
40
|
+
end
|
41
|
+
reqt.xpath("./description[normalize-space(.)='']").each do |r|
|
42
|
+
r.replace("\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -3,36 +3,37 @@ require "htmlentities"
|
|
3
3
|
require "json"
|
4
4
|
require "open-uri"
|
5
5
|
require "mathml2asciimath"
|
6
|
+
require_relative "cleanup_section_names"
|
6
7
|
|
7
8
|
module Asciidoctor
|
8
9
|
module Standoc
|
9
10
|
module Cleanup
|
10
|
-
def make_preface(
|
11
|
-
if
|
11
|
+
def make_preface(xml, sect)
|
12
|
+
if xml.at("//foreword | //introduction | //acknowledgements | "\
|
12
13
|
"//*[@preface]")
|
13
|
-
preface =
|
14
|
-
f =
|
15
|
-
f =
|
16
|
-
move_clauses_into_preface(
|
17
|
-
f =
|
14
|
+
preface = sect.add_previous_sibling("<preface/>").first
|
15
|
+
f = xml.at("//foreword") and preface.add_child f.remove
|
16
|
+
f = xml.at("//introduction") and preface.add_child f.remove
|
17
|
+
move_clauses_into_preface(xml, preface)
|
18
|
+
f = xml.at("//acknowledgements") and preface.add_child f.remove
|
18
19
|
end
|
19
|
-
make_abstract(
|
20
|
+
make_abstract(xml, sect)
|
20
21
|
end
|
21
22
|
|
22
|
-
def move_clauses_into_preface(
|
23
|
-
|
23
|
+
def move_clauses_into_preface(xml, preface)
|
24
|
+
xml.xpath("//*[@preface]").each do |c|
|
24
25
|
c.delete("preface")
|
25
26
|
preface.add_child c.remove
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
def make_abstract(
|
30
|
-
if
|
31
|
-
preface =
|
32
|
-
|
33
|
-
abstract =
|
30
|
+
def make_abstract(xml, sect)
|
31
|
+
if xml.at("//abstract[not(ancestor::bibitem)]")
|
32
|
+
preface = sect.at("//preface") ||
|
33
|
+
sect.add_previous_sibling("<preface/>").first
|
34
|
+
abstract = xml.at("//abstract[not(ancestor::bibitem)]").remove
|
34
35
|
preface.prepend_child abstract.remove
|
35
|
-
bibabstract = bibabstract_location(
|
36
|
+
bibabstract = bibabstract_location(xml)
|
36
37
|
dupabstract = abstract.dup
|
37
38
|
dupabstract.traverse { |n| n.remove_attribute("id") }
|
38
39
|
dupabstract.remove_attribute("language")
|
@@ -42,42 +43,46 @@ module Asciidoctor
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
def bibabstract_location(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
def bibabstract_location(xml)
|
47
|
+
xml.at("//bibdata/script") || xml.at("//bibdata/language") ||
|
48
|
+
xml.at("//bibdata/contributor[not(following-sibling::contributor)]") ||
|
49
|
+
xml.at("//bibdata/date[not(following-sibling::date)]") ||
|
50
|
+
xml.at("//docnumber") ||
|
51
|
+
xml.at("//bibdata/docidentifier"\
|
52
|
+
"[not(following-sibling::docidentifier)]") ||
|
53
|
+
xml.at("//bibdata/uri[not(following-sibling::uri)]") ||
|
54
|
+
xml.at("//bibdata/title[not(following-sibling::title)]")
|
54
55
|
end
|
55
56
|
|
56
|
-
def make_bibliography(
|
57
|
-
if
|
58
|
-
biblio =
|
59
|
-
|
57
|
+
def make_bibliography(xml, sect)
|
58
|
+
if xml.at("//sections/references")
|
59
|
+
biblio = sect.add_next_sibling("<bibliography/>").first
|
60
|
+
xml.xpath("//sections/references").each do |r|
|
60
61
|
biblio.add_child r.remove
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
|
-
def make_indexsect(
|
66
|
-
|
66
|
+
def make_indexsect(xml, sect)
|
67
|
+
xml.xpath("//sections/indexsect").reverse_each do |r|
|
68
|
+
sect.next = r.remove
|
69
|
+
end
|
67
70
|
end
|
68
71
|
|
69
|
-
def sections_order_cleanup(
|
70
|
-
s =
|
71
|
-
make_preface(
|
72
|
-
make_annexes(
|
73
|
-
make_indexsect(
|
74
|
-
make_bibliography(
|
75
|
-
|
72
|
+
def sections_order_cleanup(xml)
|
73
|
+
s = xml.at("//sections")
|
74
|
+
make_preface(xml, s)
|
75
|
+
make_annexes(xml)
|
76
|
+
make_indexsect(xml, s)
|
77
|
+
make_bibliography(xml, s)
|
78
|
+
xml.xpath("//sections/annex").reverse_each { |r| s.next = r.remove }
|
76
79
|
end
|
77
|
-
|
78
|
-
|
80
|
+
|
81
|
+
def make_annexes(xml)
|
82
|
+
xml.xpath("//*[@annex]").each do |y|
|
79
83
|
y.delete("annex")
|
80
84
|
next if y.name == "annex" || !y.ancestors("annex").empty?
|
85
|
+
|
81
86
|
y.wrap("<annex/>")
|
82
87
|
y.parent["id"] = "_#{UUIDTools::UUID.random_create}"
|
83
88
|
y.parent["obligation"] = y["obligation"]
|
@@ -86,59 +91,61 @@ module Asciidoctor
|
|
86
91
|
end
|
87
92
|
end
|
88
93
|
|
89
|
-
def maxlevel(
|
94
|
+
def maxlevel(xml)
|
90
95
|
max = 5
|
91
|
-
|
96
|
+
xml.xpath("//clause[@level]").each do |c|
|
92
97
|
max = c["level"].to_i if max < c["level"].to_i
|
93
98
|
end
|
94
99
|
max
|
95
100
|
end
|
96
101
|
|
97
|
-
def sections_level_cleanup(
|
98
|
-
m = maxlevel(
|
102
|
+
def sections_level_cleanup(xml)
|
103
|
+
m = maxlevel(xml)
|
99
104
|
return if m < 6
|
105
|
+
|
100
106
|
m.downto(6).each do |l|
|
101
|
-
|
107
|
+
xml.xpath("//clause[@level = '#{l}']").each do |c|
|
102
108
|
c.delete("level")
|
103
109
|
c.previous_element << c.remove
|
104
110
|
end
|
105
111
|
end
|
106
112
|
end
|
107
113
|
|
108
|
-
def sections_cleanup(
|
109
|
-
sections_order_cleanup(
|
110
|
-
sections_level_cleanup(
|
111
|
-
sections_names_cleanup(
|
112
|
-
change_clauses(
|
114
|
+
def sections_cleanup(xml)
|
115
|
+
sections_order_cleanup(xml)
|
116
|
+
sections_level_cleanup(xml)
|
117
|
+
sections_names_cleanup(xml)
|
118
|
+
change_clauses(xml)
|
113
119
|
end
|
114
120
|
|
115
|
-
def obligations_cleanup(
|
116
|
-
obligations_cleanup_info(
|
117
|
-
obligations_cleanup_norm(
|
118
|
-
obligations_cleanup_inherit(
|
121
|
+
def obligations_cleanup(xml)
|
122
|
+
obligations_cleanup_info(xml)
|
123
|
+
obligations_cleanup_norm(xml)
|
124
|
+
obligations_cleanup_inherit(xml)
|
119
125
|
end
|
120
126
|
|
121
|
-
def obligations_cleanup_info(
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
+
def obligations_cleanup_info(xml)
|
128
|
+
s = xml.at("//foreword") and s["obligation"] = "informative"
|
129
|
+
s = xml.at("//introduction") and s["obligation"] = "informative"
|
130
|
+
s = xml.at("//acknowledgements") and s["obligation"] = "informative"
|
131
|
+
xml.xpath("//references").each { |r| r["obligation"] = "informative" }
|
132
|
+
xml.xpath("//preface//clause").each do |r|
|
127
133
|
r["obligation"] = "informative"
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
131
|
-
def obligations_cleanup_norm(
|
132
|
-
|
133
|
-
|
134
|
-
|
137
|
+
def obligations_cleanup_norm(xml)
|
138
|
+
s = xml.at("//clause[@type = 'scope']") and
|
139
|
+
s["obligation"] = "normative"
|
140
|
+
xml.xpath("//terms").each { |r| r["obligation"] = "normative" }
|
141
|
+
xml.xpath("//definitions").each { |r| r["obligation"] = "normative" }
|
135
142
|
end
|
136
143
|
|
137
|
-
def obligations_cleanup_inherit(
|
138
|
-
|
144
|
+
def obligations_cleanup_inherit(xml)
|
145
|
+
xml.xpath("//annex | //clause[not(ancestor::boilerplate)]").each do |r|
|
139
146
|
r["obligation"] = "normative" unless r["obligation"]
|
140
147
|
end
|
141
|
-
|
148
|
+
xml.xpath(Utils::SUBCLAUSE_XPATH).each do |r|
|
142
149
|
o = r&.at("./ancestor::*/@obligation")&.text and r["obligation"] = o
|
143
150
|
end
|
144
151
|
end
|
@@ -148,8 +155,9 @@ module Asciidoctor
|
|
148
155
|
sections_clausebefore_cleanup(xmldoc)
|
149
156
|
end
|
150
157
|
|
151
|
-
|
158
|
+
def preface_clausebefore_cleanup(xmldoc)
|
152
159
|
return unless xmldoc.at("//preface")
|
160
|
+
|
153
161
|
unless ins = xmldoc.at("//preface").children.first
|
154
162
|
xmldoc.at("//preface") << " "
|
155
163
|
ins = xmldoc.at("//preface").children.first
|
@@ -162,6 +170,7 @@ module Asciidoctor
|
|
162
170
|
|
163
171
|
def sections_clausebefore_cleanup(xmldoc)
|
164
172
|
return unless xmldoc.at("//sections")
|
173
|
+
|
165
174
|
unless ins = xmldoc.at("//sections").children.first
|
166
175
|
xmldoc.at("//sections") << " "
|
167
176
|
ins = xmldoc.at("//sections").children.first
|
@@ -171,73 +180,6 @@ module Asciidoctor
|
|
171
180
|
ins.previous = x.remove
|
172
181
|
end
|
173
182
|
end
|
174
|
-
|
175
|
-
def get_or_make_title(node)
|
176
|
-
unless node.at("./title")
|
177
|
-
if node.children.empty?
|
178
|
-
node << "<title/>"
|
179
|
-
else
|
180
|
-
node.children.first.previous = "<title/>"
|
181
|
-
end
|
182
|
-
end
|
183
|
-
node.at("./title")
|
184
|
-
end
|
185
|
-
|
186
|
-
def replace_title(doc, xpath, text, first = false)
|
187
|
-
return unless text
|
188
|
-
|
189
|
-
doc.xpath(xpath).each_with_index do |node, i|
|
190
|
-
next if first && !i.zero?
|
191
|
-
title = get_or_make_title(node)
|
192
|
-
fn = title.xpath("./fn")
|
193
|
-
fn.each { |n| n.remove }
|
194
|
-
title.content = text
|
195
|
-
fn.each { |n| title << n }
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
def sections_names_cleanup(xml)
|
200
|
-
replace_title(xml, "//clause[@type = 'scope']", @i18n&.scope)
|
201
|
-
replace_title(xml, "//preface//abstract", @i18n&.abstract)
|
202
|
-
replace_title(xml, "//foreword", @i18n&.foreword)
|
203
|
-
replace_title(xml, "//introduction", @i18n&.introduction)
|
204
|
-
replace_title(xml, "//acknowledgements", @i18n&.acknowledgements)
|
205
|
-
section_names_refs_cleanup(xml)
|
206
|
-
section_names_terms_cleanup(xml)
|
207
|
-
end
|
208
|
-
|
209
|
-
def section_names_refs_cleanup(xml)
|
210
|
-
replace_title(xml, "//references[@normative = 'true']",
|
211
|
-
@i18n&.normref, true)
|
212
|
-
replace_title(xml, "//references[@normative = 'false']",
|
213
|
-
@i18n&.bibliography, true)
|
214
|
-
end
|
215
|
-
|
216
|
-
NO_SYMABBR = "[.//definitions[not(@type)]]".freeze
|
217
|
-
SYMABBR = "[.//definitions[@type = 'symbols']"\
|
218
|
-
"[@type = 'abbreviated_terms']]".freeze
|
219
|
-
SYMnoABBR = "[.//definitions[@type = 'symbols']"\
|
220
|
-
"[not(@type = 'abbreviated_terms')]]".freeze
|
221
|
-
ABBRnoSYM = "[.//definitions[not(@type = 'symbols')]"\
|
222
|
-
"[@type = 'abbreviated_terms']]".freeze
|
223
|
-
|
224
|
-
def section_names_terms_cleanup(x)
|
225
|
-
replace_title(x, "//definitions[@type = 'symbols']", @i18n&.symbols)
|
226
|
-
replace_title(x, "//definitions[@type = 'abbreviated_terms']",
|
227
|
-
@i18n&.abbrev)
|
228
|
-
replace_title(x, "//definitions[not(@type)]", @i18n&.symbolsabbrev)
|
229
|
-
replace_title(x, "//terms#{SYMnoABBR} | //clause[.//terms]#{SYMnoABBR}",
|
230
|
-
@i18n&.termsdefsymbols, true)
|
231
|
-
replace_title(x, "//terms#{ABBRnoSYM} | //clause[.//terms]#{ABBRnoSYM}",
|
232
|
-
@i18n&.termsdefabbrev, true)
|
233
|
-
replace_title(x, "//terms#{SYMABBR} | //clause[.//terms]#{SYMABBR}",
|
234
|
-
@i18n&.termsdefsymbolsabbrev, true)
|
235
|
-
replace_title(x, "//terms#{NO_SYMABBR} | //clause[.//terms]#{NO_SYMABBR}",
|
236
|
-
@i18n&.termsdefsymbolsabbrev, true)
|
237
|
-
replace_title(
|
238
|
-
x, "//terms[not(.//definitions)] | //clause[.//terms][not(.//definitions)]",
|
239
|
-
@i18n&.termsdef, true)
|
240
|
-
end
|
241
183
|
end
|
242
184
|
end
|
243
185
|
end
|