metanorma-standoc 1.8.8 → 1.9.4
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 -13
- data/.hound.yml +3 -1
- data/.rubocop.yml +3 -7
- data/Gemfile.devel +0 -0
- data/lib/asciidoctor/standoc/base.rb +42 -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 +77 -134
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
- 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 +70 -45
- data/lib/asciidoctor/standoc/inline.rb +30 -22
- data/lib/asciidoctor/standoc/isodoc.rng +321 -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 +715 -509
- data/spec/asciidoctor/blocks_spec.rb +830 -727
- data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
- data/spec/asciidoctor/cleanup_spec.rb +1836 -1673
- data/spec/asciidoctor/inline_spec.rb +330 -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 +1528 -1533
- data/spec/asciidoctor/section_spec.rb +778 -689
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +296 -304
- data/spec/spec_helper.rb +13 -9
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +66 -66
- data/spec/vcr_cassettes/isobib_get_123.yml +17 -17
- data/spec/vcr_cassettes/isobib_get_123_1.yml +31 -31
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +40 -40
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +17 -17
- data/spec/vcr_cassettes/isobib_get_124.yml +16 -16
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +78 -66
- metadata +69 -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: d42939fe573eddd8bd58ff20a2e3eaacd3eb9de328afccabba60453a8b94cd43
|
4
|
+
data.tar.gz: e2d2e0f516b11587c5dcc6e8f87d39e4d63095b8e96014e7d1bfa610ceb6bae8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 653295f7c1dbdb48a201f0784e6d123058a2ccd0abc018fe9ae68049b9c01f29d0120c3a3ec5a25b968e18fbbf4ca3c85c0da294985f2dcee42ea2d049cdb526
|
7
|
+
data.tar.gz: d36fd8fa5b679f71c780bab99fe4c5a18d58c40e8995065975d87cbc0ce51f6459748c1c5310f3c4419d3058087a78d5e9d481839e4579c2d872d0359852ee28
|
data/.github/workflows/rake.yml
CHANGED
@@ -4,7 +4,7 @@ name: rake
|
|
4
4
|
|
5
5
|
on:
|
6
6
|
push:
|
7
|
-
branches: [ master, main
|
7
|
+
branches: [ master, main ]
|
8
8
|
tags: [ v* ]
|
9
9
|
pull_request:
|
10
10
|
|
@@ -16,19 +16,9 @@ jobs:
|
|
16
16
|
strategy:
|
17
17
|
fail-fast: false
|
18
18
|
matrix:
|
19
|
-
ruby: [ '2.7', '2.6', '2.5', '2.4' ]
|
19
|
+
ruby: [ '3.0', '2.7', '2.6', '2.5', '2.4' ]
|
20
20
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
21
21
|
experimental: [ false ]
|
22
|
-
include:
|
23
|
-
- ruby: '3.0'
|
24
|
-
os: 'ubuntu-latest'
|
25
|
-
experimental: true
|
26
|
-
- ruby: '3.0'
|
27
|
-
os: 'windows-latest'
|
28
|
-
experimental: true
|
29
|
-
- ruby: '3.0'
|
30
|
-
os: 'macos-latest'
|
31
|
-
experimental: true
|
32
22
|
steps:
|
33
23
|
- uses: actions/checkout@master
|
34
24
|
|
@@ -49,5 +39,5 @@ jobs:
|
|
49
39
|
with:
|
50
40
|
token: ${{ secrets.METANORMA_CI_PAT_TOKEN || secrets.GITHUB_TOKEN }}
|
51
41
|
repository: ${{ github.repository }}
|
52
|
-
event-type:
|
42
|
+
event-type: tests-passed
|
53
43
|
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'
|
data/.hound.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,14 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# https://github.com/
|
3
|
-
# All project-specific additions and overrides should be specified in this file.
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
4
3
|
inherit_from:
|
5
4
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
6
5
|
|
7
6
|
# local repo-specific modifications
|
7
|
+
# ...
|
8
8
|
|
9
9
|
AllCops:
|
10
|
-
DisplayCopNames: false
|
11
|
-
StyleGuideCopsOnly: false
|
12
10
|
TargetRubyVersion: 2.4
|
13
|
-
Rails:
|
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
|
@@ -47,11 +48,14 @@ module Asciidoctor
|
|
47
48
|
htmlcoverpage: node.attr("htmlcoverpage"),
|
48
49
|
htmlintropage: node.attr("htmlintropage"),
|
49
50
|
scripts: node.attr("scripts"),
|
51
|
+
scripts_override: node.attr("scripts-override"),
|
50
52
|
scripts_pdf: node.attr("scripts-pdf"),
|
51
53
|
datauriimage: node.attr("data-uri-image"),
|
52
54
|
htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
|
53
55
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
54
56
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
57
|
+
bare: node.attr("bare"),
|
58
|
+
sectionsplit: node.attr("sectionsplit"),
|
55
59
|
}
|
56
60
|
end
|
57
61
|
|
@@ -60,7 +64,7 @@ module Asciidoctor
|
|
60
64
|
end
|
61
65
|
|
62
66
|
def doc_extract_attributes(node)
|
63
|
-
{
|
67
|
+
attrs = {
|
64
68
|
script: node.attr("script"),
|
65
69
|
bodyfont: node.attr("body-font"),
|
66
70
|
headerfont: node.attr("header-font"),
|
@@ -78,7 +82,16 @@ module Asciidoctor
|
|
78
82
|
htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"),
|
79
83
|
doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"),
|
80
84
|
break_up_urls_in_tables: node.attr("break-up-urls-in-tables"),
|
85
|
+
bare: node.attr("bare"),
|
81
86
|
}
|
87
|
+
|
88
|
+
if font_manifest_file = node.attr("mn2pdf-font-manifest-file")
|
89
|
+
attrs[IsoDoc::XslfoPdfConvert::MN2PDF_OPTIONS] = {
|
90
|
+
IsoDoc::XslfoPdfConvert::MN2PDF_FONT_MANIFEST => font_manifest_file,
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
attrs
|
82
95
|
end
|
83
96
|
|
84
97
|
def doc_converter(node)
|
@@ -98,10 +111,15 @@ module Asciidoctor
|
|
98
111
|
@draft = node.attributes.has_key?("draft")
|
99
112
|
@novalid = node.attr("novalid")
|
100
113
|
@smartquotes = node.attr("smartquotes") != "false"
|
101
|
-
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
114
|
+
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
115
|
+
node.attr("mn-keep-asciimath") != "false"
|
102
116
|
@fontheader = default_fonts(node)
|
103
117
|
@files_to_delete = []
|
104
|
-
|
118
|
+
if node.attr("docfile")
|
119
|
+
@filename = File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
|
120
|
+
else
|
121
|
+
@filename = ""
|
122
|
+
end
|
105
123
|
@localdir = Metanorma::Utils::localdir(node)
|
106
124
|
@output_dir = outputdir node
|
107
125
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
@@ -133,10 +151,12 @@ module Asciidoctor
|
|
133
151
|
end
|
134
152
|
|
135
153
|
def outputs(node, ret)
|
136
|
-
File.open(@filename
|
137
|
-
presentation_xml_converter(node).convert(@filename
|
138
|
-
html_converter(node).convert(@filename
|
139
|
-
|
154
|
+
File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
|
155
|
+
presentation_xml_converter(node).convert("#{@filename}.xml")
|
156
|
+
html_converter(node).convert("#{@filename}.presentation.xml",
|
157
|
+
nil, false, "#{@filename}.html")
|
158
|
+
doc_converter(node).convert("#{@filename}.presentation.xml",
|
159
|
+
nil, false, "#{@filename}.doc")
|
140
160
|
end
|
141
161
|
|
142
162
|
def document(node)
|
@@ -153,12 +173,21 @@ module Asciidoctor
|
|
153
173
|
end
|
154
174
|
|
155
175
|
def clean_exit
|
156
|
-
@log.write(@output_dir
|
176
|
+
@log.write("#{@output_dir}#{@filename}.err") unless @novalid
|
177
|
+
|
157
178
|
@files_to_delete.each { |f| FileUtils.rm f }
|
158
179
|
end
|
159
180
|
|
181
|
+
def clean_abort(msg, file = nil)
|
182
|
+
file and
|
183
|
+
File.open("#{@filename}.xml.abort", "w:UTF-8") { |f| f.write(file) }
|
184
|
+
clean_exit
|
185
|
+
abort(msg)
|
186
|
+
end
|
187
|
+
|
160
188
|
def makexml1(node)
|
161
|
-
result = ["<?xml version='1.0' encoding='UTF-8'?>",
|
189
|
+
result = ["<?xml version='1.0' encoding='UTF-8'?>",
|
190
|
+
"<#{xml_root_tag} type='semantic' version='#{version}'>"]
|
162
191
|
result << noko { |ixml| front node, ixml }
|
163
192
|
result << noko { |ixml| middle node, ixml }
|
164
193
|
result << "</#{xml_root_tag}>"
|
@@ -193,36 +222,13 @@ module Asciidoctor
|
|
193
222
|
end
|
194
223
|
end
|
195
224
|
|
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
225
|
private
|
222
226
|
|
223
227
|
def outputdir(node)
|
224
|
-
if node.attr("output_dir").nil_or_empty?
|
225
|
-
|
228
|
+
if node.attr("output_dir").nil_or_empty?
|
229
|
+
Metanorma::Utils::localdir(node)
|
230
|
+
else
|
231
|
+
File.join(node.attr("output_dir"), "")
|
226
232
|
end
|
227
233
|
end
|
228
234
|
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
|