metanorma-standoc 1.11.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +3 -31
- data/.gitignore +23 -0
- data/Gemfile +2 -0
- data/lib/asciidoctor/standoc/base.rb +2 -241
- data/lib/asciidoctor/standoc/blocks.rb +2 -238
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -100
- data/lib/asciidoctor/standoc/cleanup.rb +2 -207
- data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
- data/lib/asciidoctor/standoc/cleanup_block.rb +2 -173
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -204
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +2 -108
- data/lib/asciidoctor/standoc/cleanup_image.rb +2 -69
- data/lib/asciidoctor/standoc/cleanup_inline.rb +2 -179
- data/lib/asciidoctor/standoc/cleanup_maths.rb +2 -221
- data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -169
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +2 -93
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -110
- data/lib/asciidoctor/standoc/cleanup_section.rb +2 -184
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -91
- data/lib/asciidoctor/standoc/cleanup_symbols.rb +2 -47
- data/lib/asciidoctor/standoc/cleanup_table.rb +2 -67
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -113
- data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -161
- data/lib/asciidoctor/standoc/cleanup_text.rb +2 -95
- data/lib/asciidoctor/standoc/cleanup_toc.rb +3 -0
- data/lib/asciidoctor/standoc/cleanup_xref.rb +2 -106
- data/lib/asciidoctor/standoc/converter.rb +2 -123
- data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +2 -56
- data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +2 -102
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +3 -404
- data/lib/asciidoctor/standoc/deprecated.rb +5 -0
- data/lib/asciidoctor/standoc/front.rb +2 -219
- data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
- data/lib/asciidoctor/standoc/inline.rb +2 -229
- data/lib/asciidoctor/standoc/lists.rb +2 -119
- data/lib/asciidoctor/standoc/macros.rb +2 -203
- data/lib/asciidoctor/standoc/macros_form.rb +2 -62
- data/lib/asciidoctor/standoc/macros_note.rb +2 -44
- data/lib/asciidoctor/standoc/macros_plantuml.rb +2 -112
- data/lib/asciidoctor/standoc/macros_terms.rb +2 -180
- data/lib/asciidoctor/standoc/ref.rb +2 -225
- data/lib/asciidoctor/standoc/ref_sect.rb +2 -143
- data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
- data/lib/asciidoctor/standoc/render.rb +3 -0
- data/lib/asciidoctor/standoc/reqt.rb +2 -89
- data/lib/asciidoctor/standoc/section.rb +2 -190
- data/lib/asciidoctor/standoc/table.rb +2 -84
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +2 -178
- data/lib/asciidoctor/standoc/terms.rb +2 -153
- data/lib/asciidoctor/standoc/utils.rb +2 -116
- data/lib/asciidoctor/standoc/validate.rb +2 -157
- data/lib/asciidoctor/standoc/validate_section.rb +2 -54
- data/lib/isodoc/html/htmlstyle.css +20 -11
- data/lib/isodoc/html/htmlstyle.scss +11 -11
- data/lib/metanorma/standoc/base.rb +149 -0
- data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +0 -0
- data/lib/metanorma/standoc/blocks.rb +239 -0
- data/lib/metanorma/standoc/blocks_notes.rb +101 -0
- data/lib/metanorma/standoc/cleanup.rb +146 -0
- data/lib/metanorma/standoc/cleanup_amend.rb +54 -0
- data/lib/metanorma/standoc/cleanup_block.rb +173 -0
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +213 -0
- data/lib/metanorma/standoc/cleanup_footnotes.rb +109 -0
- data/lib/metanorma/standoc/cleanup_image.rb +70 -0
- data/lib/metanorma/standoc/cleanup_inline.rb +190 -0
- data/lib/metanorma/standoc/cleanup_maths.rb +222 -0
- data/lib/metanorma/standoc/cleanup_ref.rb +170 -0
- data/lib/metanorma/standoc/cleanup_ref_dl.rb +104 -0
- data/lib/metanorma/standoc/cleanup_reqt.rb +111 -0
- data/lib/metanorma/standoc/cleanup_section.rb +212 -0
- data/lib/metanorma/standoc/cleanup_section_names.rb +92 -0
- data/lib/metanorma/standoc/cleanup_symbols.rb +48 -0
- data/lib/metanorma/standoc/cleanup_table.rb +68 -0
- data/lib/metanorma/standoc/cleanup_terms.rb +140 -0
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +199 -0
- data/lib/metanorma/standoc/cleanup_text.rb +96 -0
- data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
- data/lib/metanorma/standoc/cleanup_xref.rb +107 -0
- data/lib/metanorma/standoc/converter.rb +124 -0
- data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +57 -0
- data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +103 -0
- data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +409 -0
- data/lib/metanorma/standoc/front.rb +224 -0
- data/lib/metanorma/standoc/front_contributor.rb +192 -0
- data/lib/metanorma/standoc/inline.rb +232 -0
- data/lib/{asciidoctor → metanorma}/standoc/isodoc.rng +90 -18
- data/lib/metanorma/standoc/lists.rb +120 -0
- data/lib/metanorma/standoc/macros.rb +204 -0
- data/lib/metanorma/standoc/macros_form.rb +63 -0
- data/lib/metanorma/standoc/macros_note.rb +45 -0
- data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
- data/lib/metanorma/standoc/macros_terms.rb +181 -0
- data/lib/metanorma/standoc/ref.rb +243 -0
- data/lib/metanorma/standoc/ref_sect.rb +153 -0
- data/lib/metanorma/standoc/ref_utility.rb +129 -0
- data/lib/metanorma/standoc/render.rb +115 -0
- data/lib/metanorma/standoc/reqt.rb +90 -0
- data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
- data/lib/metanorma/standoc/section.rb +209 -0
- data/lib/metanorma/standoc/table.rb +85 -0
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +179 -0
- data/lib/metanorma/standoc/terms.rb +160 -0
- data/lib/metanorma/standoc/utils.rb +101 -0
- data/lib/metanorma/standoc/validate.rb +158 -0
- data/lib/metanorma/standoc/validate_section.rb +55 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
- data/lib/metanorma-standoc.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/{asciidoctor → metanorma}/base_spec.rb +73 -8
- data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/blocks_spec.rb +49 -20
- data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +25 -1
- data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +2 -2
- data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +9 -9
- data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +528 -91
- data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +22 -22
- data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +17 -17
- data/spec/{asciidoctor → metanorma}/inline_spec.rb +175 -6
- data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +5 -9
- data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
- data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
- data/spec/{asciidoctor → metanorma}/macros_spec.rb +8 -8
- data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
- data/spec/metanorma/refs_dl_spec.rb +863 -0
- data/spec/{asciidoctor → metanorma}/refs_spec.rb +1277 -687
- data/spec/{asciidoctor → metanorma}/section_spec.rb +90 -3
- data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +179 -179
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +98 -98
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +111 -111
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
- 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 +89 -38
- data/lib/asciidoctor/standoc/ref_date_id.rb +0 -62
- data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -0,0 +1,239 @@
|
|
1
|
+
require "htmlentities"
|
2
|
+
require "uri" if /^2\./.match?(RUBY_VERSION)
|
3
|
+
require_relative "./blocks_notes"
|
4
|
+
|
5
|
+
module Metanorma
|
6
|
+
module Standoc
|
7
|
+
module Blocks
|
8
|
+
def id_attr(node = nil)
|
9
|
+
{ id: Metanorma::Utils::anchor_or_uuid(node),
|
10
|
+
tag: node&.attr("tag"),
|
11
|
+
"multilingual-rendering": node&.attr("multilingual-rendering") }
|
12
|
+
end
|
13
|
+
|
14
|
+
def id_unnum_attrs(node)
|
15
|
+
attr_code(id_attr(node).merge(
|
16
|
+
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
17
|
+
number: node.attr("number"),
|
18
|
+
subsequence: node.attr("subsequence"),
|
19
|
+
))
|
20
|
+
end
|
21
|
+
|
22
|
+
def formula_attrs(node)
|
23
|
+
attr_code(id_unnum_attrs(node)
|
24
|
+
.merge(keep_attrs(node).merge(
|
25
|
+
inequality: node.option?("inequality") ? "true" : nil,
|
26
|
+
)))
|
27
|
+
end
|
28
|
+
|
29
|
+
def keep_attrs(node)
|
30
|
+
{ "keep-with-next": node.attr("keep-with-next"),
|
31
|
+
"keep-lines-together": node.attr("keep-lines-together") }
|
32
|
+
end
|
33
|
+
|
34
|
+
# We append each contained block to its parent
|
35
|
+
def open(node)
|
36
|
+
role = node.role || node.attr("style")
|
37
|
+
reqt_subpart(role) and return requirement_subpart(node)
|
38
|
+
role == "form" and return form(node)
|
39
|
+
role == "definition" and return termdefinition(node)
|
40
|
+
result = []
|
41
|
+
node.blocks.each do |b|
|
42
|
+
result << send(b.context, b)
|
43
|
+
end
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
def form(node)
|
48
|
+
noko do |xml|
|
49
|
+
xml.form **attr_code(id_attr(node)
|
50
|
+
.merge(class: node.attr("class"),
|
51
|
+
name: node.attr("name"), action: node.attr("action"))) do |f|
|
52
|
+
f << node.content
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def literal_attrs(node)
|
58
|
+
attr_code(id_attr(node).merge(keep_attrs(node)))
|
59
|
+
end
|
60
|
+
|
61
|
+
def literal(node)
|
62
|
+
noko do |xml|
|
63
|
+
xml.figure **literal_attrs(node) do |f|
|
64
|
+
figure_title(node, f)
|
65
|
+
f.pre node.lines.join("\n"),
|
66
|
+
**attr_code(id: Metanorma::Utils::anchor_or_uuid,
|
67
|
+
alt: node.attr("alt"))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# NOTE: html escaping is performed by Nokogiri
|
73
|
+
def stem(node)
|
74
|
+
noko do |xml|
|
75
|
+
xml.formula **formula_attrs(node) do |s|
|
76
|
+
stem_parse(node.lines.join("\n"), s, node.style.to_sym)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def term_example(node)
|
82
|
+
noko do |xml|
|
83
|
+
xml.termexample **attr_code(id_attr(node)) do |ex|
|
84
|
+
wrap_in_para(node, ex)
|
85
|
+
end
|
86
|
+
end.join("\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
def example(node)
|
90
|
+
return term_example(node) if in_terms?
|
91
|
+
|
92
|
+
role = node.role || node.attr("style")
|
93
|
+
%w(recommendation requirement permission).include?(role) and
|
94
|
+
return requirement(node, role)
|
95
|
+
return pseudocode_example(node) if role == "pseudocode"
|
96
|
+
return svgmap_example(node) if role == "svgmap"
|
97
|
+
return form(node) if role == "form"
|
98
|
+
return termdefinition(node) if role == "definition"
|
99
|
+
|
100
|
+
reqt_subpart(role) and return requirement_subpart(node)
|
101
|
+
example_proper(node)
|
102
|
+
end
|
103
|
+
|
104
|
+
def svgmap_attrs(node)
|
105
|
+
attr_code(id_attr(node)
|
106
|
+
.merge(id: node.id,
|
107
|
+
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
108
|
+
number: node.attr("number"),
|
109
|
+
subsequence: node.attr("subsequence"))
|
110
|
+
.merge(keep_attrs(node)))
|
111
|
+
end
|
112
|
+
|
113
|
+
def svgmap_example(node)
|
114
|
+
noko do |xml|
|
115
|
+
xml.svgmap **attr_code(svgmap_attrs(node).merge(
|
116
|
+
src: node.attr("src"), alt: node.attr("alt"),
|
117
|
+
)) do |ex|
|
118
|
+
figure_title(node, ex)
|
119
|
+
ex << node.content
|
120
|
+
end
|
121
|
+
end.join("\n")
|
122
|
+
end
|
123
|
+
|
124
|
+
# prevent A's and other subs inappropriate for pseudocode
|
125
|
+
def pseudocode_example(node)
|
126
|
+
node.blocks.each { |b| b.remove_sub(:replacements) }
|
127
|
+
noko do |xml|
|
128
|
+
xml.figure **example_attrs(node).merge(class: "pseudocode") do |ex|
|
129
|
+
figure_title(node, ex)
|
130
|
+
wrap_in_para(node, ex)
|
131
|
+
end
|
132
|
+
end.join("\n")
|
133
|
+
end
|
134
|
+
|
135
|
+
def example_attrs(node)
|
136
|
+
attr_code(id_unnum_attrs(node).merge(keep_attrs(node)))
|
137
|
+
end
|
138
|
+
|
139
|
+
def example_proper(node)
|
140
|
+
noko do |xml|
|
141
|
+
xml.example **example_attrs(node) do |ex|
|
142
|
+
node.title.nil? or ex.name { |name| name << node.title }
|
143
|
+
wrap_in_para(node, ex)
|
144
|
+
end
|
145
|
+
end.join("\n")
|
146
|
+
end
|
147
|
+
|
148
|
+
def figure_title(node, out)
|
149
|
+
return if node.title.nil?
|
150
|
+
|
151
|
+
out.name { |name| name << node.title }
|
152
|
+
end
|
153
|
+
|
154
|
+
def figure_attrs(node)
|
155
|
+
attr_code(id_unnum_attrs(node).merge(keep_attrs(node)))
|
156
|
+
end
|
157
|
+
|
158
|
+
def image(node)
|
159
|
+
noko do |xml|
|
160
|
+
xml.figure **figure_attrs(node) do |f|
|
161
|
+
figure_title(node, f)
|
162
|
+
f.image **image_attributes(node)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def para_attrs(node)
|
168
|
+
attr_code(id_attr(node).merge(keep_attrs(node)
|
169
|
+
.merge(align: node.attr("align"),
|
170
|
+
variant_title: node.role == "variant-title" ? true : nil,
|
171
|
+
type: node.attr("type"))))
|
172
|
+
end
|
173
|
+
|
174
|
+
def paragraph(node)
|
175
|
+
return termsource(node) if node.role == "source"
|
176
|
+
|
177
|
+
noko do |xml|
|
178
|
+
xml.p **para_attrs(node) do |xml_t|
|
179
|
+
xml_t << node.content
|
180
|
+
end
|
181
|
+
end.join("\n")
|
182
|
+
end
|
183
|
+
|
184
|
+
def quote_attrs(node)
|
185
|
+
attr_code(id_attr(node).merge(keep_attrs(node))
|
186
|
+
.merge(align: node.attr("align")))
|
187
|
+
end
|
188
|
+
|
189
|
+
def quote_attribution(node, out)
|
190
|
+
if node.attr("citetitle")
|
191
|
+
m = /^(?<cite>[^,]+)(,(?<text>.*$))?$/m.match node.attr("citetitle")
|
192
|
+
out.source **attr_code(target: m[:cite], type: "inline") do |s|
|
193
|
+
s << m[:text]
|
194
|
+
end
|
195
|
+
end
|
196
|
+
node.attr("attribution") and
|
197
|
+
out.author { |a| a << node.attr("attribution") }
|
198
|
+
end
|
199
|
+
|
200
|
+
def quote(node)
|
201
|
+
noko do |xml|
|
202
|
+
xml.quote **quote_attrs(node) do |q|
|
203
|
+
quote_attribution(node, q)
|
204
|
+
wrap_in_para(node, q)
|
205
|
+
end
|
206
|
+
end.join("\n")
|
207
|
+
end
|
208
|
+
|
209
|
+
def listing_attrs(node)
|
210
|
+
attr_code(id_attr(node).merge(keep_attrs(node)
|
211
|
+
.merge(lang: node.attr("language"),
|
212
|
+
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
213
|
+
number: node.attr("number"),
|
214
|
+
filename: node.attr("filename"))))
|
215
|
+
end
|
216
|
+
|
217
|
+
# NOTE: html escaping is performed by Nokogiri
|
218
|
+
def listing(node)
|
219
|
+
fragment = ::Nokogiri::XML::Builder.new do |xml|
|
220
|
+
xml.sourcecode **listing_attrs(node) do |s|
|
221
|
+
figure_title(node, s)
|
222
|
+
s << node.content
|
223
|
+
end
|
224
|
+
end
|
225
|
+
fragment.to_xml(encoding: "US-ASCII", save_with:
|
226
|
+
Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
227
|
+
end
|
228
|
+
|
229
|
+
def pass(node)
|
230
|
+
noko do |xml|
|
231
|
+
xml.passthrough **attr_code(formats:
|
232
|
+
node.attr("format") || "metanorma") do |p|
|
233
|
+
p << HTMLEntities.new.encode(node.content, :basic, :hexadecimal)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Standoc
|
3
|
+
module Blocks
|
4
|
+
def termnote_attrs(node)
|
5
|
+
attr_code(id_attr(node).merge(keep_attrs(node)
|
6
|
+
.merge(
|
7
|
+
unnumbered: node.attr("unnumbered"),
|
8
|
+
number: node.attr("number"),
|
9
|
+
subsequence: node.attr("subsequence"),
|
10
|
+
"keep-separate": node.attr("keep-separate"),
|
11
|
+
)))
|
12
|
+
end
|
13
|
+
|
14
|
+
def note_attrs(node)
|
15
|
+
attr_code(
|
16
|
+
termnote_attrs(node).merge(
|
17
|
+
type: node.attr("type"),
|
18
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
|
19
|
+
),
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def sidebar_attrs(node)
|
24
|
+
todo_attrs(node).merge(
|
25
|
+
attr_code(
|
26
|
+
from: node.attr("from"),
|
27
|
+
to: node.attr("to") || node.attr("from"),
|
28
|
+
),
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sidebar(node)
|
33
|
+
return unless draft?
|
34
|
+
|
35
|
+
noko do |xml|
|
36
|
+
xml.review **sidebar_attrs(node) do |r|
|
37
|
+
wrap_in_para(node, r)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def todo_attrs(node)
|
43
|
+
date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
|
44
|
+
date += "T00:00:00Z" unless /T/.match? date
|
45
|
+
attr_code(id_attr(node)
|
46
|
+
.merge(reviewer: node.attr("reviewer") || node.attr("source") ||
|
47
|
+
"(Unknown)",
|
48
|
+
date: date))
|
49
|
+
end
|
50
|
+
|
51
|
+
def todo(node)
|
52
|
+
noko do |xml|
|
53
|
+
xml.review **todo_attrs(node) do |r|
|
54
|
+
wrap_in_para(node, r)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def termnote(node)
|
60
|
+
noko do |xml|
|
61
|
+
xml.termnote **termnote_attrs(node) do |ex|
|
62
|
+
wrap_in_para(node, ex)
|
63
|
+
end
|
64
|
+
end.join("\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
def note(node)
|
68
|
+
noko do |xml|
|
69
|
+
xml.note **note_attrs(node) do |c|
|
70
|
+
wrap_in_para(node, c)
|
71
|
+
end
|
72
|
+
end.join("\n")
|
73
|
+
end
|
74
|
+
|
75
|
+
def admonition_attrs(node)
|
76
|
+
name = node.attr("name")
|
77
|
+
a = node.attr("type") and ["danger", "safety precautions"].each do |t|
|
78
|
+
name = t if a.casecmp(t).zero?
|
79
|
+
end
|
80
|
+
attr_code(keep_attrs(node).merge(id_attr(node)
|
81
|
+
.merge(
|
82
|
+
type: name,
|
83
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil,
|
84
|
+
)))
|
85
|
+
end
|
86
|
+
|
87
|
+
def admonition(node)
|
88
|
+
return termnote(node) if in_terms?
|
89
|
+
return note(node) if node.attr("name") == "note"
|
90
|
+
return todo(node) if node.attr("name") == "todo"
|
91
|
+
|
92
|
+
noko do |xml|
|
93
|
+
xml.admonition **admonition_attrs(node) do |a|
|
94
|
+
node.title.nil? or a.name { |name| name << node.title }
|
95
|
+
wrap_in_para(node, a)
|
96
|
+
end
|
97
|
+
end.join("\n")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "pathname"
|
3
|
+
require "html2doc"
|
4
|
+
require_relative "./cleanup_block"
|
5
|
+
require_relative "./cleanup_table"
|
6
|
+
require_relative "./cleanup_footnotes"
|
7
|
+
require_relative "./cleanup_ref"
|
8
|
+
require_relative "./cleanup_ref_dl"
|
9
|
+
require_relative "./cleanup_boilerplate"
|
10
|
+
require_relative "./cleanup_section"
|
11
|
+
require_relative "./cleanup_terms"
|
12
|
+
require_relative "./cleanup_symbols"
|
13
|
+
require_relative "./cleanup_xref"
|
14
|
+
require_relative "./cleanup_inline"
|
15
|
+
require_relative "./cleanup_amend"
|
16
|
+
require_relative "./cleanup_maths"
|
17
|
+
require_relative "./cleanup_image"
|
18
|
+
require_relative "./cleanup_reqt"
|
19
|
+
require_relative "./cleanup_text"
|
20
|
+
require_relative "./cleanup_toc"
|
21
|
+
require "relaton_iev"
|
22
|
+
|
23
|
+
module Metanorma
|
24
|
+
module Standoc
|
25
|
+
module Cleanup
|
26
|
+
def cleanup(xmldoc)
|
27
|
+
element_name_cleanup(xmldoc)
|
28
|
+
sections_cleanup(xmldoc)
|
29
|
+
obligations_cleanup(xmldoc)
|
30
|
+
table_cleanup(xmldoc)
|
31
|
+
formula_cleanup(xmldoc)
|
32
|
+
form_cleanup(xmldoc)
|
33
|
+
sourcecode_cleanup(xmldoc)
|
34
|
+
figure_cleanup(xmldoc)
|
35
|
+
element_name_cleanup(xmldoc)
|
36
|
+
ref_cleanup(xmldoc)
|
37
|
+
note_cleanup(xmldoc)
|
38
|
+
clausebefore_cleanup(xmldoc)
|
39
|
+
floatingtitle_cleanup(xmldoc)
|
40
|
+
bibitem_cleanup(xmldoc)
|
41
|
+
normref_cleanup(xmldoc)
|
42
|
+
biblio_cleanup(xmldoc)
|
43
|
+
reference_names(xmldoc)
|
44
|
+
symbols_cleanup(xmldoc)
|
45
|
+
xref_cleanup(xmldoc)
|
46
|
+
concept_cleanup(xmldoc)
|
47
|
+
related_cleanup(xmldoc)
|
48
|
+
origin_cleanup(xmldoc)
|
49
|
+
bookmark_cleanup(xmldoc)
|
50
|
+
termdef_cleanup(xmldoc)
|
51
|
+
RelatonIev::iev_cleanup(xmldoc, @bibdb)
|
52
|
+
element_name_cleanup(xmldoc)
|
53
|
+
index_cleanup(xmldoc)
|
54
|
+
bpart_cleanup(xmldoc)
|
55
|
+
quotesource_cleanup(xmldoc)
|
56
|
+
callout_cleanup(xmldoc)
|
57
|
+
footnote_cleanup(xmldoc)
|
58
|
+
mathml_cleanup(xmldoc)
|
59
|
+
script_cleanup(xmldoc)
|
60
|
+
docidentifier_cleanup(xmldoc)
|
61
|
+
requirement_cleanup(xmldoc)
|
62
|
+
bibdata_cleanup(xmldoc)
|
63
|
+
svgmap_cleanup(xmldoc)
|
64
|
+
boilerplate_cleanup(xmldoc)
|
65
|
+
toc_cleanup(xmldoc)
|
66
|
+
smartquotes_cleanup(xmldoc)
|
67
|
+
variant_cleanup(xmldoc)
|
68
|
+
para_cleanup(xmldoc)
|
69
|
+
empty_element_cleanup(xmldoc)
|
70
|
+
img_cleanup(xmldoc)
|
71
|
+
anchor_cleanup(xmldoc)
|
72
|
+
xmldoc
|
73
|
+
end
|
74
|
+
|
75
|
+
def docidentifier_cleanup(xmldoc); end
|
76
|
+
|
77
|
+
TEXT_ELEMS =
|
78
|
+
%w{status language script version author name callout phone email
|
79
|
+
street city state country postcode identifier referenceFrom surname
|
80
|
+
referenceTo docidentifier docnumber prefix initial addition forename
|
81
|
+
title draft secretariat title-main title-intro title-part
|
82
|
+
verbal-definition non-verbal-representation}.freeze
|
83
|
+
|
84
|
+
# it seems Nokogiri::XML is treating the content of <script> as cdata,
|
85
|
+
# because of its use in HTML. Bad nokogiri. Undoing that, since we use
|
86
|
+
# script as a normal tag
|
87
|
+
def script_cleanup(xmldoc)
|
88
|
+
xmldoc.xpath("//script").each { |x| x.content = x.to_str }
|
89
|
+
end
|
90
|
+
|
91
|
+
def empty_element_cleanup(xmldoc)
|
92
|
+
xmldoc.xpath("//#{TEXT_ELEMS.join(' | //')}").each do |x|
|
93
|
+
next if x.name == "name" && x.parent.name == "expression"
|
94
|
+
|
95
|
+
x.remove if x.children.empty?
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def element_name_cleanup(xmldoc)
|
100
|
+
xmldoc.traverse { |n| n.name = n.name.gsub(/_/, "-") }
|
101
|
+
end
|
102
|
+
|
103
|
+
# allows us to deal with doc relation localities,
|
104
|
+
# temporarily stashed to "bpart"
|
105
|
+
def bpart_cleanup(xmldoc)
|
106
|
+
xmldoc.xpath("//relation/bpart").each do |x|
|
107
|
+
extract_localities(x)
|
108
|
+
x.replace(x.children)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def variant_cleanup(xmldoc)
|
113
|
+
variant_space_cleanup(xmldoc)
|
114
|
+
xmldoc.xpath("//*[variant]").each do |c|
|
115
|
+
next unless c.children.any? do |n|
|
116
|
+
n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
|
117
|
+
end
|
118
|
+
|
119
|
+
variant_cleanup1(c)
|
120
|
+
end
|
121
|
+
xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
|
122
|
+
end
|
123
|
+
|
124
|
+
def variant_cleanup1(elem)
|
125
|
+
elem.xpath("./variant").each do |n|
|
126
|
+
if n.at_xpath("preceding-sibling::node()"\
|
127
|
+
"[not(self::text()[not(normalize-space())])][1]"\
|
128
|
+
"[self::variantwrap]")
|
129
|
+
n.previous_element << n
|
130
|
+
else
|
131
|
+
n.replace("<variantwrap/>").first << n
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def variant_space_cleanup(xmldoc)
|
137
|
+
xmldoc.xpath("//*[variant]").each do |c|
|
138
|
+
if c&.next&.text? && c&.next&.next&.name == "variant"
|
139
|
+
c.next.text.gsub(/\s/, "").empty? and
|
140
|
+
c.next.remove
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Standoc
|
3
|
+
module Cleanup
|
4
|
+
def change_clauses(x)
|
5
|
+
x.xpath("//clause[@change]").each do |c|
|
6
|
+
a = create_amend(c)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_amend(c)
|
11
|
+
a = c.add_child("<amend id='_#{UUIDTools::UUID.random_create}'/>").first
|
12
|
+
c.elements.each do |e|
|
13
|
+
e.parent = a unless %w(amend title).include? e.name
|
14
|
+
end
|
15
|
+
create_amend1(c, a)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_amend1(c, a)
|
19
|
+
create_amend2(c, a)
|
20
|
+
d = a.at("./description")
|
21
|
+
d.xpath(".//autonumber").each { |e| d.previous = e }
|
22
|
+
d.xpath(".//p[normalize-space(.)='']").each { |e| e.remove }
|
23
|
+
move_attrs_to_amend(c, a)
|
24
|
+
a
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_amend2(c, a)
|
28
|
+
q = a.at("./quote") and q.name = "newcontent"
|
29
|
+
if q.nil?
|
30
|
+
a.children = "<description>#{a.children.to_xml}</description>"
|
31
|
+
else
|
32
|
+
pre = q&.xpath("./preceding-sibling::*")&.remove
|
33
|
+
post = q&.xpath("./following-sibling::*")&.remove
|
34
|
+
pre.empty? or a << "<description>#{pre.to_xml}</description>"
|
35
|
+
a << q.remove
|
36
|
+
post.empty? or a << "<description>#{post.to_xml}</description>"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def move_attrs_to_amend(c, a)
|
41
|
+
%w(change path path_end title).each do |e|
|
42
|
+
next unless c[e]
|
43
|
+
a[e] = c[e]
|
44
|
+
c.delete(e)
|
45
|
+
end
|
46
|
+
return unless a["locality"]
|
47
|
+
loc = a.children.add_previous_sibling("<location/>")
|
48
|
+
extract_localities1(loc, a["locality"])
|
49
|
+
loc1 = loc.at("./localityStack") and loc.replace(loc1.elements)
|
50
|
+
a.delete("locality")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|