metanorma-standoc 1.9.0 → 1.10.0
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 +4 -8
- data/lib/asciidoctor/standoc/base.rb +31 -35
- 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 +28 -15
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +117 -77
- data/lib/asciidoctor/standoc/cleanup_maths.rb +36 -27
- data/lib/asciidoctor/standoc/cleanup_ref.rb +31 -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 -135
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +19 -18
- data/lib/asciidoctor/standoc/converter.rb +7 -2
- 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 +45 -34
- data/lib/asciidoctor/standoc/isodoc.rng +209 -4
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +11 -11
- data/lib/asciidoctor/standoc/macros_form.rb +63 -0
- data/lib/asciidoctor/standoc/macros_plantuml.rb +19 -21
- data/lib/asciidoctor/standoc/macros_terms.rb +33 -23
- 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 +40 -27
- data/lib/asciidoctor/standoc/terms.rb +25 -18
- data/lib/asciidoctor/standoc/utils.rb +35 -9
- data/lib/asciidoctor/standoc/validate.rb +48 -33
- data/lib/metanorma-standoc.rb +0 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/asciidoctor/base_spec.rb +701 -508
- data/spec/asciidoctor/blocks_spec.rb +831 -738
- data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
- data/spec/asciidoctor/cleanup_spec.rb +889 -682
- data/spec/asciidoctor/inline_spec.rb +62 -14
- data/spec/asciidoctor/isobib_cache_spec.rb +404 -358
- data/spec/asciidoctor/lists_spec.rb +149 -137
- data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
- data/spec/asciidoctor/macros_spec.rb +923 -503
- 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 +405 -299
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +342 -304
- data/spec/spec_helper.rb +13 -9
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +54 -54
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +25 -25
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +37 -37
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
- metadata +16 -15
- 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
@@ -3,7 +3,7 @@ require "nokogiri"
|
|
3
3
|
require "htmlentities"
|
4
4
|
require "pathname"
|
5
5
|
require "open-uri"
|
6
|
-
require_relative "./front_contributor
|
6
|
+
require_relative "./front_contributor"
|
7
7
|
|
8
8
|
module Asciidoctor
|
9
9
|
module Standoc
|
@@ -40,6 +40,7 @@ module Asciidoctor
|
|
40
40
|
|
41
41
|
def metadata_committee(node, xml)
|
42
42
|
return unless node.attr("technical-committee")
|
43
|
+
|
43
44
|
xml.editorialgroup do |a|
|
44
45
|
committee_component("technical-committee", node, a)
|
45
46
|
end
|
@@ -47,8 +48,8 @@ module Asciidoctor
|
|
47
48
|
|
48
49
|
def metadata_ics(node, xml)
|
49
50
|
ics = node.attr("library-ics")
|
50
|
-
ics
|
51
|
-
xml.ics { |
|
51
|
+
ics&.split(/,\s*/)&.each do |i|
|
52
|
+
xml.ics { |elem| elem.code i }
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -71,15 +72,15 @@ module Asciidoctor
|
|
71
72
|
|
72
73
|
def datetypes
|
73
74
|
%w{ published accessed created implemented obsoleted
|
74
|
-
confirmed updated issued circulated unchanged received
|
75
|
-
vote-started vote-ended
|
76
|
-
}
|
75
|
+
confirmed updated issued circulated unchanged received
|
76
|
+
vote-started vote-ended announced }
|
77
77
|
end
|
78
78
|
|
79
79
|
def metadata_date(node, xml)
|
80
80
|
datetypes.each { |t| metadata_date1(node, xml, t) }
|
81
|
-
node.attributes.
|
81
|
+
node.attributes.each_key do |a|
|
82
82
|
next unless a == "date" || /^date_\d+$/.match(a)
|
83
|
+
|
83
84
|
type, date = node.attr(a).split(/ /, 2)
|
84
85
|
type or next
|
85
86
|
xml.date **{ type: type } do |d|
|
@@ -93,7 +94,8 @@ module Asciidoctor
|
|
93
94
|
end
|
94
95
|
|
95
96
|
def metadata_script(node, xml)
|
96
|
-
xml.script (node.attr("script") ||
|
97
|
+
xml.script (node.attr("script") ||
|
98
|
+
default_script(node.attr("language")))
|
97
99
|
end
|
98
100
|
|
99
101
|
def relaton_relations
|
@@ -114,8 +116,8 @@ module Asciidoctor
|
|
114
116
|
end
|
115
117
|
|
116
118
|
def relation_normalise(type)
|
117
|
-
type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
|
118
|
-
sub(/-in$/, "In")
|
119
|
+
type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
|
120
|
+
.sub(/-in$/, "In")
|
119
121
|
end
|
120
122
|
|
121
123
|
def metadata_getrelation(node, xml, type, desc = nil)
|
@@ -124,8 +126,8 @@ module Asciidoctor
|
|
124
126
|
id = d.split(/,\s*/)
|
125
127
|
xml.relation **{ type: relation_normalise(type) } do |r|
|
126
128
|
desc.nil? or r.description relation_normalise(desc)
|
127
|
-
fetch_ref(r, d, nil, {}) or r.bibitem do |b|
|
128
|
-
b.title id[1]
|
129
|
+
fetch_ref(r, d, nil, **{}) or r.bibitem do |b|
|
130
|
+
b.title id[1] || "--"
|
129
131
|
b.docidentifier id[0]
|
130
132
|
end
|
131
133
|
end
|
@@ -134,11 +136,20 @@ module Asciidoctor
|
|
134
136
|
|
135
137
|
def metadata_keywords(node, xml)
|
136
138
|
return unless node.attr("keywords")
|
137
|
-
|
139
|
+
|
140
|
+
node.attr("keywords").split(/,\s*/).each do |kw|
|
138
141
|
xml.keyword kw
|
139
142
|
end
|
140
143
|
end
|
141
144
|
|
145
|
+
def metadata_classifications(node, xml)
|
146
|
+
csv_split(node.attr("classification"), ",")&.each do |c|
|
147
|
+
vals = c.split(/:/, 2)
|
148
|
+
vals.size == 1 and vals = ["default", vals[0]]
|
149
|
+
xml.classification vals[1], type: vals[0]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
142
153
|
def metadata(node, xml)
|
143
154
|
title node, xml
|
144
155
|
metadata_source(node, xml)
|
@@ -155,14 +166,16 @@ module Asciidoctor
|
|
155
166
|
metadata_copyright(node, xml)
|
156
167
|
metadata_relations(node, xml)
|
157
168
|
metadata_series(node, xml)
|
169
|
+
metadata_classifications(node, xml)
|
158
170
|
metadata_keywords(node, xml)
|
159
|
-
xml.ext do
|
171
|
+
xml.ext do
|
160
172
|
metadata_ext(node, xml)
|
161
173
|
end
|
162
174
|
end
|
163
175
|
|
164
176
|
def metadata_ext(node, ext)
|
165
177
|
metadata_doctype(node, ext)
|
178
|
+
metadata_subdoctype(node, ext)
|
166
179
|
metadata_committee(node, ext)
|
167
180
|
metadata_ics(node, ext)
|
168
181
|
end
|
@@ -171,11 +184,13 @@ module Asciidoctor
|
|
171
184
|
xml.doctype doctype(node)
|
172
185
|
end
|
173
186
|
|
174
|
-
def
|
187
|
+
def metadata_subdoctype(node, xml)
|
188
|
+
s = node.attr("docsubtype") and xml.subdoctype s
|
175
189
|
end
|
176
190
|
|
177
|
-
def
|
178
|
-
|
191
|
+
def metadata_note(node, xml); end
|
192
|
+
|
193
|
+
def metadata_series(node, xml); end
|
179
194
|
|
180
195
|
def title(node, xml)
|
181
196
|
title_english(node, xml)
|
@@ -187,7 +202,8 @@ module Asciidoctor
|
|
187
202
|
at = { language: lang, format: "text/plain" }
|
188
203
|
xml.title **attr_code(at) do |t|
|
189
204
|
t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
|
190
|
-
|
205
|
+
node.attr("title-en")) ||
|
206
|
+
node.title)
|
191
207
|
end
|
192
208
|
end
|
193
209
|
end
|
@@ -196,6 +212,7 @@ module Asciidoctor
|
|
196
212
|
node.attributes.each do |k, v|
|
197
213
|
next unless /^title-(?<titlelang>.+)$/ =~ k
|
198
214
|
next if titlelang == "en"
|
215
|
+
|
199
216
|
xml.title v, { language: titlelang, format: "text/plain" }
|
200
217
|
end
|
201
218
|
end
|
@@ -10,18 +10,18 @@ module Asciidoctor
|
|
10
10
|
module Front
|
11
11
|
def committee_component(compname, node, out)
|
12
12
|
out.send compname.gsub(/-/, "_"), node.attr(compname),
|
13
|
-
|
14
|
-
|
13
|
+
**attr_code(number: node.attr("#{compname}-number"),
|
14
|
+
type: node.attr("#{compname}-type"))
|
15
15
|
i = 2
|
16
|
-
while node.attr(compname+"_#{i}")
|
17
|
-
out.send compname.gsub(/-/, "_"), node.attr(compname+"_#{i}"),
|
18
|
-
|
19
|
-
|
16
|
+
while node.attr(compname + "_#{i}")
|
17
|
+
out.send compname.gsub(/-/, "_"), node.attr(compname + "_#{i}"),
|
18
|
+
**attr_code(number: node.attr("#{compname}-number_#{i}"),
|
19
|
+
type: node.attr("#{compname}-type_#{i}"))
|
20
20
|
i += 1
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def organization(org, orgname, node = nil, default_org = nil)
|
24
|
+
def organization(org, orgname, is_pub, node = nil, default_org = nil)
|
25
25
|
abbrevs = org_abbrev
|
26
26
|
n = abbrevs.invert[orgname] and orgname = n
|
27
27
|
org.name orgname
|
@@ -29,37 +29,39 @@ module Asciidoctor
|
|
29
29
|
abbr = org_abbrev[orgname]
|
30
30
|
default_org && b = node.attr("subdivision-abbr") and abbr = b
|
31
31
|
abbr and org.abbreviation abbr
|
32
|
-
|
32
|
+
is_pub && node and org_address(node, org)
|
33
33
|
end
|
34
34
|
|
35
|
-
def org_address(node,
|
36
|
-
node.attr("pub-address") and
|
35
|
+
def org_address(node, person)
|
36
|
+
node.attr("pub-address") and person.address do |ad|
|
37
37
|
ad.formattedAddress do |f|
|
38
38
|
f << node.attr("pub-address").gsub(/ \+\n/, "<br/>")
|
39
39
|
end
|
40
40
|
end
|
41
|
-
node.attr("pub-phone") and
|
42
|
-
node.attr("pub-fax") and
|
43
|
-
|
44
|
-
node.attr("pub-
|
41
|
+
node.attr("pub-phone") and person.phone node.attr("pub-phone")
|
42
|
+
node.attr("pub-fax") and
|
43
|
+
person.phone node.attr("pub-fax"), **{ type: "fax" }
|
44
|
+
node.attr("pub-email") and person.email node.attr("pub-email")
|
45
|
+
node.attr("pub-uri") and person.uri node.attr("pub-uri")
|
45
46
|
end
|
46
47
|
|
47
48
|
# , " => ," : CSV definition does not deal with space followed by quote
|
48
49
|
# at start of field
|
49
|
-
def csv_split(
|
50
|
-
return if
|
51
|
-
|
50
|
+
def csv_split(text, delim = ";")
|
51
|
+
return if text.nil?
|
52
|
+
|
53
|
+
CSV.parse_line(text&.gsub(/#{delim} "(?!")/, "#{delim}\""),
|
52
54
|
liberal_parsing: true,
|
53
|
-
col_sep: delim)&.compact&.map
|
55
|
+
col_sep: delim)&.compact&.map(&:strip)
|
54
56
|
end
|
55
57
|
|
56
58
|
def metadata_author(node, xml)
|
57
|
-
csv_split(node.attr("publisher") || default_publisher || "")
|
58
|
-
each do |p|
|
59
|
+
csv_split(node.attr("publisher") || default_publisher || "")
|
60
|
+
&.each do |p|
|
59
61
|
xml.contributor do |c|
|
60
62
|
c.role **{ type: "author" }
|
61
63
|
c.organization do |a|
|
62
|
-
organization(a, p, node, !node.attr("publisher"))
|
64
|
+
organization(a, p, false, node, !node.attr("publisher"))
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
@@ -76,17 +78,18 @@ module Asciidoctor
|
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
def personal_role(node,
|
80
|
-
|
81
|
+
def personal_role(node, contrib, suffix)
|
82
|
+
type = node.attr("role#{suffix}")&.downcase || "author"
|
83
|
+
contrib.role **{ type: type }
|
81
84
|
end
|
82
85
|
|
83
|
-
def personal_contact(node, suffix,
|
84
|
-
node.attr("phone#{suffix}") and
|
86
|
+
def personal_contact(node, suffix, person)
|
87
|
+
node.attr("phone#{suffix}") and person.phone node.attr("phone#{suffix}")
|
85
88
|
node.attr("fax#{suffix}") and
|
86
|
-
|
87
|
-
node.attr("email#{suffix}") and
|
89
|
+
person.phone node.attr("fax#{suffix}"), **{ type: "fax" }
|
90
|
+
node.attr("email#{suffix}") and person.email node.attr("email#{suffix}")
|
88
91
|
node.attr("contributor-uri#{suffix}") and
|
89
|
-
|
92
|
+
person.uri node.attr("contributor-uri#{suffix}")
|
90
93
|
end
|
91
94
|
|
92
95
|
def personal_author1(node, xml, suffix)
|
@@ -100,8 +103,8 @@ module Asciidoctor
|
|
100
103
|
end
|
101
104
|
end
|
102
105
|
|
103
|
-
def person_name(node,
|
104
|
-
|
106
|
+
def person_name(node, _xml, suffix, person)
|
107
|
+
person.name do |n|
|
105
108
|
if node.attr("fullname#{suffix}")
|
106
109
|
n.completename node.attr("fullname#{suffix}")
|
107
110
|
else
|
@@ -112,21 +115,43 @@ module Asciidoctor
|
|
112
115
|
end
|
113
116
|
end
|
114
117
|
|
115
|
-
def person_affiliation(node,
|
116
|
-
node.attr("affiliation#{suffix}") and
|
118
|
+
def person_affiliation(node, _xml, suffix, person)
|
119
|
+
node.attr("affiliation#{suffix}") and person.affiliation do |a|
|
117
120
|
a.organization do |o|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
121
|
+
person_organization(node, suffix, o)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def person_organization(node, suffix, xml)
|
127
|
+
xml.name node.attr("affiliation#{suffix}")
|
128
|
+
abbr = node.attr("affiliation_abbrev#{suffix}") and
|
129
|
+
xml.abbreviation abbr
|
130
|
+
csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
|
131
|
+
xml.subdivision s
|
132
|
+
end
|
133
|
+
person_address(node, suffix, xml)
|
134
|
+
end
|
135
|
+
|
136
|
+
def person_address(node, suffix, xml)
|
137
|
+
if node.attr("address#{suffix}")
|
138
|
+
xml.address do |ad|
|
139
|
+
ad.formattedAddress do |f|
|
140
|
+
f << node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>")
|
128
141
|
end
|
129
142
|
end
|
143
|
+
elsif node.attr("country#{suffix}") || node.attr("city#{suffix}")
|
144
|
+
person_address_components(node, suffix, xml)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def person_address_components(node, suffix, xml)
|
149
|
+
xml.address do |ad|
|
150
|
+
s = node.attr("street#{suffix}") and ad.street s
|
151
|
+
s = node.attr("city#{suffix}") and ad.city s
|
152
|
+
s = node.attr("state#{suffix}") and ad.state s
|
153
|
+
s = node.attr("country#{suffix}") and ad.country s
|
154
|
+
s = node.attr("postcode#{suffix}") and ad.postcode s
|
130
155
|
end
|
131
156
|
end
|
132
157
|
|
@@ -135,7 +160,7 @@ module Asciidoctor
|
|
135
160
|
end
|
136
161
|
|
137
162
|
def org_abbrev
|
138
|
-
{
|
163
|
+
{}
|
139
164
|
end
|
140
165
|
|
141
166
|
def metadata_publisher(node, xml)
|
@@ -144,7 +169,7 @@ module Asciidoctor
|
|
144
169
|
xml.contributor do |c|
|
145
170
|
c.role **{ type: "publisher" }
|
146
171
|
c.organization do |a|
|
147
|
-
organization(a, p, node, !node.attr("publisher"))
|
172
|
+
organization(a, p, true, node, !node.attr("publisher"))
|
148
173
|
end
|
149
174
|
end
|
150
175
|
end
|
@@ -157,7 +182,7 @@ module Asciidoctor
|
|
157
182
|
c.from (node.attr("copyright-year") || Date.today.year)
|
158
183
|
p.match(/[A-Za-z]/).nil? or c.owner do |owner|
|
159
184
|
owner.organization do |a|
|
160
|
-
organization(a, p, node, !pub)
|
185
|
+
organization(a, p, true, node, !pub)
|
161
186
|
end
|
162
187
|
end
|
163
188
|
end
|
@@ -9,8 +9,8 @@ require "latexmath"
|
|
9
9
|
module Asciidoctor
|
10
10
|
module Standoc
|
11
11
|
module Inline
|
12
|
-
def refid?(
|
13
|
-
@refids.include?
|
12
|
+
def refid?(ref)
|
13
|
+
@refids.include? ref
|
14
14
|
end
|
15
15
|
|
16
16
|
def inline_anchor(node)
|
@@ -46,19 +46,20 @@ module Asciidoctor
|
|
46
46
|
def inline_anchor_xref_attrs(node)
|
47
47
|
m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
|
48
48
|
(?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
|
49
|
-
casing = m.nil? ? nil : m[:case]&.sub(/%$/, "")
|
50
|
-
droploc = m.nil? ? nil : ((m[:drop].nil? && m[:drop2].nil?) ? nil: true)
|
51
|
-
f = (m.nil? || m[:fn].nil?) ? "inline" : "footnote"
|
52
|
-
c = (!m.nil? && (%i[case fn drop drop2].any? { |x| !m[x].nil? })) ?
|
53
|
-
m[:text] : node.text
|
54
49
|
t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
|
55
|
-
{ target: t, type:
|
50
|
+
m.nil? and return { target: t, type: "inline", text: node.text }
|
51
|
+
droploc = m[:drop].nil? && m[:drop2].nil? ? nil : true
|
52
|
+
f = m[:fn].nil? ? "inline" : "footnote"
|
53
|
+
c = %i[case fn drop drop2].any? { |x| !m[x].nil? } ? m[:text] : node.text
|
54
|
+
{ target: t, type: f, case: m[:case]&.sub(/%$/, ""), droploc: droploc,
|
55
|
+
text: c }
|
56
56
|
end
|
57
57
|
|
58
58
|
def inline_anchor_link(node)
|
59
59
|
contents = node.text
|
60
60
|
contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
|
61
|
-
attributes = { "target": node.target, "alt": node.attr("title")
|
61
|
+
attributes = { "target": node.target, "alt": node.attr("title"),
|
62
|
+
"updatetype": node.attr("updatetype") }
|
62
63
|
noko do |xml|
|
63
64
|
xml.link **attr_code(attributes) do |l|
|
64
65
|
l << contents
|
@@ -67,8 +68,8 @@ module Asciidoctor
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def inline_anchor_bibref(node)
|
70
|
-
eref_contents = (node.text || node.target || node.id)
|
71
|
-
sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
|
71
|
+
eref_contents = (node.text || node.target || node.id)
|
72
|
+
&.sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
|
72
73
|
eref_attributes = { id: node.target || node.id }
|
73
74
|
@refids << (node.target || node.id)
|
74
75
|
noko do |xml|
|
@@ -105,7 +106,7 @@ module Asciidoctor
|
|
105
106
|
attrs = {}
|
106
107
|
node.option?("landscape") and attrs[:orientation] = "landscape"
|
107
108
|
node.option?("portrait") and attrs[:orientation] = "portrait"
|
108
|
-
noko { |xml| xml.pagebreak **attr_code(attrs)}.join
|
109
|
+
noko { |xml| xml.pagebreak **attr_code(attrs) }.join
|
109
110
|
end
|
110
111
|
|
111
112
|
def thematic_break(_node)
|
@@ -113,41 +114,45 @@ module Asciidoctor
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def xml_encode(text)
|
116
|
-
HTMLEntities.new.encode(text, :basic, :hexadecimal)
|
117
|
-
gsub(/&gt;/, ">").gsub(
|
118
|
-
gsub(/>/, ">").gsub(/</, "<").gsub(/&/, "&")
|
119
|
-
gsub(/"/, '"').gsub(/
/, "\n").gsub(/&#/, "&#")
|
117
|
+
HTMLEntities.new.encode(text, :basic, :hexadecimal)
|
118
|
+
.gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
|
119
|
+
.gsub(/>/, ">").gsub(/</, "<").gsub(/&/, "&")
|
120
|
+
.gsub(/"/, '"').gsub(/
/, "\n").gsub(/&#/, "&#")
|
120
121
|
end
|
121
122
|
|
122
|
-
def
|
123
|
+
def latex_parse1(text)
|
123
124
|
lxm_input = Unicode2LaTeX.unicode2latex(HTMLEntities.new.decode(text))
|
124
125
|
results = Latexmath.parse(lxm_input).to_mathml
|
125
126
|
results.nil? and
|
126
|
-
@log.add(
|
127
|
+
@log.add("Math", nil,
|
127
128
|
"latexmlmath failed to process equation:\n#{lxm_input}")
|
128
129
|
results&.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
|
129
130
|
end
|
130
131
|
|
131
132
|
def stem_parse(text, xml, style)
|
132
133
|
if /<([^:>&]+:)?math(\s+[^>&]+)?> |
|
133
|
-
<([^:>&]+:)?math(\s+[^>&]+)?>/x.match text
|
134
|
+
<([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
|
134
135
|
math = xml_encode(text)
|
135
136
|
xml.stem math, **{ type: "MathML" }
|
136
|
-
elsif style == :latexmath
|
137
|
-
latex = latex_parse(text) or return xml.stem **{ type: "MathML" }
|
138
|
-
xml.stem **{ type: "MathML" } do |s|
|
139
|
-
math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, "")).elements[0]
|
140
|
-
math.delete("alttext")
|
141
|
-
s.parent.children = math
|
142
|
-
end
|
137
|
+
elsif style == :latexmath then latex_parse(text, xml)
|
143
138
|
else
|
144
|
-
xml.stem text&.gsub(
|
139
|
+
xml.stem text&.gsub(/&#/, "&#"), **{ type: "AsciiMath" }
|
145
140
|
end
|
146
141
|
end
|
147
142
|
|
148
|
-
|
149
|
-
|
143
|
+
def latex_parse(text, xml)
|
144
|
+
latex = latex_parse1(text) or return xml.stem **{ type: "MathML" }
|
145
|
+
xml.stem **{ type: "MathML" } do |s|
|
146
|
+
math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
|
147
|
+
.elements[0]
|
148
|
+
math.delete("alttext")
|
149
|
+
s.parent.children = math
|
150
150
|
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def highlight_parse(text, xml)
|
154
|
+
xml << text
|
155
|
+
end
|
151
156
|
|
152
157
|
def inline_quoted(node)
|
153
158
|
noko do |xml|
|
@@ -182,14 +187,20 @@ module Asciidoctor
|
|
182
187
|
|
183
188
|
def image_attributes(node)
|
184
189
|
uri = node.image_uri (node.attr("target") || node.target)
|
185
|
-
types = /^data:/.match(uri)
|
190
|
+
types = if /^data:/.match?(uri) then Metanorma::Utils::datauri2mime(uri)
|
191
|
+
else MIME::Types.type_for(uri)
|
192
|
+
end
|
186
193
|
type = types.first.to_s
|
187
194
|
uri = uri.sub(%r{^data:image/\*;}, "data:#{type};")
|
188
|
-
|
195
|
+
image_attributes1(node, uri, type)
|
196
|
+
end
|
197
|
+
|
198
|
+
def image_attributes1(node, uri, type)
|
199
|
+
attr_code(src: uri,
|
189
200
|
id: Metanorma::Utils::anchor_or_uuid,
|
190
201
|
mimetype: type,
|
191
202
|
height: node.attr("height") || "auto",
|
192
|
-
width: node.attr("width") || "auto"
|
203
|
+
width: node.attr("width") || "auto",
|
193
204
|
filename: node.attr("filename"),
|
194
205
|
title: node.attr("titleattr"),
|
195
206
|
alt: node.alt == node.attr("default-alt") ? nil : node.alt)
|
@@ -197,14 +208,14 @@ module Asciidoctor
|
|
197
208
|
|
198
209
|
def inline_image(node)
|
199
210
|
noko do |xml|
|
200
|
-
xml.image **
|
211
|
+
xml.image **image_attributes(node)
|
201
212
|
end.join("")
|
202
213
|
end
|
203
214
|
|
204
215
|
def inline_indexterm(node)
|
205
216
|
noko do |xml|
|
206
217
|
node.type == :visible and xml << node.text
|
207
|
-
|
218
|
+
terms = (node.attr("terms") || [node.text]).map { |x| xml_encode(x) }
|
208
219
|
xml.index do |i|
|
209
220
|
i.primary { |x| x << terms[0] }
|
210
221
|
a = terms.dig(1) and i.secondary { |x| x << a }
|