metanorma-standoc 1.8.7 → 1.9.3
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/.rubocop.yml +0 -2
- data/Gemfile.devel +0 -0
- data/lib/asciidoctor/standoc/base.rb +39 -36
- 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 +51 -29
- 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 +24 -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 +104 -94
- data/lib/asciidoctor/standoc/converter.rb +10 -3
- 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 +5 -5
- data/lib/asciidoctor/standoc/inline.rb +1 -1
- data/lib/asciidoctor/standoc/isodoc.rng +305 -4
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +50 -23
- data/lib/asciidoctor/standoc/macros_form.rb +63 -0
- 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 +31 -16
- data/lib/asciidoctor/standoc/terms.rb +27 -16
- data/lib/asciidoctor/standoc/utils.rb +35 -9
- data/lib/asciidoctor/standoc/validate.rb +30 -28
- data/lib/metanorma-standoc.rb +0 -1
- data/lib/metanorma/standoc/version.rb +5 -5
- data/metanorma-standoc.gemspec +11 -11
- data/spec/asciidoctor/base_spec.rb +85 -19
- data/spec/asciidoctor/blocks_spec.rb +830 -727
- data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
- data/spec/asciidoctor/cleanup_spec.rb +1900 -1917
- data/spec/asciidoctor/inline_spec.rb +282 -283
- data/spec/asciidoctor/isobib_cache_spec.rb +406 -358
- data/spec/asciidoctor/lists_spec.rb +3 -3
- data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
- data/spec/asciidoctor/macros_spec.rb +546 -444
- data/spec/asciidoctor/macros_yaml2text_spec.rb +1 -1
- data/spec/asciidoctor/refs_dl_spec.rb +4 -4
- data/spec/asciidoctor/refs_spec.rb +19 -19
- data/spec/asciidoctor/section_spec.rb +778 -689
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +21 -21
- data/spec/spec_helper.rb +13 -9
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +62 -62
- data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
- data/spec/vcr_cassettes/isobib_get_123_1.yml +28 -28
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +41 -41
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +16 -16
- data/spec/vcr_cassettes/isobib_get_124.yml +15 -15
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +63 -61
- metadata +68 -67
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb0657fc8f9c086fa560b509e2e7e5829b9ab5d902e727ce221c040f2aad3ec4
|
4
|
+
data.tar.gz: eac14431d7f0317023a49993dee40a440fbc47d32136091cd4adfea5a5d36823
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72d1aece1ed13421fa2fdcd87f8d4468cae148cc415b3a982fc9fea236cbf5f01113e87b11fc88b0aa68ce52f057d5dcdc1441b37c028798cd66458146d0b540
|
7
|
+
data.tar.gz: b736bd6de43ace4da0c31f14b1f7f28349eb7272baf073e5b68558f68cd88e68b84fb72c76d578f0a69c8b56ae8021b5dfe75792dde64fae1a121eeaa156cfc6
|
data/.rubocop.yml
CHANGED
data/Gemfile.devel
ADDED
File without changes
|
@@ -8,6 +8,7 @@ require "isodoc"
|
|
8
8
|
require "relaton"
|
9
9
|
require "fileutils"
|
10
10
|
require "metanorma-utils"
|
11
|
+
require "isodoc/xslfo_convert"
|
11
12
|
|
12
13
|
module Asciidoctor
|
13
14
|
module Standoc
|
@@ -52,6 +53,7 @@ module Asciidoctor
|
|
52
53
|
htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
|
53
54
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
54
55
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
56
|
+
sectionsplit: node.attr("sectionsplit"),
|
55
57
|
}
|
56
58
|
end
|
57
59
|
|
@@ -60,7 +62,7 @@ module Asciidoctor
|
|
60
62
|
end
|
61
63
|
|
62
64
|
def doc_extract_attributes(node)
|
63
|
-
{
|
65
|
+
attrs = {
|
64
66
|
script: node.attr("script"),
|
65
67
|
bodyfont: node.attr("body-font"),
|
66
68
|
headerfont: node.attr("header-font"),
|
@@ -79,6 +81,14 @@ module Asciidoctor
|
|
79
81
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
80
82
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
81
83
|
}
|
84
|
+
|
85
|
+
if font_manifest_file = node.attr("mn2pdf-font-manifest-file")
|
86
|
+
attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
|
87
|
+
IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => font_manifest_file,
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
attrs
|
82
92
|
end
|
83
93
|
|
84
94
|
def doc_converter(node)
|
@@ -98,10 +108,15 @@ module Asciidoctor
|
|
98
108
|
@draft = node.attributes.has_key?("draft")
|
99
109
|
@novalid = node.attr("novalid")
|
100
110
|
@smartquotes = node.attr("smartquotes") != "false"
|
101
|
-
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
111
|
+
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
112
|
+
node.attr("mn-keep-asciimath") != "false"
|
102
113
|
@fontheader = default_fonts(node)
|
103
114
|
@files_to_delete = []
|
104
|
-
|
115
|
+
if node.attr("docfile")
|
116
|
+
@filename = File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
|
117
|
+
else
|
118
|
+
@filename = ""
|
119
|
+
end
|
105
120
|
@localdir = Metanorma::Utils::localdir(node)
|
106
121
|
@output_dir = outputdir node
|
107
122
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
@@ -133,10 +148,12 @@ module Asciidoctor
|
|
133
148
|
end
|
134
149
|
|
135
150
|
def outputs(node, ret)
|
136
|
-
File.open(@filename
|
137
|
-
presentation_xml_converter(node).convert(@filename
|
138
|
-
html_converter(node).convert(@filename
|
139
|
-
|
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")
|
140
157
|
end
|
141
158
|
|
142
159
|
def document(node)
|
@@ -153,12 +170,21 @@ module Asciidoctor
|
|
153
170
|
end
|
154
171
|
|
155
172
|
def clean_exit
|
156
|
-
@log.write(@output_dir
|
173
|
+
@log.write("#{@output_dir}#{@filename}.err") unless @novalid
|
174
|
+
|
157
175
|
@files_to_delete.each { |f| FileUtils.rm f }
|
158
176
|
end
|
159
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
|
+
|
160
185
|
def makexml1(node)
|
161
|
-
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}'>"]
|
162
188
|
result << noko { |ixml| front node, ixml }
|
163
189
|
result << noko { |ixml| middle node, ixml }
|
164
190
|
result << "</#{xml_root_tag}>"
|
@@ -193,36 +219,13 @@ module Asciidoctor
|
|
193
219
|
end
|
194
220
|
end
|
195
221
|
|
196
|
-
def default_script(lang)
|
197
|
-
case lang
|
198
|
-
when "ar", "fa"
|
199
|
-
"Arab"
|
200
|
-
when "ur"
|
201
|
-
"Aran"
|
202
|
-
when "ru", "bg"
|
203
|
-
"Cyrl"
|
204
|
-
when "hi"
|
205
|
-
"Deva"
|
206
|
-
when "el"
|
207
|
-
"Grek"
|
208
|
-
when "zh"
|
209
|
-
"Hans"
|
210
|
-
when "ko"
|
211
|
-
"Kore"
|
212
|
-
when "he"
|
213
|
-
"Hebr"
|
214
|
-
when "ja"
|
215
|
-
"Jpan"
|
216
|
-
else
|
217
|
-
"Latn"
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
222
|
private
|
222
223
|
|
223
224
|
def outputdir(node)
|
224
|
-
if node.attr("output_dir").nil_or_empty?
|
225
|
-
|
225
|
+
if node.attr("output_dir").nil_or_empty?
|
226
|
+
Metanorma::Utils::localdir(node)
|
227
|
+
else
|
228
|
+
File.join(node.attr("output_dir"), "")
|
226
229
|
end
|
227
230
|
end
|
228
231
|
end
|
@@ -30,6 +30,7 @@ module Asciidoctor
|
|
30
30
|
def open(node)
|
31
31
|
role = node.role || node.attr("style")
|
32
32
|
reqt_subpart(role) and return requirement_subpart(node)
|
33
|
+
role == "form" and return form(node)
|
33
34
|
result = []
|
34
35
|
node.blocks.each do |b|
|
35
36
|
result << send(b.context, b)
|
@@ -37,6 +38,17 @@ module Asciidoctor
|
|
37
38
|
result
|
38
39
|
end
|
39
40
|
|
41
|
+
def form(node)
|
42
|
+
noko do |xml|
|
43
|
+
xml.form **attr_code(
|
44
|
+
id: Metanorma::Utils::anchor_or_uuid,
|
45
|
+
name: node.attr("name"), action: node.attr("action")
|
46
|
+
) do |f|
|
47
|
+
f << node.content
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
def literal_attrs(node)
|
41
53
|
attr_code(id_attr(node).merge(keep_attrs(node)))
|
42
54
|
end
|
@@ -71,11 +83,14 @@ module Asciidoctor
|
|
71
83
|
|
72
84
|
def example(node)
|
73
85
|
return term_example(node) if in_terms?
|
86
|
+
|
74
87
|
role = node.role || node.attr("style")
|
75
88
|
%w(recommendation requirement permission).include?(role) and
|
76
89
|
return requirement(node, role)
|
77
90
|
return pseudocode_example(node) if role == "pseudocode"
|
78
91
|
return svgmap_example(node) if role == "svgmap"
|
92
|
+
return form(node) if role == "form"
|
93
|
+
|
79
94
|
example_proper(node)
|
80
95
|
end
|
81
96
|
|
@@ -91,9 +106,9 @@ module Asciidoctor
|
|
91
106
|
noko do |xml|
|
92
107
|
xml.svgmap **attr_code(svgmap_attrs(node).merge(
|
93
108
|
src: node.attr("src"), alt: node.attr("alt"))) do |ex|
|
94
|
-
|
95
|
-
|
96
|
-
|
109
|
+
figure_title(node, ex)
|
110
|
+
ex << node.content
|
111
|
+
end
|
97
112
|
end.join("\n")
|
98
113
|
end
|
99
114
|
|
@@ -140,13 +155,14 @@ module Asciidoctor
|
|
140
155
|
end
|
141
156
|
|
142
157
|
def para_attrs(node)
|
143
|
-
attr_code(keep_attrs(node)
|
144
|
-
|
145
|
-
|
158
|
+
attr_code(keep_attrs(node)
|
159
|
+
.merge(align: node.attr("align"),
|
160
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
146
161
|
end
|
147
162
|
|
148
163
|
def paragraph(node)
|
149
164
|
return termsource(node) if node.role == "source"
|
165
|
+
|
150
166
|
noko do |xml|
|
151
167
|
xml.p **para_attrs(node) do |xml_t|
|
152
168
|
xml_t << node.content
|
@@ -155,9 +171,9 @@ module Asciidoctor
|
|
155
171
|
end
|
156
172
|
|
157
173
|
def quote_attrs(node)
|
158
|
-
attr_code(keep_attrs(node)
|
159
|
-
|
160
|
-
|
174
|
+
attr_code(keep_attrs(node)
|
175
|
+
.merge(align: node.attr("align"),
|
176
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
161
177
|
end
|
162
178
|
|
163
179
|
def quote_attribution(node, out)
|
@@ -2,30 +2,41 @@ module Asciidoctor
|
|
2
2
|
module Standoc
|
3
3
|
module Blocks
|
4
4
|
def termnote_attrs(node)
|
5
|
-
attr_code(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
attr_code(
|
6
|
+
id_attr(node).merge(
|
7
|
+
unnumbered: node.attr("unnumbered"),
|
8
|
+
number: node.attr("number"),
|
9
|
+
subsequence: node.attr("subsequence"),
|
10
|
+
"keep-with-next": node.attr("keep-with-next"),
|
11
|
+
"keep-lines-together": node.attr("keep-with-next"),
|
12
|
+
"keep-separate": node.attr("keep-separate")
|
13
|
+
)
|
14
|
+
)
|
12
15
|
end
|
13
16
|
|
14
17
|
def note_attrs(node)
|
15
|
-
attr_code(
|
16
|
-
|
17
|
-
|
18
|
+
attr_code(
|
19
|
+
termnote_attrs(node).merge(
|
20
|
+
type: node.attr("type"),
|
21
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
|
22
|
+
)
|
23
|
+
)
|
18
24
|
end
|
19
25
|
|
20
26
|
def sidebar_attrs(node)
|
21
|
-
todo_attrs(node).merge(
|
22
|
-
|
27
|
+
todo_attrs(node).merge(
|
28
|
+
attr_code(
|
29
|
+
from: node.attr("from"),
|
30
|
+
to: node.attr("to") || node.attr("from")
|
31
|
+
)
|
32
|
+
)
|
23
33
|
end
|
24
34
|
|
25
35
|
def sidebar(node)
|
26
36
|
return unless draft?
|
37
|
+
|
27
38
|
noko do |xml|
|
28
|
-
xml.review **
|
39
|
+
xml.review **sidebar_attrs(node) do |r|
|
29
40
|
wrap_in_para(node, r)
|
30
41
|
end
|
31
42
|
end
|
@@ -33,33 +44,34 @@ module Asciidoctor
|
|
33
44
|
|
34
45
|
def todo_attrs(node)
|
35
46
|
date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
|
36
|
-
date += "T00:00:00Z" unless /T/.match date
|
47
|
+
date += "T00:00:00Z" unless /T/.match? date
|
37
48
|
attr_code(
|
38
49
|
id: ::Metanorma::Utils::anchor_or_uuid(node),
|
39
50
|
reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
|
40
|
-
date: date
|
51
|
+
date: date
|
52
|
+
)
|
41
53
|
end
|
42
54
|
|
43
55
|
def todo(node)
|
44
56
|
noko do |xml|
|
45
|
-
xml.review **
|
57
|
+
xml.review **todo_attrs(node) do |r|
|
46
58
|
wrap_in_para(node, r)
|
47
59
|
end
|
48
60
|
end
|
49
61
|
end
|
50
62
|
|
51
|
-
def termnote(
|
63
|
+
def termnote(node)
|
52
64
|
noko do |xml|
|
53
|
-
xml.termnote **termnote_attrs(
|
54
|
-
wrap_in_para(
|
65
|
+
xml.termnote **termnote_attrs(node) do |ex|
|
66
|
+
wrap_in_para(node, ex)
|
55
67
|
end
|
56
68
|
end.join("\n")
|
57
69
|
end
|
58
70
|
|
59
|
-
def note(
|
71
|
+
def note(node)
|
60
72
|
noko do |xml|
|
61
|
-
xml.note **note_attrs(
|
62
|
-
wrap_in_para(
|
73
|
+
xml.note **note_attrs(node) do |c|
|
74
|
+
wrap_in_para(node, c)
|
63
75
|
end
|
64
76
|
end.join("\n")
|
65
77
|
end
|
@@ -69,14 +81,19 @@ module Asciidoctor
|
|
69
81
|
a = node.attr("type") and ["danger", "safety precautions"].each do |t|
|
70
82
|
name = t if a.casecmp(t).zero?
|
71
83
|
end
|
72
|
-
attr_code(
|
73
|
-
|
84
|
+
attr_code(
|
85
|
+
keep_attrs(node).merge(
|
86
|
+
id: Metanorma::Utils::anchor_or_uuid(node), type: name,
|
87
|
+
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil
|
88
|
+
)
|
89
|
+
)
|
74
90
|
end
|
75
91
|
|
76
92
|
def admonition(node)
|
77
93
|
return termnote(node) if in_terms?
|
78
94
|
return note(node) if node.attr("name") == "note"
|
79
95
|
return todo(node) if node.attr("name") == "todo"
|
96
|
+
|
80
97
|
noko do |xml|
|
81
98
|
xml.admonition **admonition_attrs(node) do |a|
|
82
99
|
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)
|
@@ -31,6 +33,7 @@ module Asciidoctor
|
|
31
33
|
obligations_cleanup(xmldoc)
|
32
34
|
table_cleanup(xmldoc)
|
33
35
|
formula_cleanup(xmldoc)
|
36
|
+
form_cleanup(xmldoc)
|
34
37
|
sourcecode_cleanup(xmldoc)
|
35
38
|
figure_cleanup(xmldoc)
|
36
39
|
element_name_cleanup(xmldoc)
|
@@ -69,26 +72,43 @@ module Asciidoctor
|
|
69
72
|
xmldoc
|
70
73
|
end
|
71
74
|
|
75
|
+
IGNORE_DUMBQUOTES = "//pre | //pre//* | //tt | //tt//* | "\
|
76
|
+
"//sourcecode | //sourcecode//* | //bibdata//* | //stem | "\
|
77
|
+
"//stem//* | //figure[@class = 'pseudocode'] | "\
|
78
|
+
"//figure[@class = 'pseudocode']//*".freeze
|
79
|
+
|
72
80
|
def smartquotes_cleanup(xmldoc)
|
73
81
|
xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
|
74
|
-
|
75
|
-
|
76
|
-
|
82
|
+
if @smartquotes then smartquotes_cleanup1(xmldoc)
|
83
|
+
else dumbquote_cleanup(xmldoc)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def smartquotes_cleanup1(xmldoc)
|
88
|
+
(xmldoc.xpath("//*[child::text()]") - xmldoc.xpath(IGNORE_DUMBQUOTES))
|
89
|
+
.each do |x|
|
90
|
+
x.children.each do |n|
|
91
|
+
next unless n.text?
|
92
|
+
|
77
93
|
/[-'"(<>]|\.\.|\dx/.match(n) or next
|
78
|
-
|
94
|
+
|
79
95
|
n.replace(Metanorma::Utils::smartformat(n.text))
|
80
|
-
else
|
81
|
-
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))#.
|
82
|
-
#gsub(/</, "<").gsub(/>/, ">"))
|
83
96
|
end
|
84
97
|
end
|
85
98
|
end
|
86
99
|
|
87
|
-
def
|
100
|
+
def dumbquote_cleanup(xmldoc)
|
101
|
+
xmldoc.traverse do |n|
|
102
|
+
next unless n.text?
|
103
|
+
|
104
|
+
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
|
105
|
+
end
|
88
106
|
end
|
89
107
|
|
108
|
+
def docidentifier_cleanup(xmldoc); end
|
109
|
+
|
90
110
|
TEXT_ELEMS =
|
91
|
-
%w{status language script version author name callout phone email
|
111
|
+
%w{status language script version author name callout phone email
|
92
112
|
street city state country postcode identifier referenceFrom surname
|
93
113
|
referenceTo docidentifier docnumber prefix initial addition forename
|
94
114
|
title draft secretariat title-main title-intro title-part}.freeze
|
@@ -110,57 +130,6 @@ module Asciidoctor
|
|
110
130
|
xmldoc.traverse { |n| n.name = n.name.gsub(/_/, "-") }
|
111
131
|
end
|
112
132
|
|
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
133
|
# allows us to deal with doc relation localities,
|
165
134
|
# temporarily stashed to "bpart"
|
166
135
|
def bpart_cleanup(xmldoc)
|
@@ -170,28 +139,34 @@ module Asciidoctor
|
|
170
139
|
end
|
171
140
|
end
|
172
141
|
|
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
142
|
def variant_cleanup(xmldoc)
|
143
|
+
variant_space_cleanup(xmldoc)
|
179
144
|
xmldoc.xpath("//*[variant]").each do |c|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
next unless c.children.any? { |n| n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?) }
|
145
|
+
next unless c.children.any? do |n|
|
146
|
+
n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
|
147
|
+
end
|
148
|
+
|
185
149
|
c.xpath("./variant").each do |n|
|
186
|
-
if n.at_xpath(
|
150
|
+
if n.at_xpath("preceding-sibling::node()"\
|
151
|
+
"[not(self::text()[not(normalize-space())])][1]"\
|
152
|
+
"[self::variantwrap]")
|
187
153
|
n.previous_element << n
|
188
154
|
else
|
189
|
-
n.replace(
|
155
|
+
n.replace("<variantwrap/>").first << n
|
190
156
|
end
|
191
157
|
end
|
192
158
|
end
|
193
159
|
xmldoc.xpath("//variantwrap").each { |n| n.name = "variant" }
|
194
160
|
end
|
161
|
+
|
162
|
+
def variant_space_cleanup(xmldoc)
|
163
|
+
xmldoc.xpath("//*[variant]").each do |c|
|
164
|
+
if c&.next&.text? && c&.next&.next&.name == "variant"
|
165
|
+
c.next.text.gsub(/\s/, "").empty? and
|
166
|
+
c.next.remove
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
195
170
|
end
|
196
171
|
end
|
197
172
|
end
|