metanorma-standoc 1.11.1 → 2.0.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 -31
- data/.gitignore +23 -0
- data/Gemfile +2 -0
- data/lib/asciidoctor/standoc/base.rb +2 -241
- data/lib/asciidoctor/standoc/blocks.rb +2 -238
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -100
- data/lib/asciidoctor/standoc/cleanup.rb +2 -207
- data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
- data/lib/asciidoctor/standoc/cleanup_block.rb +2 -173
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -204
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +2 -108
- data/lib/asciidoctor/standoc/cleanup_image.rb +2 -69
- data/lib/asciidoctor/standoc/cleanup_inline.rb +2 -179
- data/lib/asciidoctor/standoc/cleanup_maths.rb +2 -221
- data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -169
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +2 -93
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -110
- data/lib/asciidoctor/standoc/cleanup_section.rb +2 -184
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -91
- data/lib/asciidoctor/standoc/cleanup_symbols.rb +2 -47
- data/lib/asciidoctor/standoc/cleanup_table.rb +2 -67
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -113
- data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -161
- data/lib/asciidoctor/standoc/cleanup_text.rb +2 -95
- data/lib/asciidoctor/standoc/cleanup_toc.rb +3 -0
- data/lib/asciidoctor/standoc/cleanup_xref.rb +2 -106
- data/lib/asciidoctor/standoc/converter.rb +2 -123
- data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +2 -56
- data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +2 -102
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +3 -404
- data/lib/asciidoctor/standoc/deprecated.rb +5 -0
- data/lib/asciidoctor/standoc/front.rb +2 -219
- data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
- data/lib/asciidoctor/standoc/inline.rb +2 -229
- data/lib/asciidoctor/standoc/lists.rb +2 -119
- data/lib/asciidoctor/standoc/macros.rb +2 -203
- data/lib/asciidoctor/standoc/macros_form.rb +2 -62
- data/lib/asciidoctor/standoc/macros_note.rb +2 -44
- data/lib/asciidoctor/standoc/macros_plantuml.rb +2 -112
- data/lib/asciidoctor/standoc/macros_terms.rb +2 -180
- data/lib/asciidoctor/standoc/ref.rb +2 -225
- data/lib/asciidoctor/standoc/ref_sect.rb +2 -143
- data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
- data/lib/asciidoctor/standoc/render.rb +3 -0
- data/lib/asciidoctor/standoc/reqt.rb +2 -89
- data/lib/asciidoctor/standoc/section.rb +2 -190
- data/lib/asciidoctor/standoc/table.rb +2 -84
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +2 -178
- data/lib/asciidoctor/standoc/terms.rb +2 -153
- data/lib/asciidoctor/standoc/utils.rb +2 -116
- data/lib/asciidoctor/standoc/validate.rb +2 -157
- data/lib/asciidoctor/standoc/validate_section.rb +2 -54
- data/lib/isodoc/html/htmlstyle.css +20 -11
- data/lib/isodoc/html/htmlstyle.scss +11 -11
- data/lib/metanorma/standoc/base.rb +149 -0
- data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +0 -0
- data/lib/metanorma/standoc/blocks.rb +239 -0
- data/lib/metanorma/standoc/blocks_notes.rb +101 -0
- data/lib/metanorma/standoc/cleanup.rb +146 -0
- data/lib/metanorma/standoc/cleanup_amend.rb +54 -0
- data/lib/metanorma/standoc/cleanup_block.rb +173 -0
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +213 -0
- data/lib/metanorma/standoc/cleanup_footnotes.rb +109 -0
- data/lib/metanorma/standoc/cleanup_image.rb +70 -0
- data/lib/metanorma/standoc/cleanup_inline.rb +190 -0
- data/lib/metanorma/standoc/cleanup_maths.rb +222 -0
- data/lib/metanorma/standoc/cleanup_ref.rb +170 -0
- data/lib/metanorma/standoc/cleanup_ref_dl.rb +104 -0
- data/lib/metanorma/standoc/cleanup_reqt.rb +111 -0
- data/lib/metanorma/standoc/cleanup_section.rb +212 -0
- data/lib/metanorma/standoc/cleanup_section_names.rb +92 -0
- data/lib/metanorma/standoc/cleanup_symbols.rb +48 -0
- data/lib/metanorma/standoc/cleanup_table.rb +68 -0
- data/lib/metanorma/standoc/cleanup_terms.rb +140 -0
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +199 -0
- data/lib/metanorma/standoc/cleanup_text.rb +96 -0
- data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
- data/lib/metanorma/standoc/cleanup_xref.rb +107 -0
- data/lib/metanorma/standoc/converter.rb +124 -0
- data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +57 -0
- data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +103 -0
- data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +409 -0
- data/lib/metanorma/standoc/front.rb +224 -0
- data/lib/metanorma/standoc/front_contributor.rb +192 -0
- data/lib/metanorma/standoc/inline.rb +232 -0
- data/lib/{asciidoctor → metanorma}/standoc/isodoc.rng +90 -18
- data/lib/metanorma/standoc/lists.rb +120 -0
- data/lib/metanorma/standoc/macros.rb +204 -0
- data/lib/metanorma/standoc/macros_form.rb +63 -0
- data/lib/metanorma/standoc/macros_note.rb +45 -0
- data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
- data/lib/metanorma/standoc/macros_terms.rb +181 -0
- data/lib/metanorma/standoc/ref.rb +243 -0
- data/lib/metanorma/standoc/ref_sect.rb +153 -0
- data/lib/metanorma/standoc/ref_utility.rb +129 -0
- data/lib/metanorma/standoc/render.rb +115 -0
- data/lib/metanorma/standoc/reqt.rb +90 -0
- data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
- data/lib/metanorma/standoc/section.rb +209 -0
- data/lib/metanorma/standoc/table.rb +85 -0
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +179 -0
- data/lib/metanorma/standoc/terms.rb +160 -0
- data/lib/metanorma/standoc/utils.rb +101 -0
- data/lib/metanorma/standoc/validate.rb +158 -0
- data/lib/metanorma/standoc/validate_section.rb +55 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
- data/lib/metanorma-standoc.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/{asciidoctor → metanorma}/base_spec.rb +73 -8
- data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/blocks_spec.rb +49 -20
- data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +25 -1
- data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +2 -2
- data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +9 -9
- data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +528 -91
- data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +22 -22
- data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +17 -17
- data/spec/{asciidoctor → metanorma}/inline_spec.rb +175 -6
- data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +5 -9
- data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
- data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
- data/spec/{asciidoctor → metanorma}/macros_spec.rb +8 -8
- data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
- data/spec/metanorma/refs_dl_spec.rb +863 -0
- data/spec/{asciidoctor → metanorma}/refs_spec.rb +1277 -687
- data/spec/{asciidoctor → metanorma}/section_spec.rb +90 -3
- data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +179 -179
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +98 -98
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +111 -111
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
- 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 +89 -38
- data/lib/asciidoctor/standoc/ref_date_id.rb +0 -62
- data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -0,0 +1,5 @@
|
|
1
|
+
warn "Please replace your references to Asciidoctor::Standoc with Metanorma::Standoc and your instances of require 'asciidoctor/standoc' with require 'metanorma/standoc'"
|
2
|
+
|
3
|
+
exit 127 if ENV['METANORMA_DEPRECATION_FAIL']
|
4
|
+
|
5
|
+
Asciidoctor::Standoc = Metanorma::Standoc unless defined? Asciidoctor::Standoc
|
@@ -1,220 +1,3 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "htmlentities"
|
4
|
-
require "pathname"
|
5
|
-
require_relative "./front_contributor"
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/front"
|
6
3
|
|
7
|
-
module Asciidoctor
|
8
|
-
module Standoc
|
9
|
-
module Front
|
10
|
-
def metadata_id(node, xml)
|
11
|
-
part, subpart = node&.attr("partnumber")&.split(/-/)
|
12
|
-
id = node.attr("docnumber") || ""
|
13
|
-
id += "-#{part}" if part
|
14
|
-
id += "-#{subpart}" if subpart
|
15
|
-
xml.docidentifier id
|
16
|
-
xml.docnumber node.attr("docnumber")
|
17
|
-
end
|
18
|
-
|
19
|
-
def metadata_other_id(node, xml)
|
20
|
-
a = node.attr("isbn") and xml.docidentifier a, type: "ISBN"
|
21
|
-
a = node.attr("isbn10") and xml.docidentifier a, type: "ISBN10"
|
22
|
-
end
|
23
|
-
|
24
|
-
def metadata_version(node, xml)
|
25
|
-
xml.edition node.attr("edition") if node.attr("edition")
|
26
|
-
xml.version do |v|
|
27
|
-
v.revision_date node.attr("revdate") if node.attr("revdate")
|
28
|
-
v.draft node.attr("draft") if node.attr("draft")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def metadata_status(node, xml)
|
33
|
-
xml.status do |s|
|
34
|
-
s.stage (node.attr("status") || node.attr("docstage") || "published")
|
35
|
-
node.attr("docsubstage") and s.substage node.attr("docsubstage")
|
36
|
-
node.attr("iteration") and s.iteration node.attr("iteration")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def metadata_committee(node, xml)
|
41
|
-
return unless node.attr("technical-committee")
|
42
|
-
|
43
|
-
xml.editorialgroup do |a|
|
44
|
-
committee_component("technical-committee", node, a)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def metadata_ics(node, xml)
|
49
|
-
ics = node.attr("library-ics")
|
50
|
-
ics&.split(/,\s*/)&.each do |i|
|
51
|
-
xml.ics { |elem| elem.code i }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def metadata_source(node, xml)
|
56
|
-
node.attr("uri") && xml.uri(node.attr("uri"))
|
57
|
-
node.attr("xml-uri") && xml.uri(node.attr("xml-uri"), type: "xml")
|
58
|
-
node.attr("html-uri") && xml.uri(node.attr("html-uri"), type: "html")
|
59
|
-
node.attr("pdf-uri") && xml.uri(node.attr("pdf-uri"), type: "pdf")
|
60
|
-
node.attr("doc-uri") && xml.uri(node.attr("doc-uri"), type: "doc")
|
61
|
-
node.attr("relaton-uri") && xml.uri(node.attr("relaton-uri"),
|
62
|
-
type: "relaton")
|
63
|
-
end
|
64
|
-
|
65
|
-
def metadata_date1(node, xml, type)
|
66
|
-
date = node.attr("#{type}-date")
|
67
|
-
date and xml.date **{ type: type } do |d|
|
68
|
-
d.on date
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def datetypes
|
73
|
-
%w{ published accessed created implemented obsoleted
|
74
|
-
confirmed updated issued circulated unchanged received
|
75
|
-
vote-started vote-ended announced }
|
76
|
-
end
|
77
|
-
|
78
|
-
def metadata_date(node, xml)
|
79
|
-
datetypes.each { |t| metadata_date1(node, xml, t) }
|
80
|
-
node.attributes.each_key do |a|
|
81
|
-
next unless a == "date" || /^date_\d+$/.match(a)
|
82
|
-
|
83
|
-
type, date = node.attr(a).split(/ /, 2)
|
84
|
-
type or next
|
85
|
-
xml.date **{ type: type } do |d|
|
86
|
-
d.on date
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def metadata_language(node, xml)
|
92
|
-
xml.language (node.attr("language") || "en")
|
93
|
-
end
|
94
|
-
|
95
|
-
def metadata_script(node, xml)
|
96
|
-
xml.script (node.attr("script") ||
|
97
|
-
default_script(node.attr("language")))
|
98
|
-
end
|
99
|
-
|
100
|
-
def relaton_relations
|
101
|
-
%w(part-of translated-from)
|
102
|
-
end
|
103
|
-
|
104
|
-
def relaton_relation_descriptions
|
105
|
-
{}
|
106
|
-
end
|
107
|
-
|
108
|
-
def metadata_relations(node, xml)
|
109
|
-
relaton_relations.each do |t|
|
110
|
-
metadata_getrelation(node, xml, t)
|
111
|
-
end
|
112
|
-
relaton_relation_descriptions.each do |k, v|
|
113
|
-
metadata_getrelation(node, xml, v, k)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def relation_normalise(type)
|
118
|
-
type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
|
119
|
-
.sub(/-in$/, "In")
|
120
|
-
end
|
121
|
-
|
122
|
-
def metadata_getrelation(node, xml, type, desc = nil)
|
123
|
-
docs = node.attr(desc || type) || return
|
124
|
-
HTMLEntities.new.decode(docs).split(/;\s*/).each do |d|
|
125
|
-
id = d.split(/,\s*/)
|
126
|
-
xml.relation **{ type: relation_normalise(type) } do |r|
|
127
|
-
desc.nil? or r.description relation_normalise(desc)
|
128
|
-
fetch_ref(r, d, nil, **{}) or r.bibitem do |b|
|
129
|
-
b.title id[1] || "--"
|
130
|
-
b.docidentifier id[0]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def metadata_keywords(node, xml)
|
137
|
-
return unless node.attr("keywords")
|
138
|
-
|
139
|
-
node.attr("keywords").split(/,\s*/).each do |kw|
|
140
|
-
xml.keyword kw
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def metadata_classifications(node, xml)
|
145
|
-
csv_split(node.attr("classification"), ",")&.each do |c|
|
146
|
-
vals = c.split(/:/, 2)
|
147
|
-
vals.size == 1 and vals = ["default", vals[0]]
|
148
|
-
xml.classification vals[1], type: vals[0]
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def metadata(node, xml)
|
153
|
-
title node, xml
|
154
|
-
metadata_source(node, xml)
|
155
|
-
metadata_id(node, xml)
|
156
|
-
metadata_other_id(node, xml)
|
157
|
-
metadata_date(node, xml)
|
158
|
-
metadata_author(node, xml)
|
159
|
-
metadata_publisher(node, xml)
|
160
|
-
metadata_version(node, xml)
|
161
|
-
metadata_note(node, xml)
|
162
|
-
metadata_language(node, xml)
|
163
|
-
metadata_script(node, xml)
|
164
|
-
metadata_status(node, xml)
|
165
|
-
metadata_copyright(node, xml)
|
166
|
-
metadata_relations(node, xml)
|
167
|
-
metadata_series(node, xml)
|
168
|
-
metadata_classifications(node, xml)
|
169
|
-
metadata_keywords(node, xml)
|
170
|
-
xml.ext do
|
171
|
-
metadata_ext(node, xml)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def metadata_ext(node, ext)
|
176
|
-
metadata_doctype(node, ext)
|
177
|
-
metadata_subdoctype(node, ext)
|
178
|
-
metadata_committee(node, ext)
|
179
|
-
metadata_ics(node, ext)
|
180
|
-
end
|
181
|
-
|
182
|
-
def metadata_doctype(node, xml)
|
183
|
-
xml.doctype doctype(node)
|
184
|
-
end
|
185
|
-
|
186
|
-
def metadata_subdoctype(node, xml)
|
187
|
-
s = node.attr("docsubtype") and xml.subdoctype s
|
188
|
-
end
|
189
|
-
|
190
|
-
def metadata_note(node, xml); end
|
191
|
-
|
192
|
-
def metadata_series(node, xml); end
|
193
|
-
|
194
|
-
def title(node, xml)
|
195
|
-
title_english(node, xml)
|
196
|
-
title_otherlangs(node, xml)
|
197
|
-
end
|
198
|
-
|
199
|
-
def title_english(node, xml)
|
200
|
-
["en"].each do |lang|
|
201
|
-
at = { language: lang, format: "text/plain" }
|
202
|
-
xml.title **attr_code(at) do |t|
|
203
|
-
t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
|
204
|
-
node.attr("title-en")) ||
|
205
|
-
node.title)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def title_otherlangs(node, xml)
|
211
|
-
node.attributes.each do |k, v|
|
212
|
-
next unless /^title-(?<titlelang>.+)$/ =~ k
|
213
|
-
next if titlelang == "en"
|
214
|
-
|
215
|
-
xml.title v, { language: titlelang, format: "text/plain" }
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
@@ -1,192 +1,3 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "htmlentities"
|
4
|
-
require "pathname"
|
5
|
-
require "csv"
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/front_contributor"
|
6
3
|
|
7
|
-
module Asciidoctor
|
8
|
-
module Standoc
|
9
|
-
module Front
|
10
|
-
def committee_component(compname, node, out)
|
11
|
-
out.send compname.gsub(/-/, "_"), node.attr(compname),
|
12
|
-
**attr_code(number: node.attr("#{compname}-number"),
|
13
|
-
type: node.attr("#{compname}-type"))
|
14
|
-
i = 2
|
15
|
-
while node.attr(compname + "_#{i}")
|
16
|
-
out.send compname.gsub(/-/, "_"), node.attr(compname + "_#{i}"),
|
17
|
-
**attr_code(number: node.attr("#{compname}-number_#{i}"),
|
18
|
-
type: node.attr("#{compname}-type_#{i}"))
|
19
|
-
i += 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def organization(org, orgname, is_pub, node = nil, default_org = nil)
|
24
|
-
abbrevs = org_abbrev
|
25
|
-
n = abbrevs.invert[orgname] and orgname = n
|
26
|
-
org.name orgname
|
27
|
-
default_org and a = node.attr("subdivision") and org.subdivision a
|
28
|
-
abbr = org_abbrev[orgname]
|
29
|
-
default_org && b = node.attr("subdivision-abbr") and abbr = b
|
30
|
-
abbr and org.abbreviation abbr
|
31
|
-
is_pub && node and org_address(node, org)
|
32
|
-
end
|
33
|
-
|
34
|
-
def org_address(node, person)
|
35
|
-
node.attr("pub-address") and person.address do |ad|
|
36
|
-
ad.formattedAddress do |f|
|
37
|
-
f << node.attr("pub-address").gsub(/ \+\n/, "<br/>")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
node.attr("pub-phone") and person.phone node.attr("pub-phone")
|
41
|
-
node.attr("pub-fax") and
|
42
|
-
person.phone node.attr("pub-fax"), **{ type: "fax" }
|
43
|
-
node.attr("pub-email") and person.email node.attr("pub-email")
|
44
|
-
node.attr("pub-uri") and person.uri node.attr("pub-uri")
|
45
|
-
end
|
46
|
-
|
47
|
-
# , " => ," : CSV definition does not deal with space followed by quote
|
48
|
-
# at start of field
|
49
|
-
def csv_split(text, delim = ";")
|
50
|
-
return if text.nil?
|
51
|
-
|
52
|
-
CSV.parse_line(text&.gsub(/#{delim} "(?!")/, "#{delim}\""),
|
53
|
-
liberal_parsing: true,
|
54
|
-
col_sep: delim)&.compact&.map(&:strip)
|
55
|
-
end
|
56
|
-
|
57
|
-
def metadata_author(node, xml)
|
58
|
-
csv_split(node.attr("publisher") || default_publisher || "")
|
59
|
-
&.each do |p|
|
60
|
-
xml.contributor do |c|
|
61
|
-
c.role **{ type: "author" }
|
62
|
-
c.organization do |a|
|
63
|
-
organization(a, p, false, node, !node.attr("publisher"))
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
personal_author(node, xml)
|
68
|
-
end
|
69
|
-
|
70
|
-
def personal_author(node, xml)
|
71
|
-
(node.attr("fullname") || node.attr("surname")) and
|
72
|
-
personal_author1(node, xml, "")
|
73
|
-
i = 2
|
74
|
-
while node.attr("fullname_#{i}") || node.attr("surname_#{i}")
|
75
|
-
personal_author1(node, xml, "_#{i}")
|
76
|
-
i += 1
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def personal_role(node, contrib, suffix)
|
81
|
-
type = node.attr("role#{suffix}")&.downcase || "author"
|
82
|
-
contrib.role **{ type: type }
|
83
|
-
end
|
84
|
-
|
85
|
-
def personal_contact(node, suffix, person)
|
86
|
-
node.attr("phone#{suffix}") and person.phone node.attr("phone#{suffix}")
|
87
|
-
node.attr("fax#{suffix}") and
|
88
|
-
person.phone node.attr("fax#{suffix}"), **{ type: "fax" }
|
89
|
-
node.attr("email#{suffix}") and person.email node.attr("email#{suffix}")
|
90
|
-
node.attr("contributor-uri#{suffix}") and
|
91
|
-
person.uri node.attr("contributor-uri#{suffix}")
|
92
|
-
end
|
93
|
-
|
94
|
-
def personal_author1(node, xml, suffix)
|
95
|
-
xml.contributor do |c|
|
96
|
-
personal_role(node, c, suffix)
|
97
|
-
c.person do |p|
|
98
|
-
person_name(node, xml, suffix, p)
|
99
|
-
person_affiliation(node, xml, suffix, p)
|
100
|
-
personal_contact(node, suffix, p)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def person_name(node, _xml, suffix, person)
|
106
|
-
person.name do |n|
|
107
|
-
if node.attr("fullname#{suffix}")
|
108
|
-
n.completename node.attr("fullname#{suffix}")
|
109
|
-
else
|
110
|
-
n.forename node.attr("givenname#{suffix}")
|
111
|
-
n.initial node.attr("initials#{suffix}")
|
112
|
-
n.surname node.attr("surname#{suffix}")
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def person_affiliation(node, _xml, suffix, person)
|
118
|
-
node.attr("affiliation#{suffix}") and person.affiliation do |a|
|
119
|
-
a.organization do |o|
|
120
|
-
person_organization(node, suffix, o)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def person_organization(node, suffix, xml)
|
126
|
-
xml.name node.attr("affiliation#{suffix}")
|
127
|
-
abbr = node.attr("affiliation_abbrev#{suffix}") and
|
128
|
-
xml.abbreviation abbr
|
129
|
-
csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
|
130
|
-
xml.subdivision s
|
131
|
-
end
|
132
|
-
person_address(node, suffix, xml)
|
133
|
-
end
|
134
|
-
|
135
|
-
def person_address(node, suffix, xml)
|
136
|
-
if node.attr("address#{suffix}")
|
137
|
-
xml.address do |ad|
|
138
|
-
ad.formattedAddress do |f|
|
139
|
-
f << node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>")
|
140
|
-
end
|
141
|
-
end
|
142
|
-
elsif node.attr("country#{suffix}") || node.attr("city#{suffix}")
|
143
|
-
person_address_components(node, suffix, xml)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def person_address_components(node, suffix, xml)
|
148
|
-
xml.address do |ad|
|
149
|
-
s = node.attr("street#{suffix}") and ad.street s
|
150
|
-
s = node.attr("city#{suffix}") and ad.city s
|
151
|
-
s = node.attr("state#{suffix}") and ad.state s
|
152
|
-
s = node.attr("country#{suffix}") and ad.country s
|
153
|
-
s = node.attr("postcode#{suffix}") and ad.postcode s
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def default_publisher
|
158
|
-
nil
|
159
|
-
end
|
160
|
-
|
161
|
-
def org_abbrev
|
162
|
-
{}
|
163
|
-
end
|
164
|
-
|
165
|
-
def metadata_publisher(node, xml)
|
166
|
-
publishers = node.attr("publisher") || default_publisher || return
|
167
|
-
csv_split(publishers)&.each do |p|
|
168
|
-
xml.contributor do |c|
|
169
|
-
c.role **{ type: "publisher" }
|
170
|
-
c.organization do |a|
|
171
|
-
organization(a, p, true, node, !node.attr("publisher"))
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def metadata_copyright(node, xml)
|
178
|
-
pub = node.attr("copyright-holder") || node.attr("publisher")
|
179
|
-
csv_split(pub || default_publisher || "-")&.each do |p|
|
180
|
-
xml.copyright do |c|
|
181
|
-
c.from (node.attr("copyright-year") || Date.today.year)
|
182
|
-
p.match(/[A-Za-z]/).nil? or c.owner do |owner|
|
183
|
-
owner.organization do |a|
|
184
|
-
organization(a, p, true, node, !pub)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
@@ -1,230 +1,3 @@
|
|
1
|
-
require "asciidoctor/
|
2
|
-
require "
|
3
|
-
require "unicode2latex"
|
4
|
-
require "mime/types"
|
5
|
-
require "base64"
|
6
|
-
require "English"
|
7
|
-
require "latexmath"
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/inline"
|
8
3
|
|
9
|
-
module Asciidoctor
|
10
|
-
module Standoc
|
11
|
-
module Inline
|
12
|
-
def refid?(ref)
|
13
|
-
@refids.include? ref
|
14
|
-
end
|
15
|
-
|
16
|
-
def inline_anchor(node)
|
17
|
-
case node.type
|
18
|
-
when :ref
|
19
|
-
inline_anchor_ref node
|
20
|
-
when :xref
|
21
|
-
inline_anchor_xref node
|
22
|
-
when :link
|
23
|
-
inline_anchor_link node
|
24
|
-
when :bibref
|
25
|
-
inline_anchor_bibref node
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def inline_anchor_ref(node)
|
30
|
-
noko do |xml|
|
31
|
-
xml.bookmark nil, **attr_code(id: node.id)
|
32
|
-
end.join
|
33
|
-
end
|
34
|
-
|
35
|
-
def inline_anchor_xref(node)
|
36
|
-
noko do |xml|
|
37
|
-
attrs = inline_anchor_xref_attrs(node)
|
38
|
-
c = attrs[:text]
|
39
|
-
attrs.delete(:text) unless c.nil?
|
40
|
-
xml.xref **attr_code(attrs) do |x|
|
41
|
-
x << c
|
42
|
-
end
|
43
|
-
end.join
|
44
|
-
end
|
45
|
-
|
46
|
-
def inline_anchor_xref_attrs(node)
|
47
|
-
m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
|
48
|
-
(?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
|
49
|
-
t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
|
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
|
-
end
|
57
|
-
|
58
|
-
def inline_anchor_link(node)
|
59
|
-
contents = node.text
|
60
|
-
contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
|
61
|
-
attributes = { "target": node.target, "alt": node.attr("title"),
|
62
|
-
"updatetype": node.attr("updatetype") }
|
63
|
-
noko do |xml|
|
64
|
-
xml.link **attr_code(attributes) do |l|
|
65
|
-
l << contents
|
66
|
-
end
|
67
|
-
end.join
|
68
|
-
end
|
69
|
-
|
70
|
-
def inline_anchor_bibref(node)
|
71
|
-
eref_contents = (node.text || node.target || node.id)
|
72
|
-
&.sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
|
73
|
-
eref_attributes = { id: node.target || node.id }
|
74
|
-
@refids << (node.target || node.id)
|
75
|
-
noko do |xml|
|
76
|
-
xml.ref **attr_code(eref_attributes) do |r|
|
77
|
-
r << eref_contents
|
78
|
-
end
|
79
|
-
end.join
|
80
|
-
end
|
81
|
-
|
82
|
-
def inline_callout(node)
|
83
|
-
noko do |xml|
|
84
|
-
xml.callout node.text
|
85
|
-
end.join
|
86
|
-
end
|
87
|
-
|
88
|
-
def inline_footnote(node)
|
89
|
-
@fn_number ||= 0
|
90
|
-
noko do |xml|
|
91
|
-
@fn_number += 1
|
92
|
-
xml.fn **{ reference: @fn_number } do |fn|
|
93
|
-
fn.p { |p| p << node.text }
|
94
|
-
end
|
95
|
-
end.join
|
96
|
-
end
|
97
|
-
|
98
|
-
def inline_break(node)
|
99
|
-
noko do |xml|
|
100
|
-
xml << node.text
|
101
|
-
xml.br
|
102
|
-
end.join
|
103
|
-
end
|
104
|
-
|
105
|
-
def page_break(node)
|
106
|
-
attrs = {}
|
107
|
-
node.option?("landscape") and attrs[:orientation] = "landscape"
|
108
|
-
node.option?("portrait") and attrs[:orientation] = "portrait"
|
109
|
-
noko { |xml| xml.pagebreak **attr_code(attrs) }.join
|
110
|
-
end
|
111
|
-
|
112
|
-
def thematic_break(_node)
|
113
|
-
noko { |xml| xml.hr }.join
|
114
|
-
end
|
115
|
-
|
116
|
-
def xml_encode(text)
|
117
|
-
HTMLEntities.new.encode(text, :basic, :hexadecimal)
|
118
|
-
.gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
|
119
|
-
.gsub(/>/, ">").gsub(/</, "<").gsub(/&/, "&")
|
120
|
-
.gsub(/"/, '"').gsub(/
/, "\n").gsub(/&#/, "&#")
|
121
|
-
end
|
122
|
-
|
123
|
-
def latex_parse1(text)
|
124
|
-
lxm_input = Unicode2LaTeX.unicode2latex(HTMLEntities.new.decode(text))
|
125
|
-
results = Latexmath.parse(lxm_input).to_mathml
|
126
|
-
results.nil? and
|
127
|
-
@log.add("Math", nil,
|
128
|
-
"latexmlmath failed to process equation:\n#{lxm_input}")
|
129
|
-
results&.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
|
130
|
-
end
|
131
|
-
|
132
|
-
def stem_parse(text, xml, style)
|
133
|
-
if /<([^:>&]+:)?math(\s+[^>&]+)?> |
|
134
|
-
<([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
|
135
|
-
math = xml_encode(text)
|
136
|
-
xml.stem math, **{ type: "MathML" }
|
137
|
-
elsif style == :latexmath then latex_parse(text, xml)
|
138
|
-
else
|
139
|
-
xml.stem text&.gsub(/&#/, "&#"), **{ type: "AsciiMath" }
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
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
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def highlight_parse(text, xml)
|
154
|
-
xml << text
|
155
|
-
end
|
156
|
-
|
157
|
-
def inline_quoted(node)
|
158
|
-
noko do |xml|
|
159
|
-
case node.type
|
160
|
-
when :emphasis then xml.em { |s| s << node.text }
|
161
|
-
when :strong then xml.strong { |s| s << node.text }
|
162
|
-
when :monospaced then xml.tt { |s| s << node.text }
|
163
|
-
when :double then xml << "\"#{node.text}\""
|
164
|
-
when :single then xml << "'#{node.text}'"
|
165
|
-
when :superscript then xml.sup { |s| s << node.text }
|
166
|
-
when :subscript then xml.sub { |s| s << node.text }
|
167
|
-
when :asciimath then stem_parse(node.text, xml, :asciimath)
|
168
|
-
when :latexmath then stem_parse(node.text, xml, :latexmath)
|
169
|
-
when :mark then highlight_parse(node.text, xml)
|
170
|
-
else
|
171
|
-
case node.role
|
172
|
-
# the following three are legacy, they are now handled by macros
|
173
|
-
when "alt"
|
174
|
-
term_designation(xml, node, "admitted", node.text)
|
175
|
-
when "deprecated"
|
176
|
-
term_designation(xml, node, "deprecates", node.text)
|
177
|
-
when "domain" then xml.domain { |a| a << node.text }
|
178
|
-
|
179
|
-
when "strike" then xml.strike { |s| s << node.text }
|
180
|
-
when "underline" then xml.underline { |s| s << node.text }
|
181
|
-
when "smallcap" then xml.smallcap { |s| s << node.text }
|
182
|
-
when "keyword" then xml.keyword { |s| s << node.text }
|
183
|
-
else
|
184
|
-
xml << node.text
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end.join
|
188
|
-
end
|
189
|
-
|
190
|
-
def image_attributes(node)
|
191
|
-
uri = node.image_uri (node.attr("target") || node.target)
|
192
|
-
types = if /^data:/.match?(uri) then Metanorma::Utils::datauri2mime(uri)
|
193
|
-
else MIME::Types.type_for(uri)
|
194
|
-
end
|
195
|
-
type = types.first.to_s
|
196
|
-
uri = uri.sub(%r{^data:image/\*;}, "data:#{type};")
|
197
|
-
image_attributes1(node, uri, type)
|
198
|
-
end
|
199
|
-
|
200
|
-
def image_attributes1(node, uri, type)
|
201
|
-
attr_code(src: uri,
|
202
|
-
id: Metanorma::Utils::anchor_or_uuid,
|
203
|
-
mimetype: type,
|
204
|
-
height: node.attr("height") || "auto",
|
205
|
-
width: node.attr("width") || "auto",
|
206
|
-
filename: node.attr("filename"),
|
207
|
-
title: node.attr("titleattr"),
|
208
|
-
alt: node.alt == node.attr("default-alt") ? nil : node.alt)
|
209
|
-
end
|
210
|
-
|
211
|
-
def inline_image(node)
|
212
|
-
noko do |xml|
|
213
|
-
xml.image **image_attributes(node)
|
214
|
-
end.join
|
215
|
-
end
|
216
|
-
|
217
|
-
def inline_indexterm(node)
|
218
|
-
noko do |xml|
|
219
|
-
node.type == :visible and xml << node.text
|
220
|
-
terms = (node.attr("terms") || [node.text]).map { |x| xml_encode(x) }
|
221
|
-
xml.index do |i|
|
222
|
-
i.primary { |x| x << terms[0] }
|
223
|
-
a = terms[1] and i.secondary { |x| x << a }
|
224
|
-
a = terms[2] and i.tertiary { |x| x << a }
|
225
|
-
end
|
226
|
-
end.join
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|