metanorma-standoc 1.4.2 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +0 -7
- data/.github/workflows/ubuntu.yml +6 -11
- data/.github/workflows/windows.yml +0 -8
- data/.rubocop.yml +1 -1
- data/Rakefile +2 -0
- data/lib/asciidoctor/standoc/base.rb +15 -21
- data/lib/asciidoctor/standoc/cleanup.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +11 -24
- data/lib/asciidoctor/standoc/cleanup_inline.rb +57 -1
- data/lib/asciidoctor/standoc/cleanup_ref.rb +13 -8
- data/lib/asciidoctor/standoc/cleanup_section.rb +90 -6
- data/lib/asciidoctor/standoc/cleanup_terms.rb +12 -2
- data/lib/asciidoctor/standoc/converter.rb +16 -2
- data/lib/asciidoctor/standoc/front.rb +0 -12
- data/lib/asciidoctor/standoc/front_contributor.rb +28 -3
- data/lib/asciidoctor/standoc/inline.rb +1 -1
- data/lib/asciidoctor/standoc/isodoc.rng +16 -7
- data/lib/asciidoctor/standoc/log.rb +10 -1
- data/lib/asciidoctor/standoc/ref.rb +24 -25
- data/lib/asciidoctor/standoc/section.rb +31 -27
- data/lib/asciidoctor/standoc/utils.rb +18 -1
- data/lib/asciidoctor/standoc/validate.rb +30 -18
- data/lib/asciidoctor/standoc/validate_section.rb +1 -1
- data/lib/metanorma/standoc/processor.rb +0 -4
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +3 -2
- data/spec/asciidoctor-standoc/base_spec.rb +21 -6
- data/spec/asciidoctor-standoc/blocks_spec.rb +21 -7
- data/spec/asciidoctor-standoc/cleanup_spec.rb +1337 -23
- data/spec/asciidoctor-standoc/inline_spec.rb +7 -4
- data/spec/asciidoctor-standoc/macros_spec.rb +41 -23
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +9 -7
- data/spec/asciidoctor-standoc/refs_spec.rb +16 -16
- data/spec/asciidoctor-standoc/section_spec.rb +42 -38
- data/spec/asciidoctor-standoc/table_spec.rb +7 -1
- data/spec/asciidoctor-standoc/validate_spec.rb +40 -0
- data/spec/assets/{html.css → html.scss} +0 -0
- data/spec/assets/i18n.yaml +17 -2
- data/spec/assets/{word.css → word.scss} +0 -0
- data/spec/metanorma/processor_spec.rb +1 -2
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +66 -66
- data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
- data/spec/vcr_cassettes/isobib_get_123_1.yml +33 -33
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +19 -19
- data/spec/vcr_cassettes/isobib_get_124.yml +19 -19
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +28 -28
- metadata +22 -12
- data/lib/asciidoctor-yaml/i18n-en.yaml +0 -20
- data/lib/asciidoctor-yaml/i18n-fr.yaml +0 -13
- data/lib/asciidoctor-yaml/i18n-zh-Hans.yaml +0 -15
- data/lib/asciidoctor/standoc/i18n.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 910ada4e6d4f62c6106391e3ec0de46a7ba4a9d5362bb103cd80ee0b2acef9dc
|
4
|
+
data.tar.gz: de8546c035da0236faa4a6ca5df9b0f54f16806d09386793f359e55b69884212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 422e64b66f95fa4c49727687c446bd3f79bc09aa0609b352bd68cc659ff06bf57243ed410e4baa8f0cb501f101212d305a756b41548fcee7e877135aea22e1f3
|
7
|
+
data.tar.gz: 97d6e164975997ecc396376abdaf2edad43c1f4fbfa601dbbc5f2f4d465747164350f500aaadc05f9fd6ed1e499925df7d74626fcde21a0578feeb50d607b84e
|
data/.github/workflows/macos.yml
CHANGED
@@ -29,10 +29,6 @@ jobs:
|
|
29
29
|
uses: actions/setup-ruby@v1
|
30
30
|
with:
|
31
31
|
ruby-version: ${{ matrix.ruby }}
|
32
|
-
architecture: 'x64'
|
33
|
-
- uses: actions/setup-node@v1
|
34
|
-
with:
|
35
|
-
node-version: '10.x'
|
36
32
|
- name: Install LaTeXML
|
37
33
|
run: |
|
38
34
|
brew install libxml2 cpanminus
|
@@ -41,9 +37,6 @@ jobs:
|
|
41
37
|
- name: Install PlantUML
|
42
38
|
run: |
|
43
39
|
brew install plantuml
|
44
|
-
- name: Install puppeteer
|
45
|
-
run: |
|
46
|
-
npm -g i puppeteer
|
47
40
|
- name: Update gems
|
48
41
|
run: |
|
49
42
|
sudo gem install bundler --force
|
@@ -29,10 +29,6 @@ jobs:
|
|
29
29
|
uses: actions/setup-ruby@v1
|
30
30
|
with:
|
31
31
|
ruby-version: ${{ matrix.ruby }}
|
32
|
-
architecture: 'x64'
|
33
|
-
- uses: actions/setup-node@v1
|
34
|
-
with:
|
35
|
-
node-version: '10.x'
|
36
32
|
- name: Update gems
|
37
33
|
run: |
|
38
34
|
gem install bundler
|
@@ -42,13 +38,12 @@ jobs:
|
|
42
38
|
sudo snap install latexml --edge
|
43
39
|
echo "::add-path::/snap/bin"
|
44
40
|
- name: Install PlantUML
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
sudo apt-get
|
51
|
-
npm install -g puppeteer@3.0.1
|
41
|
+
uses: nick-invision/retry@v1
|
42
|
+
with:
|
43
|
+
polling_interval_seconds: 5
|
44
|
+
timeout_minutes: 5
|
45
|
+
max_attempts: 3
|
46
|
+
command: sudo apt-get update -y && sudo bash -c "curl -L https://github.com/metanorma/plantuml-install/raw/master/ubuntu.sh | bash"
|
52
47
|
- name: Run specs
|
53
48
|
run: |
|
54
49
|
bundle exec rake
|
@@ -29,10 +29,6 @@ jobs:
|
|
29
29
|
uses: actions/setup-ruby@v1
|
30
30
|
with:
|
31
31
|
ruby-version: ${{ matrix.ruby }}
|
32
|
-
architecture: 'x64'
|
33
|
-
- uses: actions/setup-node@v1
|
34
|
-
with:
|
35
|
-
node-version: '10.x'
|
36
32
|
- name: Install MN Windows dependencies
|
37
33
|
shell: pwsh
|
38
34
|
run: |
|
@@ -50,10 +46,6 @@ jobs:
|
|
50
46
|
refreshenv
|
51
47
|
set PATH=C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;%PATH%
|
52
48
|
where latexmlmath
|
53
|
-
- name: Install puppeteer
|
54
|
-
shell: pwsh
|
55
|
-
run: |
|
56
|
-
npm -g i puppeteer
|
57
49
|
- name: Run specs
|
58
50
|
shell: pwsh
|
59
51
|
run: |
|
data/.rubocop.yml
CHANGED
data/Rakefile
CHANGED
@@ -14,22 +14,6 @@ module Asciidoctor
|
|
14
14
|
XML_ROOT_TAG = "standard-document".freeze
|
15
15
|
XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
|
16
16
|
|
17
|
-
Asciidoctor::Extensions.register do
|
18
|
-
preprocessor Asciidoctor::Standoc::Datamodel::AttributesTablePreprocessor
|
19
|
-
preprocessor Asciidoctor::Standoc::Datamodel::DiagramPreprocessor
|
20
|
-
preprocessor Asciidoctor::Standoc::Yaml2TextPreprocessor
|
21
|
-
inline_macro Asciidoctor::Standoc::AltTermInlineMacro
|
22
|
-
inline_macro Asciidoctor::Standoc::DeprecatedTermInlineMacro
|
23
|
-
inline_macro Asciidoctor::Standoc::DomainTermInlineMacro
|
24
|
-
inline_macro Asciidoctor::Standoc::InheritInlineMacro
|
25
|
-
inline_macro Asciidoctor::Standoc::HTML5RubyMacro
|
26
|
-
inline_macro Asciidoctor::Standoc::ConceptInlineMacro
|
27
|
-
block Asciidoctor::Standoc::ToDoAdmonitionBlock
|
28
|
-
treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
|
29
|
-
block Asciidoctor::Standoc::PlantUMLBlockMacro
|
30
|
-
block Asciidoctor::Standoc::PseudocodeBlockMacro
|
31
|
-
end
|
32
|
-
|
33
17
|
def xml_root_tag
|
34
18
|
self.class::XML_ROOT_TAG
|
35
19
|
end
|
@@ -117,6 +101,7 @@ module Asciidoctor
|
|
117
101
|
@filename = node.attr("docfile") ?
|
118
102
|
File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
|
119
103
|
@localdir = Utils::localdir(node)
|
104
|
+
@output_dir = outputdir node
|
120
105
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
121
106
|
@no_isobib = node.attr("no-isobib")
|
122
107
|
@bibdb = nil
|
@@ -126,9 +111,10 @@ module Asciidoctor
|
|
126
111
|
@log = Asciidoctor::Standoc::Log.new
|
127
112
|
init_bib_caches(node)
|
128
113
|
init_iev_caches(node)
|
129
|
-
lang = (node.attr("language") || "en")
|
130
|
-
script = (node.attr("script") || "
|
131
|
-
|
114
|
+
@lang = (node.attr("language") || "en")
|
115
|
+
@script = (node.attr("script") || "Latn")
|
116
|
+
@isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
|
117
|
+
@i18n = @isodoc.i18n
|
132
118
|
end
|
133
119
|
|
134
120
|
def default_fonts(node)
|
@@ -158,7 +144,7 @@ module Asciidoctor
|
|
158
144
|
end
|
159
145
|
|
160
146
|
def clean_exit
|
161
|
-
@log.write(@
|
147
|
+
@log.write(@output_dir + @filename + ".err") unless @novalid
|
162
148
|
@files_to_delete.each { |f| FileUtils.rm f }
|
163
149
|
end
|
164
150
|
|
@@ -184,7 +170,7 @@ module Asciidoctor
|
|
184
170
|
end
|
185
171
|
|
186
172
|
def doctype(node)
|
187
|
-
node.attr("doctype")
|
173
|
+
node.attr("doctype")&.gsub(/\s+/, "-")&.downcase
|
188
174
|
end
|
189
175
|
|
190
176
|
def front(node, xml)
|
@@ -243,6 +229,14 @@ module Asciidoctor
|
|
243
229
|
end
|
244
230
|
end.join("\n")
|
245
231
|
end
|
232
|
+
|
233
|
+
private
|
234
|
+
|
235
|
+
def outputdir(node)
|
236
|
+
if node.attr("output_dir").nil_or_empty? then Utils::localdir(node)
|
237
|
+
else File.join(node.attr("output_dir"), "")
|
238
|
+
end
|
239
|
+
end
|
246
240
|
end
|
247
241
|
end
|
248
242
|
end
|
@@ -2,25 +2,25 @@ module Asciidoctor
|
|
2
2
|
module Standoc
|
3
3
|
module Cleanup
|
4
4
|
def external_terms_boilerplate(sources)
|
5
|
-
|
6
|
-
@external_terms_boilerplate.gsub(/%/, sources || "???"),
|
5
|
+
@i18n.l10n(
|
6
|
+
@i18n.external_terms_boilerplate.gsub(/%/, sources || "???"),
|
7
7
|
@lang, @script)
|
8
8
|
end
|
9
9
|
|
10
10
|
def internal_external_terms_boilerplate(sources)
|
11
|
-
|
12
|
-
@internal_external_terms_boilerplate.gsub(/%/, sources || "??"),
|
11
|
+
@i18n.l10n(
|
12
|
+
@i18n.internal_external_terms_boilerplate.gsub(/%/, sources || "??"),
|
13
13
|
@lang, @script)
|
14
14
|
end
|
15
15
|
|
16
16
|
def term_defs_boilerplate(div, source, term, preface, isodoc)
|
17
|
-
div.next =
|
17
|
+
a = @i18n.term_def_boilerplate and div.next = a
|
18
18
|
source.each do |s|
|
19
19
|
@anchors[s["bibitemid"]] or
|
20
20
|
@log.add("Crossreferences", nil, "term source #{s['bibitemid']} not referenced")
|
21
21
|
end
|
22
22
|
if source.empty? && term.nil?
|
23
|
-
div.next = @no_terms_boilerplate
|
23
|
+
div.next = @i18n.no_terms_boilerplate
|
24
24
|
else
|
25
25
|
div.next = term_defs_boilerplate_cont(source, term, isodoc)
|
26
26
|
end
|
@@ -30,7 +30,7 @@ module Asciidoctor
|
|
30
30
|
sources = isodoc.sentence_join(src.map do |s|
|
31
31
|
%{<eref bibitemid="#{s['bibitemid']}"/>}
|
32
32
|
end)
|
33
|
-
if src.empty? then @internal_terms_boilerplate
|
33
|
+
if src.empty? then @i18n.internal_terms_boilerplate
|
34
34
|
elsif term.nil? then external_terms_boilerplate(sources)
|
35
35
|
else
|
36
36
|
internal_external_terms_boilerplate(sources)
|
@@ -42,7 +42,7 @@ module Asciidoctor
|
|
42
42
|
["reference", "bibitem"].include? e.name
|
43
43
|
end
|
44
44
|
f.at("./title").next =
|
45
|
-
"<p>#{(refs.empty? ? @norm_empty_pref : @norm_with_refs_pref)}</p>"
|
45
|
+
"<p>#{(refs.empty? ? @i18n.norm_empty_pref : @i18n.norm_with_refs_pref)}</p>"
|
46
46
|
end
|
47
47
|
|
48
48
|
TERM_CLAUSE = "//sections/terms | "\
|
@@ -54,13 +54,9 @@ module Asciidoctor
|
|
54
54
|
x = xmldoc.dup
|
55
55
|
x.root.add_namespace(nil, self.class::XML_NAMESPACE)
|
56
56
|
xml = Nokogiri::XML(x.to_xml)
|
57
|
-
|
58
|
-
@
|
59
|
-
@
|
60
|
-
conv.i18n_init(@lang, @script)
|
61
|
-
conv.metadata_init(@lang, @script, conv.labels)
|
62
|
-
conv.info(xml, nil)
|
63
|
-
conv
|
57
|
+
@isodoc ||= isodoc(@lang, @script)
|
58
|
+
@isodoc.info(xml, nil)
|
59
|
+
@isodoc
|
64
60
|
end
|
65
61
|
|
66
62
|
def boilerplate_cleanup(xmldoc)
|
@@ -83,15 +79,6 @@ module Asciidoctor
|
|
83
79
|
preface.previous = b
|
84
80
|
end
|
85
81
|
|
86
|
-
class EmptyAttr
|
87
|
-
def attr(_x)
|
88
|
-
nil
|
89
|
-
end
|
90
|
-
def attributes
|
91
|
-
{}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
82
|
def boilerplate_file(xmldoc)
|
96
83
|
File.join(@libdir, "boilerplate.xml")
|
97
84
|
end
|
@@ -117,7 +117,8 @@ module Asciidoctor
|
|
117
117
|
def concept_termbase_cleanup(x)
|
118
118
|
text = x&.children&.first&.remove&.text
|
119
119
|
termbase, key = x["key"].split(/:/, 2)
|
120
|
-
x.add_child(%(<termref base="#{termbase}" target="#{key}"
|
120
|
+
x.add_child(%(<termref base="#{termbase}" target="#{key}">) +
|
121
|
+
"#{text}</termref>")
|
121
122
|
end
|
122
123
|
|
123
124
|
def concept_xref_cleanup(x)
|
@@ -129,6 +130,61 @@ module Asciidoctor
|
|
129
130
|
x.children = "<eref>#{x.children.to_xml}</eref>"
|
130
131
|
extract_localities(x.first_element_child)
|
131
132
|
end
|
133
|
+
|
134
|
+
NAMECHAR = "\u0000-\u0022\u0024\u002c\u002f\u003a-\u0040\\u005b-\u005e"\
|
135
|
+
"\u0060\u007b-\u00b6\u00b8-\u00bf\u00d7\u00f7\u037e\u2000-\u200b"\
|
136
|
+
"\u200e-\u203e\u2041-\u206f\u2190-\u2bff\u2ff0-\u3000".freeze
|
137
|
+
#"\ud800-\uf8ff\ufdd0-\ufdef\ufffe-\uffff".freeze
|
138
|
+
NAMESTARTCHAR = "\\u002d\u002e\u0030-\u0039\u00b7\u0300-\u036f"\
|
139
|
+
"\u203f-\u2040".freeze
|
140
|
+
|
141
|
+
def to_ncname(s)
|
142
|
+
start = s[0]
|
143
|
+
ret1 = %r([#{NAMECHAR}#]).match(start) ? "_" :
|
144
|
+
(%r([#{NAMESTARTCHAR}#]).match(start) ? "_#{start}" : start)
|
145
|
+
ret = ret1 + s[1..-1].gsub(%r([#{NAMECHAR}#]), "_")
|
146
|
+
ret
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_xreftarget(s)
|
150
|
+
return to_ncname(s) unless /^[^#]+#.+$/.match(s)
|
151
|
+
/^(?<pref>[^#]+)#(?<suff>.+)$/ =~ s
|
152
|
+
pref = pref.gsub(%r([#{NAMECHAR}]), "_")
|
153
|
+
suff = suff.gsub(%r([#{NAMECHAR}]), "_")
|
154
|
+
"#{pref}##{suff}"
|
155
|
+
end
|
156
|
+
|
157
|
+
IDREF = "//*/@id | //review/@from | //review/@to | "\
|
158
|
+
"//callout/@target | //citation/@bibitemid | //eref/@bibitemid".freeze
|
159
|
+
|
160
|
+
def anchor_cleanup(x)
|
161
|
+
anchor_cleanup1(x)
|
162
|
+
xreftarget_cleanup(x)
|
163
|
+
end
|
164
|
+
|
165
|
+
def anchor_cleanup1(x)
|
166
|
+
x.xpath(IDREF).each do |s|
|
167
|
+
if (ret = to_ncname(s.value)) != (orig = s.value)
|
168
|
+
s.value = ret
|
169
|
+
output = s.parent.dup
|
170
|
+
output.children.remove
|
171
|
+
@log.add("Anchors", s.parent, "normalised identifier in #{output} "\
|
172
|
+
"from #{orig}")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def xreftarget_cleanup(x)
|
178
|
+
x.xpath("//xref/@target").each do |s|
|
179
|
+
if (ret = to_xreftarget(s.value)) != (orig = s.value)
|
180
|
+
s.value = ret
|
181
|
+
output = s.parent.dup
|
182
|
+
output.children.remove
|
183
|
+
@log.add("Anchors", s.parent, "normalised identifier in #{output} "\
|
184
|
+
"from #{orig}")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
132
188
|
end
|
133
189
|
end
|
134
190
|
end
|
@@ -50,7 +50,8 @@ module Asciidoctor
|
|
50
50
|
# only numeric references are renumbered
|
51
51
|
def biblio_renumber(xmldoc)
|
52
52
|
r = xmldoc.at("//references[@normative = 'false'] | "\
|
53
|
-
"//clause[.//references[@normative = 'false']]
|
53
|
+
"//clause[.//references[@normative = 'false']] | "\
|
54
|
+
"//annex[.//references[@normative = 'false']]") or return
|
54
55
|
r.xpath(".//bibitem[not(ancestor::bibitem)]").each_with_index do |b, i|
|
55
56
|
next unless docid = b.at("./docidentifier[@type = 'metanorma']")
|
56
57
|
next unless /^\[\d+\]$/.match(docid.text)
|
@@ -132,15 +133,17 @@ module Asciidoctor
|
|
132
133
|
end
|
133
134
|
|
134
135
|
def validate_ref_dl(bib, c)
|
135
|
-
|
136
|
+
id = bib["id"]
|
137
|
+
id ||= c["id"] unless /^_/.match(c["id"]) # do not accept implicit id
|
138
|
+
unless id
|
136
139
|
@log.add("Anchors", c, "The following reference is missing "\
|
137
|
-
|
140
|
+
"an anchor:\n" + c.to_xml)
|
138
141
|
return
|
139
142
|
end
|
140
|
-
bib["title"] or @log.add("Bibliography", c, "Reference #{
|
141
|
-
|
142
|
-
bib["docid"] or @log.add("Bibliography", c, "Reference #{
|
143
|
-
|
143
|
+
bib["title"] or @log.add("Bibliography", c, "Reference #{id} "\
|
144
|
+
"is missing a title")
|
145
|
+
bib["docid"] or @log.add("Bibliography", c, "Reference #{id} "\
|
146
|
+
"is missing a document identifier (docid)")
|
144
147
|
end
|
145
148
|
|
146
149
|
def extract_from_p(tag, bib, key)
|
@@ -200,7 +203,9 @@ module Asciidoctor
|
|
200
203
|
end
|
201
204
|
if !nested and c.at("./title")
|
202
205
|
title = c.at("./title").remove.children.to_xml
|
203
|
-
bib["title"] = bib["title"]
|
206
|
+
bib["title"] = [bib["title"]] if bib["title"].is_a? Hash
|
207
|
+
bib["title"] = [bib["title"]] if bib["title"].is_a? String
|
208
|
+
bib["title"] = [] unless bib["title"]
|
204
209
|
bib["title"] << title if !title.empty?
|
205
210
|
end
|
206
211
|
bib
|
@@ -39,6 +39,7 @@ module Asciidoctor
|
|
39
39
|
dupabstract.traverse { |n| n.remove_attribute("id") }
|
40
40
|
dupabstract.remove_attribute("language")
|
41
41
|
dupabstract.remove_attribute("script")
|
42
|
+
dupabstract&.at("./title")&.remove
|
42
43
|
bibabstract.next = dupabstract
|
43
44
|
end
|
44
45
|
end
|
@@ -105,6 +106,7 @@ module Asciidoctor
|
|
105
106
|
def sections_cleanup(x)
|
106
107
|
sections_order_cleanup(x)
|
107
108
|
sections_level_cleanup(x)
|
109
|
+
sections_names_cleanup(x)
|
108
110
|
end
|
109
111
|
|
110
112
|
def obligations_cleanup(x)
|
@@ -118,15 +120,15 @@ module Asciidoctor
|
|
118
120
|
(s = x.at("//introduction")) && s["obligation"] = "informative"
|
119
121
|
(s = x.at("//acknowledgements")) && s["obligation"] = "informative"
|
120
122
|
x.xpath("//references").each { |r| r["obligation"] = "informative" }
|
121
|
-
x.xpath("//preface//clause").each
|
123
|
+
x.xpath("//preface//clause").each do |r|
|
124
|
+
r["obligation"] = "informative"
|
125
|
+
end
|
122
126
|
end
|
123
127
|
|
124
128
|
def obligations_cleanup_norm(x)
|
125
|
-
(s = x.at("//clause[
|
126
|
-
(s = x.at("//clause[title = 'Symbols and Abbreviated Terms']")) &&
|
127
|
-
s["obligation"] = "normative"
|
129
|
+
(s = x.at("//clause[@type = 'scope']")) && s["obligation"] = "normative"
|
128
130
|
x.xpath("//terms").each { |r| r["obligation"] = "normative" }
|
129
|
-
x.xpath("//
|
131
|
+
x.xpath("//definitions").each { |r| r["obligation"] = "normative" }
|
130
132
|
end
|
131
133
|
|
132
134
|
def obligations_cleanup_inherit(x)
|
@@ -139,16 +141,98 @@ module Asciidoctor
|
|
139
141
|
end
|
140
142
|
|
141
143
|
def clausebefore_cleanup(xmldoc)
|
144
|
+
preface_clausebefore_cleanup(xmldoc)
|
145
|
+
sections_clausebefore_cleanup(xmldoc)
|
146
|
+
end
|
147
|
+
|
148
|
+
def preface_clausebefore_cleanup(xmldoc)
|
149
|
+
return unless xmldoc.at("//preface")
|
150
|
+
unless ins = xmldoc.at("//preface").children.first
|
151
|
+
xmldoc.at("//preface") << " "
|
152
|
+
ins = xmldoc.at("//preface").children.first
|
153
|
+
end
|
154
|
+
xmldoc.xpath("//preface//*[@beforeclauses = 'true']").each do |x|
|
155
|
+
x.delete("beforeclauses")
|
156
|
+
ins.previous = x.remove
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def sections_clausebefore_cleanup(xmldoc)
|
142
161
|
return unless xmldoc.at("//sections")
|
143
162
|
unless ins = xmldoc.at("//sections").children.first
|
144
163
|
xmldoc.at("//sections") << " "
|
145
164
|
ins = xmldoc.at("//sections").children.first
|
146
165
|
end
|
147
|
-
xmldoc.xpath("//*[@beforeclauses = 'true']").each do |x|
|
166
|
+
xmldoc.xpath("//sections//*[@beforeclauses = 'true']").each do |x|
|
148
167
|
x.delete("beforeclauses")
|
149
168
|
ins.previous = x.remove
|
150
169
|
end
|
151
170
|
end
|
171
|
+
|
172
|
+
def get_or_make_title(node)
|
173
|
+
unless node.at("./title")
|
174
|
+
if node.children.empty?
|
175
|
+
node << "<title/>"
|
176
|
+
else
|
177
|
+
node.children.first.previous = "<title/>"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
node.at("./title")
|
181
|
+
end
|
182
|
+
|
183
|
+
def replace_title(doc, xpath, text, first = false)
|
184
|
+
return unless text
|
185
|
+
doc.xpath(xpath).each_with_index do |node, i|
|
186
|
+
next if first && !i.zero?
|
187
|
+
title = get_or_make_title(node)
|
188
|
+
fn = title.xpath("./fn")
|
189
|
+
fn.each { |n| n.remove }
|
190
|
+
title.content = text
|
191
|
+
fn.each { |n| title << n }
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def sections_names_cleanup(x)
|
196
|
+
replace_title(x, "//clause[@type = 'scope']", @i18n&.scope)
|
197
|
+
replace_title(x, "//preface//abstract", @i18n&.abstract)
|
198
|
+
replace_title(x, "//foreword", @i18n&.foreword)
|
199
|
+
replace_title(x, "//introduction", @i18n&.introduction)
|
200
|
+
replace_title(x, "//acknowledgements", @i18n&.acknowledgements)
|
201
|
+
section_names_refs_cleanup(x)
|
202
|
+
section_names_terms_cleanup(x)
|
203
|
+
end
|
204
|
+
|
205
|
+
def section_names_refs_cleanup(x)
|
206
|
+
replace_title(x, "//references[@normative = 'true']",
|
207
|
+
@i18n&.normref, true)
|
208
|
+
replace_title(x, "//references[@normative = 'false']",
|
209
|
+
@i18n&.bibliography, true)
|
210
|
+
end
|
211
|
+
|
212
|
+
NO_SYMABBR = "[.//definitions[not(@type)]]"
|
213
|
+
SYMABBR = "[.//definitions[@type = 'symbols']"\
|
214
|
+
"[@type = 'abbreviated_terms']]".freeze
|
215
|
+
SYMnoABBR = "[.//definitions[@type = 'symbols']"\
|
216
|
+
"[not(@type = 'abbreviated_terms')]]".freeze
|
217
|
+
ABBRnoSYM = "[.//definitions[not(@type = 'symbols')]"\
|
218
|
+
"[@type = 'abbreviated_terms']]".freeze
|
219
|
+
|
220
|
+
def section_names_terms_cleanup(x)
|
221
|
+
replace_title(x, "//definitions[@type = 'symbols']", @i18n&.symbols)
|
222
|
+
replace_title(x, "//definitions[@type = 'abbreviated_terms']", @i18n&.abbrev)
|
223
|
+
replace_title(x, "//definitions[not(@type)]", @i18n&.symbolsabbrev)
|
224
|
+
replace_title(x, "//terms#{SYMnoABBR} | //clause[.//terms]#{SYMnoABBR}",
|
225
|
+
@i18n&.termsdefsymbols, true)
|
226
|
+
replace_title(x, "//terms#{ABBRnoSYM} | //clause[.//terms]#{ABBRnoSYM}",
|
227
|
+
@i18n&.termsdefabbrev, true)
|
228
|
+
replace_title(x, "//terms#{SYMABBR} | //clause[.//terms]#{SYMABBR}",
|
229
|
+
@i18n&.termsdefsymbolsabbrev, true)
|
230
|
+
replace_title(x, "//terms#{NO_SYMABBR} | //clause[.//terms]#{NO_SYMABBR}",
|
231
|
+
@i18n&.termsdefsymbolsabbrev, true)
|
232
|
+
replace_title(
|
233
|
+
x, "//terms[not(.//definitions)] | //clause[.//terms][not(.//definitions)]",
|
234
|
+
@i18n&.termsdef, true)
|
235
|
+
end
|
152
236
|
end
|
153
237
|
end
|
154
238
|
end
|