metanorma-standoc 1.8.1 → 1.8.6
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 +11 -41
- data/.rubocop.yml +1 -1
- data/lib/asciidoctor/standoc/base.rb +4 -2
- data/lib/asciidoctor/standoc/blocks.rb +16 -7
- data/lib/asciidoctor/standoc/cleanup.rb +26 -73
- data/lib/asciidoctor/standoc/cleanup_block.rb +36 -24
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +3 -3
- data/lib/asciidoctor/standoc/cleanup_inline.rb +4 -3
- data/lib/asciidoctor/standoc/cleanup_maths.rb +123 -0
- data/lib/asciidoctor/standoc/cleanup_ref.rb +4 -13
- data/lib/asciidoctor/standoc/cleanup_section.rb +5 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -2
- data/lib/asciidoctor/standoc/inline.rb +7 -15
- data/lib/asciidoctor/standoc/isodoc.rng +105 -2
- data/lib/asciidoctor/standoc/section.rb +9 -0
- data/lib/asciidoctor/standoc/utils.rb +0 -24
- data/lib/asciidoctor/standoc/validate.rb +16 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/{asciidoctor-standoc → asciidoctor}/base_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/blocks_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/cleanup_sections_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/cleanup_spec.rb +303 -10
- data/spec/{asciidoctor-standoc → asciidoctor}/datamodel/attributes_table_preprocessor_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/datamodel/diagram_preprocessor_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/inline_spec.rb +2 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/isobib_cache_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/lists_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_json2text_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_lutaml_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_plantuml_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_yaml2text_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/refs_dl_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/refs_spec.rb +163 -141
- data/spec/{asciidoctor-standoc → asciidoctor}/section_spec.rb +17 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/table_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/validate_spec.rb +20 -0
- data/spec/fixtures/action_schemaexpg1.svg +122 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +48 -48
- 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 +31 -31
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +11 -11
- data/spec/vcr_cassettes/isobib_get_124.yml +12 -12
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +94 -30
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
- metadata +37 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d29f898d11836b1b9ae020605081f35a144ed06406a24776b93841d05cafac62
|
4
|
+
data.tar.gz: 5f47fb98bf9189ab80a18fe9f32150e0cf840f6860ec2317147122583748f162
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92cf686a035d48f5b0507d0fffa91b2b207f741cc14a939b498330065e204b6a194bab1b7796115ff790ae0f29e046d7bf429da1dd51b554b5251febd9b350eb
|
7
|
+
data.tar.gz: 91a13d5900acf6099186c51e294dd6f441bd298fdafa958bc53d8a0ef95dbfad4427cfad1464cffb1ced2ae840158cb9364c00249a25595b4cfea9a65d4f2136
|
data/.github/workflows/rake.yml
CHANGED
@@ -16,17 +16,17 @@ jobs:
|
|
16
16
|
strategy:
|
17
17
|
fail-fast: false
|
18
18
|
matrix:
|
19
|
-
ruby: [ '2.6', '2.5', '2.4' ]
|
19
|
+
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
20
20
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
21
|
experimental: [ false ]
|
22
22
|
include:
|
23
|
-
- ruby: '
|
23
|
+
- ruby: '3.0'
|
24
24
|
os: 'ubuntu-latest'
|
25
25
|
experimental: true
|
26
|
-
- ruby: '
|
26
|
+
- ruby: '3.0'
|
27
27
|
os: 'windows-latest'
|
28
28
|
experimental: true
|
29
|
-
- ruby: '
|
29
|
+
- ruby: '3.0'
|
30
30
|
os: 'macos-latest'
|
31
31
|
experimental: true
|
32
32
|
steps:
|
@@ -35,49 +35,19 @@ jobs:
|
|
35
35
|
- uses: ruby/setup-ruby@v1
|
36
36
|
with:
|
37
37
|
ruby-version: ${{ matrix.ruby }}
|
38
|
+
bundler-cache: true
|
38
39
|
|
39
|
-
-
|
40
|
-
run: brew install autoconf automake libtool
|
41
|
-
|
42
|
-
- uses: actions/cache@v2
|
43
|
-
with:
|
44
|
-
path: vendor/bundle
|
45
|
-
key: bundle-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
|
46
|
-
restore-keys: bundle-${{ matrix.os }}-${{ matrix.ruby }}
|
47
|
-
|
48
|
-
- run: bundle config set path 'vendor/bundle'
|
49
|
-
|
50
|
-
- run: bundle install --jobs 4 --retry 3
|
51
|
-
|
52
|
-
- name: install plantuml ubuntu
|
53
|
-
if: matrix.os == 'ubuntu-latest'
|
54
|
-
uses: nick-invision/retry@v1
|
55
|
-
with:
|
56
|
-
polling_interval_seconds: 5
|
57
|
-
timeout_minutes: 5
|
58
|
-
max_attempts: 3
|
59
|
-
command: >
|
60
|
-
sudo apt-get update -y && sudo bash -c
|
61
|
-
"curl -L https://github.com/metanorma/plantuml-install/raw/master/ubuntu.sh | bash"
|
62
|
-
|
63
|
-
- if: matrix.os == 'macos-latest'
|
64
|
-
run: brew install plantuml
|
65
|
-
|
66
|
-
- if: matrix.os == 'windows-latest'
|
67
|
-
run: cinst -y plantuml
|
40
|
+
- uses: metanorma/metanorma-build-scripts/plantuml-setup-action@master
|
68
41
|
|
69
42
|
- run: bundle exec rake
|
70
43
|
|
71
44
|
tests-passed:
|
72
45
|
needs: rake
|
73
46
|
runs-on: ubuntu-latest
|
74
|
-
continue-on-error: true
|
75
47
|
steps:
|
76
|
-
-
|
77
|
-
uses: Sibz/github-status-action@v1
|
48
|
+
- uses: peter-evans/repository-dispatch@v1
|
78
49
|
with:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
sha: ${{ github.event.pull_request.head.sha || github.sha }}
|
50
|
+
token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
|
51
|
+
repository: ${{ github.repository }}
|
52
|
+
event-type: notify
|
53
|
+
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
data/.rubocop.yml
CHANGED
@@ -104,12 +104,14 @@ module Asciidoctor
|
|
104
104
|
@output_dir = outputdir node
|
105
105
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
106
106
|
@no_isobib = node.attr("no-isobib")
|
107
|
+
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
108
|
+
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
107
109
|
@bibdb = nil
|
108
110
|
@seen_headers = []
|
109
111
|
@datauriimage = node.attr("data-uri-image")
|
110
112
|
@boilerplateauthority = node.attr("boilerplate-authority")
|
111
113
|
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
112
|
-
@sourcecode_markup_end = node.attr("sourcecode-markup-
|
114
|
+
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
113
115
|
@log = Metanorma::Utils::Log.new
|
114
116
|
init_bib_caches(node)
|
115
117
|
init_iev_caches(node)
|
@@ -137,7 +139,7 @@ module Asciidoctor
|
|
137
139
|
|
138
140
|
def document(node)
|
139
141
|
init(node)
|
140
|
-
ret = makexml(node).to_xml(indent: 2)
|
142
|
+
ret = makexml(node).to_xml(encoding: "US-ASCII", indent: 2)
|
141
143
|
outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
|
142
144
|
clean_exit
|
143
145
|
ret
|
@@ -74,11 +74,20 @@ module Asciidoctor
|
|
74
74
|
%w(recommendation requirement permission).include?(role) and
|
75
75
|
return requirement(node, role)
|
76
76
|
return pseudocode_example(node) if role == "pseudocode"
|
77
|
+
return svgmap_example(node) if role == "svgmap"
|
77
78
|
example_proper(node)
|
78
79
|
end
|
79
80
|
|
81
|
+
def svgmap_example(node)
|
82
|
+
noko do |xml|
|
83
|
+
xml.svgmap **attr_code(example_attrs(node).merge(src: node.attr("src"), alt: node.attr("alt"))) do |ex|
|
84
|
+
ex << node.content
|
85
|
+
end
|
86
|
+
end.join("\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
# prevent A's and other subs inappropriate for pseudocode
|
80
90
|
def pseudocode_example(node)
|
81
|
-
# prevent A's and other subs inappropriate for pseudocode
|
82
91
|
node.blocks.each { |b| b.remove_sub(:replacements) }
|
83
92
|
noko do |xml|
|
84
93
|
xml.figure **example_attrs(node).merge(class: "pseudocode") do |ex|
|
@@ -121,7 +130,7 @@ module Asciidoctor
|
|
121
130
|
|
122
131
|
def para_attrs(node)
|
123
132
|
attr_code(keep_attrs(node).merge(align: node.attr("align"),
|
124
|
-
|
133
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
125
134
|
end
|
126
135
|
|
127
136
|
def paragraph(node)
|
@@ -135,7 +144,7 @@ module Asciidoctor
|
|
135
144
|
|
136
145
|
def quote_attrs(node)
|
137
146
|
attr_code(keep_attrs(node).merge(align: node.attr("align"),
|
138
|
-
|
147
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
139
148
|
end
|
140
149
|
|
141
150
|
def quote_attribution(node, out)
|
@@ -160,10 +169,10 @@ module Asciidoctor
|
|
160
169
|
|
161
170
|
def listing_attrs(node)
|
162
171
|
attr_code(keep_attrs(node).merge(lang: node.attr("language"),
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
172
|
+
id: Metanorma::Utils::anchor_or_uuid(node),
|
173
|
+
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
174
|
+
number: node.attr("number"),
|
175
|
+
filename: node.attr("filename")))
|
167
176
|
end
|
168
177
|
|
169
178
|
# NOTE: html escaping is performed by Nokogiri
|
@@ -11,6 +11,7 @@ require_relative "./cleanup_section.rb"
|
|
11
11
|
require_relative "./cleanup_terms.rb"
|
12
12
|
require_relative "./cleanup_inline.rb"
|
13
13
|
require_relative "./cleanup_amend.rb"
|
14
|
+
require_relative "./cleanup_maths.rb"
|
14
15
|
require "relaton_iev"
|
15
16
|
|
16
17
|
module Asciidoctor
|
@@ -24,25 +25,15 @@ module Asciidoctor
|
|
24
25
|
</passthrough>}mx) { |m| HTMLEntities.new.decode($1) }
|
25
26
|
end
|
26
27
|
|
27
|
-
def asciimath2mathml(text)
|
28
|
-
text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do |m|
|
29
|
-
"<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
|
30
|
-
end
|
31
|
-
text = Html2Doc.asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"])
|
32
|
-
x = Nokogiri::XML(text)
|
33
|
-
x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
|
34
|
-
y.wrap("<stem type='MathML'></stem>")
|
35
|
-
end
|
36
|
-
x.to_xml
|
37
|
-
end
|
38
|
-
|
39
28
|
def cleanup(xmldoc)
|
40
29
|
element_name_cleanup(xmldoc)
|
41
30
|
sections_cleanup(xmldoc)
|
42
31
|
obligations_cleanup(xmldoc)
|
43
32
|
table_cleanup(xmldoc)
|
44
33
|
formula_cleanup(xmldoc)
|
34
|
+
sourcecode_cleanup(xmldoc)
|
45
35
|
figure_cleanup(xmldoc)
|
36
|
+
element_name_cleanup(xmldoc)
|
46
37
|
ref_cleanup(xmldoc)
|
47
38
|
note_cleanup(xmldoc)
|
48
39
|
clausebefore_cleanup(xmldoc)
|
@@ -67,6 +58,7 @@ module Asciidoctor
|
|
67
58
|
bookmark_cleanup(xmldoc)
|
68
59
|
requirement_cleanup(xmldoc)
|
69
60
|
bibdata_cleanup(xmldoc)
|
61
|
+
svgmap_cleanup(xmldoc)
|
70
62
|
boilerplate_cleanup(xmldoc)
|
71
63
|
smartquotes_cleanup(xmldoc)
|
72
64
|
variant_cleanup(xmldoc)
|
@@ -83,8 +75,7 @@ module Asciidoctor
|
|
83
75
|
next unless n.text?
|
84
76
|
if @smartquotes
|
85
77
|
/[-'"(<>]|\.\.|\dx/.match(n) or next
|
86
|
-
n.ancestors("pre, tt, sourcecode, bibdata, on, "
|
87
|
-
"stem, figure[@class = 'pseudocode']").empty? or next
|
78
|
+
n.ancestors("pre, tt, sourcecode, bibdata, on, stem, figure[@class = 'pseudocode']").empty? or next
|
88
79
|
n.replace(Metanorma::Utils::smartformat(n.text))
|
89
80
|
else
|
90
81
|
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))#.
|
@@ -148,59 +139,26 @@ module Asciidoctor
|
|
148
139
|
align_callouts_to_annotations(xmldoc)
|
149
140
|
end
|
150
141
|
|
151
|
-
def
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
|
160
|
-
|
161
|
-
def mathml_preserve_space(m)
|
162
|
-
m.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
|
163
|
-
x.children = x.children.to_xml.gsub(/^\s/, " ").gsub(/\s$/, " ")
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
def mathml_namespace(stem)
|
168
|
-
stem.xpath("./math", ).each { |x| x.default_namespace = MATHML_NS }
|
169
|
-
end
|
170
|
-
|
171
|
-
def mathml_mi_italics
|
172
|
-
{ uppergreek: true, upperroman: true,
|
173
|
-
lowergreek: true, lowerroman: true }
|
174
|
-
end
|
175
|
-
|
176
|
-
# presuppose multichar mi upright, singlechar mi MathML default italic
|
177
|
-
def mathml_italicise(x)
|
178
|
-
x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]", "m" => MATHML_NS).each do |i|
|
179
|
-
char = HTMLEntities.new.decode(i.text)
|
180
|
-
i["mathvariant"] = "normal" if mi_italicise?(char)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def mi_italicise?(c)
|
185
|
-
return false if c.length > 1
|
186
|
-
if /\p{Greek}/.match(c)
|
187
|
-
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowergreek] ||
|
188
|
-
/\p{Upper}/.match(c) && !mathml_mi_italics[:uppergreek]
|
189
|
-
elsif /\p{Latin}/.match(c)
|
190
|
-
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowerroman] ||
|
191
|
-
/\p{Upper}/.match(c) && !mathml_mi_italics[:upperroman]
|
192
|
-
else
|
193
|
-
false
|
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
|
194
149
|
end
|
195
150
|
end
|
196
151
|
|
197
|
-
def
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
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)
|
203
160
|
end
|
161
|
+
acc.join
|
204
162
|
end
|
205
163
|
|
206
164
|
# allows us to deal with doc relation localities,
|
@@ -214,23 +172,18 @@ module Asciidoctor
|
|
214
172
|
|
215
173
|
def img_cleanup(xmldoc)
|
216
174
|
return xmldoc unless @datauriimage
|
217
|
-
xmldoc.xpath("//image").each
|
218
|
-
i["src"] = datauri(i["src"])
|
219
|
-
end
|
175
|
+
xmldoc.xpath("//image").each { |i| i["src"] = Metanorma::Utils::datauri(i["src"], @localdir) }
|
220
176
|
end
|
221
177
|
|
222
178
|
def variant_cleanup(xmldoc)
|
223
179
|
xmldoc.xpath("//*[variant]").each do |c|
|
224
|
-
c&.next&.text? && c&.next&.next&.name == "variant" &&
|
225
|
-
c.next.
|
180
|
+
c&.next&.text? && c&.next&.next&.name == "variant" && c.next.text.gsub(/\s/, "").empty? and
|
181
|
+
c.next.remove
|
226
182
|
end
|
227
183
|
xmldoc.xpath("//*[variant]").each do |c|
|
228
|
-
next unless c.children.any?
|
229
|
-
n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
|
230
|
-
end
|
184
|
+
next unless c.children.any? { |n| n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?) }
|
231
185
|
c.xpath("./variant").each do |n|
|
232
|
-
if n.at_xpath('preceding-sibling::node()[not(self::text()'
|
233
|
-
'[not(normalize-space())])][1][self::variantwrap]')
|
186
|
+
if n.at_xpath('preceding-sibling::node()[not(self::text()[not(normalize-space())])][1][self::variantwrap]')
|
234
187
|
n.previous_element << n
|
235
188
|
else
|
236
189
|
n.replace('<variantwrap/>').first << n
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require "date"
|
2
2
|
require "htmlentities"
|
3
|
-
require "json"
|
4
3
|
require "open-uri"
|
5
4
|
|
6
5
|
module Asciidoctor
|
@@ -22,9 +21,7 @@ module Asciidoctor
|
|
22
21
|
def dl1_table_cleanup(xmldoc)
|
23
22
|
q = "//table/following-sibling::*[1][self::dl]"
|
24
23
|
xmldoc.xpath(q).each do |s|
|
25
|
-
|
26
|
-
s.previous_element << s.remove
|
27
|
-
end
|
24
|
+
s["key"] == "true" and s.previous_element << s.remove
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
@@ -32,8 +29,7 @@ module Asciidoctor
|
|
32
29
|
def dl2_table_cleanup(xmldoc)
|
33
30
|
q = "//table/following-sibling::*[1][self::p]"
|
34
31
|
xmldoc.xpath(q).each do |s|
|
35
|
-
if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? &&
|
36
|
-
s.next_element.name == "dl"
|
32
|
+
if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? && s.next_element.name == "dl"
|
37
33
|
s.next_element["key"] = "true"
|
38
34
|
s.previous_element << s.next_element.remove
|
39
35
|
s.remove
|
@@ -92,17 +88,14 @@ module Asciidoctor
|
|
92
88
|
def formula_cleanup_where1(x)
|
93
89
|
q = "//formula/following-sibling::*[1][self::dl]"
|
94
90
|
x.xpath(q).each do |s|
|
95
|
-
|
96
|
-
s.previous_element << s.remove
|
97
|
-
end
|
91
|
+
s["key"] == "true" and s.previous_element << s.remove
|
98
92
|
end
|
99
93
|
end
|
100
94
|
|
101
95
|
def formula_cleanup_where2(x)
|
102
96
|
q = "//formula/following-sibling::*[1][self::p]"
|
103
97
|
x.xpath(q).each do |s|
|
104
|
-
if s.text =~ /^\s*where[^a-z]*$/i && !s.next_element.nil? &&
|
105
|
-
s.next_element.name == "dl"
|
98
|
+
if s.text =~ /^\s*where[^a-z]*$/i && !s.next_element.nil? && s.next_element.name == "dl"
|
106
99
|
s.next_element["key"] = "true"
|
107
100
|
s.previous_element << s.next_element.remove
|
108
101
|
s.remove
|
@@ -113,9 +106,7 @@ module Asciidoctor
|
|
113
106
|
def figure_dl_cleanup1(xmldoc)
|
114
107
|
q = "//figure/following-sibling::*[self::dl]"
|
115
108
|
xmldoc.xpath(q).each do |s|
|
116
|
-
|
117
|
-
s.previous_element << s.remove
|
118
|
-
end
|
109
|
+
s["key"] == "true" and s.previous_element << s.remove
|
119
110
|
end
|
120
111
|
end
|
121
112
|
|
@@ -123,8 +114,7 @@ module Asciidoctor
|
|
123
114
|
def figure_dl_cleanup2(xmldoc)
|
124
115
|
q = "//figure/following-sibling::*[self::p]"
|
125
116
|
xmldoc.xpath(q).each do |s|
|
126
|
-
if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? &&
|
127
|
-
s.next_element.name == "dl"
|
117
|
+
if s.text =~ /^\s*key[^a-z]*$/i && !s.next_element.nil? && s.next_element.name == "dl"
|
128
118
|
s.next_element["key"] = "true"
|
129
119
|
s.previous_element << s.next_element.remove
|
130
120
|
s.remove
|
@@ -135,8 +125,7 @@ module Asciidoctor
|
|
135
125
|
# examples containing only figures become subfigures of figures
|
136
126
|
def subfigure_cleanup(xmldoc)
|
137
127
|
xmldoc.xpath("//example[figure]").each do |e|
|
138
|
-
next unless e.elements.map { |m| m.name }.
|
139
|
-
reject { |m| %w(name figure).include? m }.empty?
|
128
|
+
next unless e.elements.map { |m| m.name }.reject { |m| %w(name figure).include? m }.empty?
|
140
129
|
e.name = "figure"
|
141
130
|
end
|
142
131
|
end
|
@@ -148,12 +137,10 @@ module Asciidoctor
|
|
148
137
|
subfigure_cleanup(xmldoc)
|
149
138
|
end
|
150
139
|
|
151
|
-
ELEMS_ALLOW_NOTES =
|
152
|
-
%w[p formula ul ol dl figure].freeze
|
140
|
+
ELEMS_ALLOW_NOTES = %w[p formula ul ol dl figure].freeze
|
153
141
|
|
154
142
|
# if a note is at the end of a section, it is left alone
|
155
|
-
# if a note is followed by a non-note block,
|
156
|
-
# it is moved inside its preceding block if it is not delimited
|
143
|
+
# if a note is followed by a non-note block, it is moved inside its preceding block if it is not delimited
|
157
144
|
# (so there was no way of making that block include the note)
|
158
145
|
def note_cleanup(xmldoc)
|
159
146
|
q = "//note[following-sibling::*[not(local-name() = 'note')]]"
|
@@ -201,9 +188,34 @@ module Asciidoctor
|
|
201
188
|
n = d.next.remove
|
202
189
|
d << n.children
|
203
190
|
end
|
204
|
-
r.xpath("./description[normalize-space(.)='']").each
|
205
|
-
|
191
|
+
r.xpath("./description[normalize-space(.)='']").each { |d| d.replace("\n") }
|
192
|
+
end
|
193
|
+
|
194
|
+
def svgmap_cleanup(xmldoc)
|
195
|
+
svgmap_populate(xmldoc)
|
196
|
+
Metanorma::Utils::svgmap_rewrite(xmldoc, @localdir)
|
197
|
+
end
|
198
|
+
|
199
|
+
def svgmap_populate(xmldoc)
|
200
|
+
xmldoc.xpath("//svgmap").each do |s|
|
201
|
+
s1 = s.dup
|
202
|
+
s.children.remove
|
203
|
+
f = s1.at(".//figure") and s << f
|
204
|
+
s1.xpath(".//li").each do |li|
|
205
|
+
t = li&.at(".//eref | .//link | .//xref") or next
|
206
|
+
href = t.xpath("./following-sibling::node()")
|
207
|
+
next if href.empty?
|
208
|
+
s << %[<target href="#{svgmap_target(href)}">#{t.to_xml}</target>]
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def svgmap_target(nodeset)
|
214
|
+
nodeset.each do |n|
|
215
|
+
next unless n.name == "link"
|
216
|
+
n.children = n["target"]
|
206
217
|
end
|
218
|
+
nodeset.text.sub(/^[,; ]/, "").strip
|
207
219
|
end
|
208
220
|
end
|
209
221
|
end
|