metanorma-standoc 1.9.0 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asciidoctor/standoc/base.rb +28 -35
- data/lib/asciidoctor/standoc/blocks.rb +7 -6
- data/lib/asciidoctor/standoc/blocks_notes.rb +20 -14
- data/lib/asciidoctor/standoc/cleanup.rb +32 -78
- data/lib/asciidoctor/standoc/cleanup_block.rb +44 -84
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +9 -7
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
- data/lib/asciidoctor/standoc/cleanup_maths.rb +36 -27
- data/lib/asciidoctor/standoc/cleanup_ref.rb +21 -13
- 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 +5 -0
- data/lib/asciidoctor/standoc/front.rb +35 -18
- data/lib/asciidoctor/standoc/front_contributor.rb +5 -5
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/ref.rb +87 -112
- data/lib/asciidoctor/standoc/ref_date_id.rb +62 -0
- data/lib/asciidoctor/standoc/utils.rb +32 -6
- data/lib/asciidoctor/standoc/validate.rb +12 -12
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- data/spec/asciidoctor/base_spec.rb +60 -7
- data/spec/asciidoctor/cleanup_spec.rb +2 -6
- data/spec/asciidoctor/refs_spec.rb +1 -1
- data/spec/spec_helper.rb +11 -9
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03a2df03031208cf9cd54413c1dc342f748c3978a2e189f9cf4ae369fcc1820c
|
4
|
+
data.tar.gz: fc94c4cc2a0e117c06f41d709d8e5d6a6f3f0ba6e1ffc8a6ccdfb60b91ed3ffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32bac104b6523e30e510ada3e1e25861139b62c66c8d7bbcb782284648622b5f1da48acd8a6e97f511ead0baca45c7903ac7f31c1023596becc473d08deea87f
|
7
|
+
data.tar.gz: 4c0ee4e816c81ca1e98d5bbbb47ad2c755feca016c0b5ddae5283688291813e0d1d511444835d7bee1979dc49ef3d664a7d1966938b46b3a5ad0f2dd9a0da6d2
|
@@ -108,10 +108,15 @@ module Asciidoctor
|
|
108
108
|
@draft = node.attributes.has_key?("draft")
|
109
109
|
@novalid = node.attr("novalid")
|
110
110
|
@smartquotes = node.attr("smartquotes") != "false"
|
111
|
-
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
111
|
+
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
112
|
+
node.attr("mn-keep-asciimath") != "false"
|
112
113
|
@fontheader = default_fonts(node)
|
113
114
|
@files_to_delete = []
|
114
|
-
|
115
|
+
if node.attr("docfile")
|
116
|
+
@filename = File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
|
117
|
+
else
|
118
|
+
@filename = ""
|
119
|
+
end
|
115
120
|
@localdir = Metanorma::Utils::localdir(node)
|
116
121
|
@output_dir = outputdir node
|
117
122
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
@@ -143,10 +148,12 @@ module Asciidoctor
|
|
143
148
|
end
|
144
149
|
|
145
150
|
def outputs(node, ret)
|
146
|
-
File.open(@filename
|
147
|
-
presentation_xml_converter(node).convert(@filename
|
148
|
-
html_converter(node).convert(@filename
|
149
|
-
|
151
|
+
File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
|
152
|
+
presentation_xml_converter(node).convert("#{@filename}.xml")
|
153
|
+
html_converter(node).convert("#{@filename}.presentation.xml",
|
154
|
+
nil, false, "#{@filename}.html")
|
155
|
+
doc_converter(node).convert("#{@filename}.presentation.xml",
|
156
|
+
nil, false, "#{@filename}.doc")
|
150
157
|
end
|
151
158
|
|
152
159
|
def document(node)
|
@@ -163,12 +170,21 @@ module Asciidoctor
|
|
163
170
|
end
|
164
171
|
|
165
172
|
def clean_exit
|
166
|
-
@log.write(@output_dir
|
173
|
+
@log.write("#{@output_dir}#{@filename}.err") unless @novalid
|
174
|
+
|
167
175
|
@files_to_delete.each { |f| FileUtils.rm f }
|
168
176
|
end
|
169
177
|
|
178
|
+
def clean_abort(msg, file = nil)
|
179
|
+
file and
|
180
|
+
File.open("#{@filename}.xml.abort", "w:UTF-8") { |f| f.write(file) }
|
181
|
+
clean_exit
|
182
|
+
abort(msg)
|
183
|
+
end
|
184
|
+
|
170
185
|
def makexml1(node)
|
171
|
-
result = ["<?xml version='1.0' encoding='UTF-8'?>",
|
186
|
+
result = ["<?xml version='1.0' encoding='UTF-8'?>",
|
187
|
+
"<#{xml_root_tag} type='semantic' version='#{version}'>"]
|
172
188
|
result << noko { |ixml| front node, ixml }
|
173
189
|
result << noko { |ixml| middle node, ixml }
|
174
190
|
result << "</#{xml_root_tag}>"
|
@@ -203,36 +219,13 @@ module Asciidoctor
|
|
203
219
|
end
|
204
220
|
end
|
205
221
|
|
206
|
-
def default_script(lang)
|
207
|
-
case lang
|
208
|
-
when "ar", "fa"
|
209
|
-
"Arab"
|
210
|
-
when "ur"
|
211
|
-
"Aran"
|
212
|
-
when "ru", "bg"
|
213
|
-
"Cyrl"
|
214
|
-
when "hi"
|
215
|
-
"Deva"
|
216
|
-
when "el"
|
217
|
-
"Grek"
|
218
|
-
when "zh"
|
219
|
-
"Hans"
|
220
|
-
when "ko"
|
221
|
-
"Kore"
|
222
|
-
when "he"
|
223
|
-
"Hebr"
|
224
|
-
when "ja"
|
225
|
-
"Jpan"
|
226
|
-
else
|
227
|
-
"Latn"
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
222
|
private
|
232
223
|
|
233
224
|
def outputdir(node)
|
234
|
-
if node.attr("output_dir").nil_or_empty?
|
235
|
-
|
225
|
+
if node.attr("output_dir").nil_or_empty?
|
226
|
+
Metanorma::Utils::localdir(node)
|
227
|
+
else
|
228
|
+
File.join(node.attr("output_dir"), "")
|
236
229
|
end
|
237
230
|
end
|
238
231
|
end
|
@@ -140,13 +140,14 @@ module Asciidoctor
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def para_attrs(node)
|
143
|
-
attr_code(keep_attrs(node)
|
144
|
-
|
145
|
-
|
143
|
+
attr_code(keep_attrs(node)
|
144
|
+
.merge(align: node.attr("align"),
|
145
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
146
146
|
end
|
147
147
|
|
148
148
|
def paragraph(node)
|
149
149
|
return termsource(node) if node.role == "source"
|
150
|
+
|
150
151
|
noko do |xml|
|
151
152
|
xml.p **para_attrs(node) do |xml_t|
|
152
153
|
xml_t << node.content
|
@@ -155,9 +156,9 @@ module Asciidoctor
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def quote_attrs(node)
|
158
|
-
attr_code(keep_attrs(node)
|
159
|
-
|
160
|
-
|
159
|
+
attr_code(keep_attrs(node)
|
160
|
+
.merge(align: node.attr("align"),
|
161
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
161
162
|
end
|
162
163
|
|
163
164
|
def quote_attribution(node, out)
|
@@ -12,9 +12,11 @@ module Asciidoctor
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def note_attrs(node)
|
15
|
-
attr_code(termnote_attrs(node)
|
16
|
-
|
17
|
-
|
15
|
+
attr_code(termnote_attrs(node)
|
16
|
+
.merge(
|
17
|
+
type: node.attr("type"),
|
18
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
|
19
|
+
))
|
18
20
|
end
|
19
21
|
|
20
22
|
def sidebar_attrs(node)
|
@@ -24,6 +26,7 @@ module Asciidoctor
|
|
24
26
|
|
25
27
|
def sidebar(node)
|
26
28
|
return unless draft?
|
29
|
+
|
27
30
|
noko do |xml|
|
28
31
|
xml.review **(sidebar_attrs(node)) do |r|
|
29
32
|
wrap_in_para(node, r)
|
@@ -33,33 +36,34 @@ module Asciidoctor
|
|
33
36
|
|
34
37
|
def todo_attrs(node)
|
35
38
|
date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
|
36
|
-
date += "T00:00:00Z" unless /T/.match date
|
39
|
+
date += "T00:00:00Z" unless /T/.match? date
|
37
40
|
attr_code(
|
38
41
|
id: ::Metanorma::Utils::anchor_or_uuid(node),
|
39
42
|
reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
|
40
|
-
date: date
|
43
|
+
date: date
|
44
|
+
)
|
41
45
|
end
|
42
46
|
|
43
47
|
def todo(node)
|
44
48
|
noko do |xml|
|
45
|
-
xml.review **
|
49
|
+
xml.review **todo_attrs(node) do |r|
|
46
50
|
wrap_in_para(node, r)
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
|
-
def termnote(
|
55
|
+
def termnote(node)
|
52
56
|
noko do |xml|
|
53
|
-
xml.termnote **termnote_attrs(
|
54
|
-
wrap_in_para(
|
57
|
+
xml.termnote **termnote_attrs(node) do |ex|
|
58
|
+
wrap_in_para(node, ex)
|
55
59
|
end
|
56
60
|
end.join("\n")
|
57
61
|
end
|
58
62
|
|
59
|
-
def note(
|
63
|
+
def note(node)
|
60
64
|
noko do |xml|
|
61
|
-
xml.note **note_attrs(
|
62
|
-
wrap_in_para(
|
65
|
+
xml.note **note_attrs(node) do |c|
|
66
|
+
wrap_in_para(node, c)
|
63
67
|
end
|
64
68
|
end.join("\n")
|
65
69
|
end
|
@@ -69,14 +73,16 @@ module Asciidoctor
|
|
69
73
|
a = node.attr("type") and ["danger", "safety precautions"].each do |t|
|
70
74
|
name = t if a.casecmp(t).zero?
|
71
75
|
end
|
72
|
-
attr_code(keep_attrs(node)
|
73
|
-
|
76
|
+
attr_code(keep_attrs(node)
|
77
|
+
.merge(id: Metanorma::Utils::anchor_or_uuid(node), type: name,
|
78
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
|
74
79
|
end
|
75
80
|
|
76
81
|
def admonition(node)
|
77
82
|
return termnote(node) if in_terms?
|
78
83
|
return note(node) if node.attr("name") == "note"
|
79
84
|
return todo(node) if node.attr("name") == "todo"
|
85
|
+
|
80
86
|
noko do |xml|
|
81
87
|
xml.admonition **admonition_attrs(node) do |a|
|
82
88
|
node.title.nil? or a.name { |name| name << node.title }
|
@@ -2,27 +2,29 @@ require "nokogiri"
|
|
2
2
|
require "pathname"
|
3
3
|
require "open-uri"
|
4
4
|
require "html2doc"
|
5
|
-
require_relative "./cleanup_block
|
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_inline
|
13
|
-
require_relative "./cleanup_amend
|
14
|
-
require_relative "./cleanup_maths
|
5
|
+
require_relative "./cleanup_block"
|
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_inline"
|
13
|
+
require_relative "./cleanup_amend"
|
14
|
+
require_relative "./cleanup_maths"
|
15
|
+
require_relative "./cleanup_image"
|
16
|
+
require_relative "./cleanup_reqt"
|
15
17
|
require "relaton_iev"
|
16
18
|
|
17
19
|
module Asciidoctor
|
18
20
|
module Standoc
|
19
21
|
module Cleanup
|
20
22
|
def textcleanup(result)
|
21
|
-
text = result.flatten.map { |l| l.sub(/\s*$/, "") }
|
23
|
+
text = result.flatten.map { |l| l.sub(/\s*$/, "") } * "\n"
|
22
24
|
!@keepasciimath and text = asciimath2mathml(text)
|
23
25
|
text = text.gsub(/\s+<fn /, "<fn ")
|
24
26
|
text.gsub(%r{<passthrough\s+formats="metanorma">([^<]*)
|
25
|
-
</passthrough>}mx) {
|
27
|
+
</passthrough>}mx) { HTMLEntities.new.decode($1) }
|
26
28
|
end
|
27
29
|
|
28
30
|
def cleanup(xmldoc)
|
@@ -73,22 +75,24 @@ module Asciidoctor
|
|
73
75
|
xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
|
74
76
|
xmldoc.traverse do |n|
|
75
77
|
next unless n.text?
|
78
|
+
|
76
79
|
if @smartquotes
|
77
80
|
/[-'"(<>]|\.\.|\dx/.match(n) or next
|
78
|
-
|
81
|
+
|
82
|
+
n.ancestors("pre, tt, sourcecode, bibdata, on, "\
|
83
|
+
"stem, figure[@class = 'pseudocode']").empty? or next
|
79
84
|
n.replace(Metanorma::Utils::smartformat(n.text))
|
80
85
|
else
|
81
|
-
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))
|
82
|
-
#gsub(/</, "<").gsub(/>/, ">"))
|
86
|
+
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
|
87
|
+
# gsub(/</, "<").gsub(/>/, ">"))
|
83
88
|
end
|
84
89
|
end
|
85
90
|
end
|
86
91
|
|
87
|
-
def docidentifier_cleanup(xmldoc)
|
88
|
-
end
|
92
|
+
def docidentifier_cleanup(xmldoc); end
|
89
93
|
|
90
94
|
TEXT_ELEMS =
|
91
|
-
%w{status language script version author name callout phone email
|
95
|
+
%w{status language script version author name callout phone email
|
92
96
|
street city state country postcode identifier referenceFrom surname
|
93
97
|
referenceTo docidentifier docnumber prefix initial addition forename
|
94
98
|
title draft secretariat title-main title-intro title-part}.freeze
|
@@ -110,57 +114,6 @@ module Asciidoctor
|
|
110
114
|
xmldoc.traverse { |n| n.name = n.name.gsub(/_/, "-") }
|
111
115
|
end
|
112
116
|
|
113
|
-
def link_callouts_to_annotations(callouts, annotations)
|
114
|
-
callouts.each_with_index do |c, i|
|
115
|
-
c["target"] = "_" + UUIDTools::UUID.random_create
|
116
|
-
annotations[i]["id"] = c["target"]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def align_callouts_to_annotations(xmldoc)
|
121
|
-
xmldoc.xpath("//sourcecode").each do |x|
|
122
|
-
callouts = x.elements.select { |e| e.name == "callout" }
|
123
|
-
annotations = x.elements.select { |e| e.name == "annotation" }
|
124
|
-
callouts.size == annotations.size and
|
125
|
-
link_callouts_to_annotations(callouts, annotations)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def merge_annotations_into_sourcecode(xmldoc)
|
130
|
-
xmldoc.xpath("//sourcecode").each do |x|
|
131
|
-
while x&.next_element&.name == "annotation"
|
132
|
-
x.next_element.parent = x
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def callout_cleanup(xmldoc)
|
138
|
-
merge_annotations_into_sourcecode(xmldoc)
|
139
|
-
align_callouts_to_annotations(xmldoc)
|
140
|
-
end
|
141
|
-
|
142
|
-
def sourcecode_cleanup(xmldoc)
|
143
|
-
xmldoc.xpath("//sourcecode").each do |x|
|
144
|
-
x.traverse do |n|
|
145
|
-
next unless n.text?
|
146
|
-
next unless /#{Regexp.escape(@sourcecode_markup_start)}/.match(n.text)
|
147
|
-
n.replace(sourcecode_markup(n))
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def sourcecode_markup(n)
|
153
|
-
acc = []
|
154
|
-
n.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|#{Regexp.escape(@sourcecode_markup_end)})/).
|
155
|
-
each_slice(4).map do |a|
|
156
|
-
acc << Nokogiri::XML::Text.new(a[0], n.document).
|
157
|
-
to_xml(encoding: "US-ASCII", save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
158
|
-
next unless a.size == 4
|
159
|
-
acc << Asciidoctor.convert(a[2], backend: (self&.backend&.to_sym || :standoc), doctype: :inline)
|
160
|
-
end
|
161
|
-
acc.join
|
162
|
-
end
|
163
|
-
|
164
117
|
# allows us to deal with doc relation localities,
|
165
118
|
# temporarily stashed to "bpart"
|
166
119
|
def bpart_cleanup(xmldoc)
|
@@ -170,23 +123,24 @@ module Asciidoctor
|
|
170
123
|
end
|
171
124
|
end
|
172
125
|
|
173
|
-
def img_cleanup(xmldoc)
|
174
|
-
return xmldoc unless @datauriimage
|
175
|
-
xmldoc.xpath("//image").each { |i| i["src"] = Metanorma::Utils::datauri(i["src"], @localdir) }
|
176
|
-
end
|
177
|
-
|
178
126
|
def variant_cleanup(xmldoc)
|
179
127
|
xmldoc.xpath("//*[variant]").each do |c|
|
180
|
-
c&.next&.text? && c&.next&.next&.name == "variant" &&
|
128
|
+
c&.next&.text? && c&.next&.next&.name == "variant" &&
|
129
|
+
c.next.text.gsub(/\s/, "").empty? and
|
181
130
|
c.next.remove
|
182
131
|
end
|
183
132
|
xmldoc.xpath("//*[variant]").each do |c|
|
184
|
-
next unless c.children.any?
|
133
|
+
next unless c.children.any? do |n|
|
134
|
+
n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
|
135
|
+
end
|
136
|
+
|
185
137
|
c.xpath("./variant").each do |n|
|
186
|
-
if n.at_xpath(
|
138
|
+
if n.at_xpath("preceding-sibling::node()"\
|
139
|
+
"[not(self::text()[not(normalize-space())])][1]"\
|
140
|
+
"[self::variantwrap]")
|
187
141
|
n.previous_element << n
|
188
142
|
else
|
189
|
-
n.replace(
|
143
|
+
n.replace("<variantwrap/>").first << n
|
190
144
|
end
|
191
145
|
end
|
192
146
|
end
|
@@ -40,6 +40,7 @@ module Asciidoctor
|
|
40
40
|
def insert_thead(s)
|
41
41
|
thead = s.at("./thead")
|
42
42
|
return thead unless thead.nil?
|
43
|
+
|
43
44
|
if tname = s.at("./name")
|
44
45
|
thead = tname.add_next_sibling("<thead/>").first
|
45
46
|
return thead
|
@@ -80,21 +81,21 @@ module Asciidoctor
|
|
80
81
|
end
|
81
82
|
|
82
83
|
# include where definition list inside stem block
|
83
|
-
def formula_cleanup(
|
84
|
-
formula_cleanup_where1(
|
85
|
-
formula_cleanup_where2(
|
84
|
+
def formula_cleanup(formula)
|
85
|
+
formula_cleanup_where1(formula)
|
86
|
+
formula_cleanup_where2(formula)
|
86
87
|
end
|
87
88
|
|
88
|
-
def formula_cleanup_where1(
|
89
|
+
def formula_cleanup_where1(formula)
|
89
90
|
q = "//formula/following-sibling::*[1][self::dl]"
|
90
|
-
|
91
|
+
formula.xpath(q).each do |s|
|
91
92
|
s["key"] == "true" and s.previous_element << s.remove
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
95
|
-
def formula_cleanup_where2(
|
96
|
+
def formula_cleanup_where2(formula)
|
96
97
|
q = "//formula/following-sibling::*[1][self::p]"
|
97
|
-
|
98
|
+
formula.xpath(q).each do |s|
|
98
99
|
if s.text =~ /^\s*where[^a-z]*$/i && s&.next_element&.name == "dl"
|
99
100
|
s.next_element["key"] = "true"
|
100
101
|
s.previous_element << s.next_element.remove
|
@@ -125,9 +126,10 @@ module Asciidoctor
|
|
125
126
|
# examples containing only figures become subfigures of figures
|
126
127
|
def subfigure_cleanup(xmldoc)
|
127
128
|
xmldoc.xpath("//example[figure]").each do |e|
|
128
|
-
next unless e.elements.map
|
129
|
+
next unless e.elements.map(&:name).reject do |m|
|
129
130
|
%w(name figure).include? m
|
130
131
|
end.empty?
|
132
|
+
|
131
133
|
e.name = "figure"
|
132
134
|
end
|
133
135
|
end
|
@@ -150,6 +152,7 @@ module Asciidoctor
|
|
150
152
|
xmldoc.xpath(q).each do |n|
|
151
153
|
next if n["keep-separate"] == "true"
|
152
154
|
next unless n.ancestors("table").empty?
|
155
|
+
|
153
156
|
prev = n.previous_element || next
|
154
157
|
n.parent = prev if ELEMS_ALLOW_NOTES.include? prev.name
|
155
158
|
end
|
@@ -159,100 +162,57 @@ module Asciidoctor
|
|
159
162
|
end
|
160
163
|
end
|
161
164
|
|
162
|
-
def
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
def requirement_inherit(x)
|
168
|
-
x.xpath("//requirement | //recommendation | //permission").each do |r|
|
169
|
-
ins = r.at("./classification") ||
|
170
|
-
r.at("./description | ./measurementtarget | ./specification | "\
|
171
|
-
"./verification | ./import | ./description | ./requirement | "\
|
172
|
-
"./recommendation | ./permission")
|
173
|
-
r.xpath("./*//inherit").each { |i| ins.previous = i }
|
165
|
+
def link_callouts_to_annotations(callouts, annotations)
|
166
|
+
callouts.each_with_index do |c, i|
|
167
|
+
c["target"] = "_" + UUIDTools::UUID.random_create
|
168
|
+
annotations[i]["id"] = c["target"]
|
174
169
|
end
|
175
170
|
end
|
176
171
|
|
177
|
-
def
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
e.before(t)
|
184
|
-
t.children = e.remove
|
185
|
-
end
|
186
|
-
end
|
187
|
-
requirement_cleanup1(r)
|
172
|
+
def align_callouts_to_annotations(xmldoc)
|
173
|
+
xmldoc.xpath("//sourcecode").each do |x|
|
174
|
+
callouts = x.elements.select { |e| e.name == "callout" }
|
175
|
+
annotations = x.elements.select { |e| e.name == "annotation" }
|
176
|
+
callouts.size == annotations.size and
|
177
|
+
link_callouts_to_annotations(callouts, annotations)
|
188
178
|
end
|
189
179
|
end
|
190
180
|
|
191
|
-
def
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
end
|
197
|
-
r.xpath("./description[normalize-space(.)='']").each do |d|
|
198
|
-
d.replace("\n")
|
181
|
+
def merge_annotations_into_sourcecode(xmldoc)
|
182
|
+
xmldoc.xpath("//sourcecode").each do |x|
|
183
|
+
while x&.next_element&.name == "annotation"
|
184
|
+
x.next_element.parent = x
|
185
|
+
end
|
199
186
|
end
|
200
187
|
end
|
201
188
|
|
202
|
-
def
|
203
|
-
|
204
|
-
|
205
|
-
Metanorma::Utils::svgmap_rewrite(xmldoc, @localdir)
|
189
|
+
def callout_cleanup(xmldoc)
|
190
|
+
merge_annotations_into_sourcecode(xmldoc)
|
191
|
+
align_callouts_to_annotations(xmldoc)
|
206
192
|
end
|
207
193
|
|
208
|
-
def
|
209
|
-
|
210
|
-
|
211
|
-
|
194
|
+
def sourcecode_cleanup(xmldoc)
|
195
|
+
xmldoc.xpath("//sourcecode").each do |x|
|
196
|
+
x.traverse do |n|
|
197
|
+
next unless n.text?
|
198
|
+
next unless /#{Regexp.escape(@sourcecode_markup_start)}/.match?(n.text)
|
212
199
|
|
213
|
-
|
214
|
-
xmldoc.xpath("//svgmap").each do |s|
|
215
|
-
f = s.at(".//figure") or next
|
216
|
-
if t = s.at("./name") and !f.at("./name")
|
217
|
-
f.children.first.previous = t.remove
|
218
|
-
end
|
219
|
-
if s["id"] && guid?(f["id"])
|
220
|
-
f["id"] = s["id"]
|
221
|
-
s.delete("id")
|
200
|
+
n.replace(sourcecode_markup(n))
|
222
201
|
end
|
223
|
-
svgmap_moveattrs1(s, f)
|
224
202
|
end
|
225
203
|
end
|
226
204
|
|
227
|
-
def
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
end
|
235
|
-
|
236
|
-
def svgmap_populate(xmldoc)
|
237
|
-
xmldoc.xpath("//svgmap").each do |s|
|
238
|
-
s1 = s.dup
|
239
|
-
s.children.remove
|
240
|
-
f = s1.at(".//figure") and s << f
|
241
|
-
s1.xpath(".//li").each do |li|
|
242
|
-
t = li&.at(".//eref | .//link | .//xref") or next
|
243
|
-
href = t.xpath("./following-sibling::node()")
|
244
|
-
href.empty? or
|
245
|
-
s << %[<target href="#{svgmap_target(href)}">#{t.to_xml}</target>]
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
205
|
+
def sourcecode_markup(n)
|
206
|
+
acc = []
|
207
|
+
n.text.split(/(#{Regexp.escape(@sourcecode_markup_start)}|#{Regexp.escape(@sourcecode_markup_end)})/)
|
208
|
+
.each_slice(4).map do |a|
|
209
|
+
acc << Nokogiri::XML::Text.new(a[0], n.document)
|
210
|
+
.to_xml(encoding: "US-ASCII", save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION)
|
211
|
+
next unless a.size == 4
|
249
212
|
|
250
|
-
|
251
|
-
nodeset.each do |n|
|
252
|
-
next unless n.name == "link"
|
253
|
-
n.children = n["target"]
|
213
|
+
acc << Asciidoctor.convert(a[2], backend: (self&.backend&.to_sym || :standoc), doctype: :inline)
|
254
214
|
end
|
255
|
-
|
215
|
+
acc.join
|
256
216
|
end
|
257
217
|
end
|
258
218
|
end
|