metanorma-standoc 1.8.5 → 1.9.1
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/.gitignore +2 -0
- data/.rubocop.yml +5 -1
- data/Gemfile.devel +0 -0
- data/lib/asciidoctor/standoc/base.rb +41 -36
- data/lib/asciidoctor/standoc/biblio.rng +4 -6
- data/lib/asciidoctor/standoc/blocks.rb +27 -12
- data/lib/asciidoctor/standoc/blocks_notes.rb +20 -14
- data/lib/asciidoctor/standoc/cleanup.rb +32 -78
- data/lib/asciidoctor/standoc/cleanup_block.rb +56 -59
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +32 -21
- 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 +37 -28
- 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 +21 -15
- data/lib/asciidoctor/standoc/converter.rb +3 -1
- 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 +130 -1
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +40 -13
- 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 +12 -12
- data/lib/asciidoctor/standoc/terms.rb +10 -6
- data/lib/asciidoctor/standoc/utils.rb +32 -6
- data/lib/asciidoctor/standoc/validate.rb +12 -12
- data/lib/metanorma/standoc/version.rb +5 -5
- data/metanorma-standoc.gemspec +11 -11
- data/spec/asciidoctor/base_spec.rb +78 -8
- data/spec/asciidoctor/blocks_spec.rb +10 -0
- data/spec/asciidoctor/cleanup_sections_spec.rb +14 -14
- data/spec/asciidoctor/cleanup_spec.rb +1860 -1874
- data/spec/asciidoctor/inline_spec.rb +272 -273
- data/spec/asciidoctor/macros_spec.rb +8 -2
- data/spec/asciidoctor/refs_spec.rb +135 -7
- data/spec/asciidoctor/section_spec.rb +670 -687
- data/spec/assets/html-override.css +1 -0
- data/spec/assets/word-override.css +1 -0
- data/spec/spec_helper.rb +11 -9
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +60 -60
- data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
- data/spec/vcr_cassettes/isobib_get_123_1.yml +32 -32
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +41 -41
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +15 -15
- data/spec/vcr_cassettes/isobib_get_124.yml +17 -17
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +53 -49
- metadata +71 -68
- data/.rubocop.ribose.yml +0 -66
- data/.rubocop.tb.yml +0 -650
- data/spec/asciidoctor/macros_lutaml_spec.rb +0 -80
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
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# This project follows the Ribose OSS style guide.
|
2
2
|
# https://github.com/riboseinc/oss-guides
|
3
3
|
# All project-specific additions and overrides should be specified in this file.
|
4
|
-
|
5
4
|
inherit_from:
|
6
5
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
6
|
+
|
7
|
+
# local repo-specific modifications
|
8
|
+
|
7
9
|
AllCops:
|
10
|
+
DisplayCopNames: false
|
11
|
+
StyleGuideCopsOnly: false
|
8
12
|
TargetRubyVersion: 2.4
|
9
13
|
Rails:
|
10
14
|
Enabled: true
|
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
|
@@ -43,6 +44,7 @@ module Asciidoctor
|
|
43
44
|
i18nyaml: node.attr("i18nyaml"),
|
44
45
|
scope: node.attr("scope"),
|
45
46
|
htmlstylesheet: node.attr("htmlstylesheet"),
|
47
|
+
htmlstylesheet_override: node.attr("htmlstylesheet-override"),
|
46
48
|
htmlcoverpage: node.attr("htmlcoverpage"),
|
47
49
|
htmlintropage: node.attr("htmlintropage"),
|
48
50
|
scripts: node.attr("scripts"),
|
@@ -51,6 +53,7 @@ module Asciidoctor
|
|
51
53
|
htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
|
52
54
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
53
55
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
56
|
+
sectionsplit: node.attr("sectionsplit"),
|
54
57
|
}
|
55
58
|
end
|
56
59
|
|
@@ -59,7 +62,7 @@ module Asciidoctor
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def doc_extract_attributes(node)
|
62
|
-
{
|
65
|
+
attrs = {
|
63
66
|
script: node.attr("script"),
|
64
67
|
bodyfont: node.attr("body-font"),
|
65
68
|
headerfont: node.attr("header-font"),
|
@@ -67,6 +70,7 @@ module Asciidoctor
|
|
67
70
|
i18nyaml: node.attr("i18nyaml"),
|
68
71
|
scope: node.attr("scope"),
|
69
72
|
wordstylesheet: node.attr("wordstylesheet"),
|
73
|
+
wordstylesheet_override: node.attr("wordstylesheet-override"),
|
70
74
|
standardstylesheet: node.attr("standardstylesheet"),
|
71
75
|
header: node.attr("header"),
|
72
76
|
wordcoverpage: node.attr("wordcoverpage"),
|
@@ -77,6 +81,14 @@ module Asciidoctor
|
|
77
81
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
78
82
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
79
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
|
80
92
|
end
|
81
93
|
|
82
94
|
def doc_converter(node)
|
@@ -96,10 +108,15 @@ module Asciidoctor
|
|
96
108
|
@draft = node.attributes.has_key?("draft")
|
97
109
|
@novalid = node.attr("novalid")
|
98
110
|
@smartquotes = node.attr("smartquotes") != "false"
|
99
|
-
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
111
|
+
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
112
|
+
node.attr("mn-keep-asciimath") != "false"
|
100
113
|
@fontheader = default_fonts(node)
|
101
114
|
@files_to_delete = []
|
102
|
-
|
115
|
+
if node.attr("docfile")
|
116
|
+
@filename = File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
|
117
|
+
else
|
118
|
+
@filename = ""
|
119
|
+
end
|
103
120
|
@localdir = Metanorma::Utils::localdir(node)
|
104
121
|
@output_dir = outputdir node
|
105
122
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
@@ -131,10 +148,12 @@ module Asciidoctor
|
|
131
148
|
end
|
132
149
|
|
133
150
|
def outputs(node, ret)
|
134
|
-
File.open(@filename
|
135
|
-
presentation_xml_converter(node).convert(@filename
|
136
|
-
html_converter(node).convert(@filename
|
137
|
-
|
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")
|
138
157
|
end
|
139
158
|
|
140
159
|
def document(node)
|
@@ -151,12 +170,21 @@ module Asciidoctor
|
|
151
170
|
end
|
152
171
|
|
153
172
|
def clean_exit
|
154
|
-
@log.write(@output_dir
|
173
|
+
@log.write("#{@output_dir}#{@filename}.err") unless @novalid
|
174
|
+
|
155
175
|
@files_to_delete.each { |f| FileUtils.rm f }
|
156
176
|
end
|
157
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
|
+
|
158
185
|
def makexml1(node)
|
159
|
-
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}'>"]
|
160
188
|
result << noko { |ixml| front node, ixml }
|
161
189
|
result << noko { |ixml| middle node, ixml }
|
162
190
|
result << "</#{xml_root_tag}>"
|
@@ -191,36 +219,13 @@ module Asciidoctor
|
|
191
219
|
end
|
192
220
|
end
|
193
221
|
|
194
|
-
def default_script(lang)
|
195
|
-
case lang
|
196
|
-
when "ar", "fa"
|
197
|
-
"Arab"
|
198
|
-
when "ur"
|
199
|
-
"Aran"
|
200
|
-
when "ru", "bg"
|
201
|
-
"Cyrl"
|
202
|
-
when "hi"
|
203
|
-
"Deva"
|
204
|
-
when "el"
|
205
|
-
"Grek"
|
206
|
-
when "zh"
|
207
|
-
"Hans"
|
208
|
-
when "ko"
|
209
|
-
"Kore"
|
210
|
-
when "he"
|
211
|
-
"Hebr"
|
212
|
-
when "ja"
|
213
|
-
"Jpan"
|
214
|
-
else
|
215
|
-
"Latn"
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
222
|
private
|
220
223
|
|
221
224
|
def outputdir(node)
|
222
|
-
if node.attr("output_dir").nil_or_empty?
|
223
|
-
|
225
|
+
if node.attr("output_dir").nil_or_empty?
|
226
|
+
Metanorma::Utils::localdir(node)
|
227
|
+
else
|
228
|
+
File.join(node.attr("output_dir"), "")
|
224
229
|
end
|
225
230
|
end
|
226
231
|
end
|
@@ -124,7 +124,7 @@
|
|
124
124
|
<value>application/tei+xml</value>
|
125
125
|
<value>text/x-asciidoc</value>
|
126
126
|
<value>text/markdown</value>
|
127
|
-
<value>application/x-
|
127
|
+
<value>application/x-metanorma+xml</value>
|
128
128
|
<text/>
|
129
129
|
</choice>
|
130
130
|
</attribute>
|
@@ -452,6 +452,7 @@
|
|
452
452
|
<attribute name="type">
|
453
453
|
<choice>
|
454
454
|
<value>isni</value>
|
455
|
+
<value>orcid</value>
|
455
456
|
<value>uri</value>
|
456
457
|
</choice>
|
457
458
|
</attribute>
|
@@ -461,10 +462,7 @@
|
|
461
462
|
<define name="org-identifier">
|
462
463
|
<element name="identifier">
|
463
464
|
<attribute name="type">
|
464
|
-
<
|
465
|
-
<value>orcid</value>
|
466
|
-
<value>uri</value>
|
467
|
-
</choice>
|
465
|
+
<data type="string" datatypeLibrary=""/>
|
468
466
|
</attribute>
|
469
467
|
<text/>
|
470
468
|
</element>
|
@@ -1106,7 +1104,7 @@
|
|
1106
1104
|
<value>complementOf</value>
|
1107
1105
|
<value>obsoletes</value>
|
1108
1106
|
<value>obsoletedBy</value>
|
1109
|
-
<value>
|
1107
|
+
<value>cites</value>
|
1110
1108
|
<value>isCitedIn</value>
|
1111
1109
|
</choice>
|
1112
1110
|
</define>
|
@@ -45,8 +45,9 @@ module Asciidoctor
|
|
45
45
|
noko do |xml|
|
46
46
|
xml.figure **literal_attrs(node) do |f|
|
47
47
|
figure_title(node, f)
|
48
|
-
f.pre node.lines.join("\n"),
|
49
|
-
|
48
|
+
f.pre node.lines.join("\n"),
|
49
|
+
**attr_code(id: Metanorma::Utils::anchor_or_uuid,
|
50
|
+
alt: node.attr("alt"))
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
@@ -78,9 +79,19 @@ module Asciidoctor
|
|
78
79
|
example_proper(node)
|
79
80
|
end
|
80
81
|
|
82
|
+
def svgmap_attrs(node)
|
83
|
+
attr_code( { id: node.id,
|
84
|
+
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
85
|
+
number: node.attr("number"),
|
86
|
+
subsequence: node.attr("subsequence") }.
|
87
|
+
merge(keep_attrs(node)))
|
88
|
+
end
|
89
|
+
|
81
90
|
def svgmap_example(node)
|
82
91
|
noko do |xml|
|
83
|
-
xml.svgmap **attr_code(
|
92
|
+
xml.svgmap **attr_code(svgmap_attrs(node).merge(
|
93
|
+
src: node.attr("src"), alt: node.attr("alt"))) do |ex|
|
94
|
+
figure_title(node, ex)
|
84
95
|
ex << node.content
|
85
96
|
end
|
86
97
|
end.join("\n")
|
@@ -129,12 +140,14 @@ module Asciidoctor
|
|
129
140
|
end
|
130
141
|
|
131
142
|
def para_attrs(node)
|
132
|
-
attr_code(keep_attrs(node)
|
133
|
-
|
143
|
+
attr_code(keep_attrs(node)
|
144
|
+
.merge(align: node.attr("align"),
|
145
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
134
146
|
end
|
135
147
|
|
136
148
|
def paragraph(node)
|
137
149
|
return termsource(node) if node.role == "source"
|
150
|
+
|
138
151
|
noko do |xml|
|
139
152
|
xml.p **para_attrs(node) do |xml_t|
|
140
153
|
xml_t << node.content
|
@@ -143,8 +156,9 @@ module Asciidoctor
|
|
143
156
|
end
|
144
157
|
|
145
158
|
def quote_attrs(node)
|
146
|
-
attr_code(keep_attrs(node)
|
147
|
-
|
159
|
+
attr_code(keep_attrs(node)
|
160
|
+
.merge(align: node.attr("align"),
|
161
|
+
id: Metanorma::Utils::anchor_or_uuid(node)))
|
148
162
|
end
|
149
163
|
|
150
164
|
def quote_attribution(node, out)
|
@@ -168,11 +182,12 @@ module Asciidoctor
|
|
168
182
|
end
|
169
183
|
|
170
184
|
def listing_attrs(node)
|
171
|
-
attr_code(keep_attrs(node).
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
185
|
+
attr_code(keep_attrs(node).
|
186
|
+
merge(lang: node.attr("language"),
|
187
|
+
id: Metanorma::Utils::anchor_or_uuid(node),
|
188
|
+
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
189
|
+
number: node.attr("number"),
|
190
|
+
filename: node.attr("filename")))
|
176
191
|
end
|
177
192
|
|
178
193
|
# NOTE: html escaping is performed by Nokogiri
|
@@ -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
|