metanorma-standoc 1.7.3 → 1.8.5
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 +34 -45
- data/lib/asciidoctor/standoc/basicdoc.rng +5 -3
- data/lib/asciidoctor/standoc/blocks.rb +20 -11
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -2
- data/lib/asciidoctor/standoc/cleanup.rb +29 -77
- data/lib/asciidoctor/standoc/cleanup_block.rb +39 -27
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +56 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +26 -29
- data/lib/asciidoctor/standoc/cleanup_maths.rb +123 -0
- data/lib/asciidoctor/standoc/cleanup_ref.rb +4 -98
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +94 -0
- data/lib/asciidoctor/standoc/cleanup_section.rb +5 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -2
- data/lib/asciidoctor/standoc/converter.rb +0 -1
- data/lib/asciidoctor/standoc/front.rb +2 -2
- data/lib/asciidoctor/standoc/inline.rb +8 -16
- data/lib/asciidoctor/standoc/isodoc.rng +108 -2
- data/lib/asciidoctor/standoc/lists.rb +2 -2
- data/lib/asciidoctor/standoc/macros_plantuml.rb +1 -1
- data/lib/asciidoctor/standoc/ref_sect.rb +2 -2
- data/lib/asciidoctor/standoc/reqt.rb +6 -1
- data/lib/asciidoctor/standoc/section.rb +12 -80
- data/lib/asciidoctor/standoc/table.rb +1 -1
- data/lib/asciidoctor/standoc/terms.rb +125 -0
- data/lib/asciidoctor/standoc/utils.rb +2 -120
- 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 +30 -1
- 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 +408 -6
- 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 +4 -4
- 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 +13 -1
- data/spec/{asciidoctor-standoc → asciidoctor}/refs_spec.rb +175 -153
- data/spec/{asciidoctor-standoc → asciidoctor}/section_spec.rb +22 -3
- 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 +47 -47
- data/spec/vcr_cassettes/isobib_get_123.yml +14 -14
- data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -27
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +36 -36
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +94 -30
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -45
- metadata +49 -46
- data/lib/asciidoctor/standoc/log.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65dcd1f22a2224fb908c38f21bec75287e1568269b080f2b53ae9eda9963c2d9
|
4
|
+
data.tar.gz: d9912320a4f7319c2bd132e169dc315d52f3ee48a724b046f1c1c36f510ae079
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f2af97c651cd815e92dc61df5e81dbbfe4509abb82ba491674f72b722fadd7ba3f580870e7444e41e15357b4290f29ae99b6222b88115e45a571eae17f14836
|
7
|
+
data.tar.gz: 75dec696a85df288ea1b94c36e6608408c2c53bc5e8c163f8a7b817d8a43d50f10a4d0ae2a098fed331224cb322cdd6ba35509f7504fb3ea4d322819fa829e65
|
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
@@ -7,6 +7,7 @@ require "open-uri"
|
|
7
7
|
require "isodoc"
|
8
8
|
require "relaton"
|
9
9
|
require "fileutils"
|
10
|
+
require "metanorma-utils"
|
10
11
|
|
11
12
|
module Asciidoctor
|
12
13
|
module Standoc
|
@@ -91,6 +92,7 @@ module Asciidoctor
|
|
91
92
|
@draft = false
|
92
93
|
@refids = Set.new
|
93
94
|
@anchors = {}
|
95
|
+
@internal_eref_namespaces = []
|
94
96
|
@draft = node.attributes.has_key?("draft")
|
95
97
|
@novalid = node.attr("novalid")
|
96
98
|
@smartquotes = node.attr("smartquotes") != "false"
|
@@ -98,28 +100,32 @@ module Asciidoctor
|
|
98
100
|
@fontheader = default_fonts(node)
|
99
101
|
@files_to_delete = []
|
100
102
|
@filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : ""
|
101
|
-
@localdir = Utils::localdir(node)
|
103
|
+
@localdir = Metanorma::Utils::localdir(node)
|
102
104
|
@output_dir = outputdir node
|
103
105
|
@no_isobib_cache = node.attr("no-isobib-cache")
|
104
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") || "}}}"
|
105
109
|
@bibdb = nil
|
106
110
|
@seen_headers = []
|
107
111
|
@datauriimage = node.attr("data-uri-image")
|
108
112
|
@boilerplateauthority = node.attr("boilerplate-authority")
|
109
|
-
@
|
113
|
+
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
114
|
+
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
115
|
+
@log = Metanorma::Utils::Log.new
|
110
116
|
init_bib_caches(node)
|
111
117
|
init_iev_caches(node)
|
112
118
|
@lang = (node.attr("language") || "en")
|
113
|
-
@script = (node.attr("script") || "
|
119
|
+
@script = (node.attr("script") || default_script(node.attr("language")))
|
114
120
|
@isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
|
115
121
|
@i18n = @isodoc.i18n
|
116
122
|
end
|
117
123
|
|
118
124
|
def default_fonts(node)
|
119
125
|
b = node.attr("body-font") ||
|
120
|
-
(node.attr("script") == "Hans" ? '"
|
126
|
+
(node.attr("script") == "Hans" ? '"Source Han Sans",serif' : '"Cambria",serif')
|
121
127
|
h = node.attr("header-font") ||
|
122
|
-
(node.attr("script") == "Hans" ? '"
|
128
|
+
(node.attr("script") == "Hans" ? '"Source Han Sans",sans-serif' : '"Cambria",serif')
|
123
129
|
m = node.attr("monospace-font") || '"Courier New",monospace'
|
124
130
|
"$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"
|
125
131
|
end
|
@@ -133,7 +139,7 @@ module Asciidoctor
|
|
133
139
|
|
134
140
|
def document(node)
|
135
141
|
init(node)
|
136
|
-
ret = makexml(node).to_xml(indent: 2)
|
142
|
+
ret = makexml(node).to_xml(encoding: "US-ASCII", indent: 2)
|
137
143
|
outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
|
138
144
|
clean_exit
|
139
145
|
ret
|
@@ -185,52 +191,35 @@ module Asciidoctor
|
|
185
191
|
end
|
186
192
|
end
|
187
193
|
|
188
|
-
def
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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"
|
196
214
|
else
|
197
|
-
|
215
|
+
"Latn"
|
198
216
|
end
|
199
|
-
m[:text] && xml_t.modification do |mod|
|
200
|
-
mod.p { |p| p << m[:text].sub(/^\s+/, "") }
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
|
205
|
-
^(?<xref><(xref|concept)[^>]+>([^<]*</(xref|concept)>)?)
|
206
|
-
(,\s(?<text>.*))?
|
207
|
-
$
|
208
|
-
REGEXP
|
209
|
-
TERM_REFERENCE_RE =
|
210
|
-
Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
|
211
|
-
Regexp::IGNORECASE | Regexp::MULTILINE)
|
212
|
-
|
213
|
-
def extract_termsource_refs(text, node)
|
214
|
-
matched = TERM_REFERENCE_RE.match text
|
215
|
-
matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
|
216
|
-
matched
|
217
|
-
end
|
218
|
-
|
219
|
-
def termsource(node)
|
220
|
-
matched = extract_termsource_refs(node.content, node) || return
|
221
|
-
noko do |xml|
|
222
|
-
attrs = { status: matched[:text] ? "modified" : "identical" }
|
223
|
-
xml.termsource **attrs do |xml_t|
|
224
|
-
seen_xref = Nokogiri::XML.fragment(matched[:xref])
|
225
|
-
add_term_source(xml_t, seen_xref, matched)
|
226
|
-
end
|
227
|
-
end.join("\n")
|
228
217
|
end
|
229
218
|
|
230
219
|
private
|
231
220
|
|
232
221
|
def outputdir(node)
|
233
|
-
if node.attr("output_dir").nil_or_empty? then Utils::localdir(node)
|
222
|
+
if node.attr("output_dir").nil_or_empty? then Metanorma::Utils::localdir(node)
|
234
223
|
else File.join(node.attr("output_dir"), "")
|
235
224
|
end
|
236
225
|
end
|
@@ -729,9 +729,11 @@
|
|
729
729
|
</define>
|
730
730
|
<define name="index">
|
731
731
|
<element name="index">
|
732
|
-
<
|
733
|
-
<
|
734
|
-
|
732
|
+
<optional>
|
733
|
+
<attribute name="to">
|
734
|
+
<data type="IDREF"/>
|
735
|
+
</attribute>
|
736
|
+
</optional>
|
735
737
|
<element name="primary">
|
736
738
|
<oneOrMore>
|
737
739
|
<ref name="PureTextElement"/>
|
@@ -6,11 +6,11 @@ module Asciidoctor
|
|
6
6
|
module Standoc
|
7
7
|
module Blocks
|
8
8
|
def id_attr(node = nil)
|
9
|
-
{ id: Utils::anchor_or_uuid(node) }
|
9
|
+
{ id: Metanorma::Utils::anchor_or_uuid(node) }
|
10
10
|
end
|
11
11
|
|
12
12
|
def id_unnum_attrs(node)
|
13
|
-
attr_code( id: Utils::anchor_or_uuid(node),
|
13
|
+
attr_code( id: Metanorma::Utils::anchor_or_uuid(node),
|
14
14
|
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
15
15
|
number: node.attr("number"),
|
16
16
|
subsequence: node.attr("subsequence") )
|
@@ -29,7 +29,7 @@ module Asciidoctor
|
|
29
29
|
# We append each contained block to its parent
|
30
30
|
def open(node)
|
31
31
|
role = node.role || node.attr("style")
|
32
|
-
|
32
|
+
reqt_subpart(role) and return requirement_subpart(node)
|
33
33
|
result = []
|
34
34
|
node.blocks.each do |b|
|
35
35
|
result << send(b.context, b)
|
@@ -45,7 +45,7 @@ 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"), **attr_code(id: Utils::anchor_or_uuid,
|
48
|
+
f.pre node.lines.join("\n"), **attr_code(id: Metanorma::Utils::anchor_or_uuid,
|
49
49
|
alt: node.attr("alt"))
|
50
50
|
end
|
51
51
|
end
|
@@ -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
|
@@ -35,7 +35,7 @@ module Asciidoctor
|
|
35
35
|
date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "")
|
36
36
|
date += "T00:00:00Z" unless /T/.match date
|
37
37
|
attr_code(
|
38
|
-
id: Utils::anchor_or_uuid(node),
|
38
|
+
id: ::Metanorma::Utils::anchor_or_uuid(node),
|
39
39
|
reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)",
|
40
40
|
date: date )
|
41
41
|
end
|
@@ -69,7 +69,7 @@ module Asciidoctor
|
|
69
69
|
a = node.attr("type") and ["danger", "safety precautions"].each do |t|
|
70
70
|
name = t if a.casecmp(t).zero?
|
71
71
|
end
|
72
|
-
attr_code(keep_attrs(node).merge(id: Utils::anchor_or_uuid(node), type: name,
|
72
|
+
attr_code(keep_attrs(node).merge(id: Metanorma::Utils::anchor_or_uuid(node), type: name,
|
73
73
|
beforeclauses: node.attr("beforeclauses") == "true" ? "true" : nil))
|
74
74
|
end
|
75
75
|
|
@@ -5,11 +5,13 @@ require "html2doc"
|
|
5
5
|
require_relative "./cleanup_block.rb"
|
6
6
|
require_relative "./cleanup_footnotes.rb"
|
7
7
|
require_relative "./cleanup_ref.rb"
|
8
|
+
require_relative "./cleanup_ref_dl.rb"
|
8
9
|
require_relative "./cleanup_boilerplate.rb"
|
9
10
|
require_relative "./cleanup_section.rb"
|
10
11
|
require_relative "./cleanup_terms.rb"
|
11
12
|
require_relative "./cleanup_inline.rb"
|
12
13
|
require_relative "./cleanup_amend.rb"
|
14
|
+
require_relative "./cleanup_maths.rb"
|
13
15
|
require "relaton_iev"
|
14
16
|
|
15
17
|
module Asciidoctor
|
@@ -23,26 +25,15 @@ module Asciidoctor
|
|
23
25
|
</passthrough>}mx) { |m| HTMLEntities.new.decode($1) }
|
24
26
|
end
|
25
27
|
|
26
|
-
def asciimath2mathml(text)
|
27
|
-
text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do |m|
|
28
|
-
"<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
|
29
|
-
end
|
30
|
-
text = Html2Doc.
|
31
|
-
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)
|
@@ -78,14 +70,13 @@ module Asciidoctor
|
|
78
70
|
end
|
79
71
|
|
80
72
|
def smartquotes_cleanup(xmldoc)
|
81
|
-
xmldoc.xpath("//date").each { |d| Utils::endash_date(d) }
|
73
|
+
xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
|
82
74
|
xmldoc.traverse do |n|
|
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
|
-
|
88
|
-
n.replace(Utils::smartformat(n.text))
|
78
|
+
n.ancestors("pre, tt, sourcecode, bibdata, on, stem, figure[@class = 'pseudocode']").empty? or next
|
79
|
+
n.replace(Metanorma::Utils::smartformat(n.text))
|
89
80
|
else
|
90
81
|
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))#.
|
91
82
|
#gsub(/</, "<").gsub(/>/, ">"))
|
@@ -148,60 +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/, " ").
|
164
|
-
gsub(/\s$/, " ")
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def mathml_namespace(stem)
|
169
|
-
stem.xpath("./math", ).each { |x| x.default_namespace = MATHML_NS }
|
170
|
-
end
|
171
|
-
|
172
|
-
def mathml_mi_italics
|
173
|
-
{ uppergreek: true, upperroman: true,
|
174
|
-
lowergreek: true, lowerroman: true }
|
175
|
-
end
|
176
|
-
|
177
|
-
# presuppose multichar mi upright, singlechar mi MathML default italic
|
178
|
-
def mathml_italicise(x)
|
179
|
-
x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]", "m" => MATHML_NS).each do |i|
|
180
|
-
char = HTMLEntities.new.decode(i.text)
|
181
|
-
i["mathvariant"] = "normal" if mi_italicise?(char)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def mi_italicise?(c)
|
186
|
-
return false if c.length > 1
|
187
|
-
if /\p{Greek}/.match(c)
|
188
|
-
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowergreek] ||
|
189
|
-
/\p{Upper}/.match(c) && !mathml_mi_italics[:uppergreek]
|
190
|
-
elsif /\p{Latin}/.match(c)
|
191
|
-
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowerroman] ||
|
192
|
-
/\p{Upper}/.match(c) && !mathml_mi_italics[:upperroman]
|
193
|
-
else
|
194
|
-
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
|
195
149
|
end
|
196
150
|
end
|
197
151
|
|
198
|
-
def
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
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)
|
204
160
|
end
|
161
|
+
acc.join
|
205
162
|
end
|
206
163
|
|
207
164
|
# allows us to deal with doc relation localities,
|
@@ -215,23 +172,18 @@ module Asciidoctor
|
|
215
172
|
|
216
173
|
def img_cleanup(xmldoc)
|
217
174
|
return xmldoc unless @datauriimage
|
218
|
-
xmldoc.xpath("//image").each
|
219
|
-
i["src"] = datauri(i["src"])
|
220
|
-
end
|
175
|
+
xmldoc.xpath("//image").each { |i| i["src"] = Metanorma::Utils::datauri(i["src"], @localdir) }
|
221
176
|
end
|
222
177
|
|
223
178
|
def variant_cleanup(xmldoc)
|
224
179
|
xmldoc.xpath("//*[variant]").each do |c|
|
225
|
-
c&.next&.text? && c&.next&.next&.name == "variant" &&
|
226
|
-
c.next.
|
180
|
+
c&.next&.text? && c&.next&.next&.name == "variant" && c.next.text.gsub(/\s/, "").empty? and
|
181
|
+
c.next.remove
|
227
182
|
end
|
228
183
|
xmldoc.xpath("//*[variant]").each do |c|
|
229
|
-
next unless c.children.any?
|
230
|
-
n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?)
|
231
|
-
end
|
184
|
+
next unless c.children.any? { |n| n.name != "variant" && (!n.text? || !n.text.gsub(/\s/, "").empty?) }
|
232
185
|
c.xpath("./variant").each do |n|
|
233
|
-
if n.at_xpath('preceding-sibling::node()[not(self::text()'
|
234
|
-
'[not(normalize-space())])][1][self::variantwrap]')
|
186
|
+
if n.at_xpath('preceding-sibling::node()[not(self::text()[not(normalize-space())])][1][self::variantwrap]')
|
235
187
|
n.previous_element << n
|
236
188
|
else
|
237
189
|
n.replace('<variantwrap/>').first << n
|