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,224 @@
|
|
1
|
+
require "date"
|
2
|
+
require "nokogiri"
|
3
|
+
require "htmlentities"
|
4
|
+
require "pathname"
|
5
|
+
require_relative "./front_contributor"
|
6
|
+
|
7
|
+
module Metanorma
|
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
|
+
Metanorma::Utils.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) or return
|
124
|
+
HTMLEntities.new.decode(docs).split(/;\s*/).each do |d|
|
125
|
+
metadata_getrelation1(d, xml, type, desc)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def metadata_getrelation1(doc, xml, type, desc)
|
130
|
+
id = doc.split(/,\s*/)
|
131
|
+
xml.relation **{ type: relation_normalise(type) } do |r|
|
132
|
+
desc.nil? or r.description desc.gsub(/-/, " ")
|
133
|
+
fetch_ref(r, doc, nil, **{}) or r.bibitem do |b|
|
134
|
+
b.title id[1] || "--"
|
135
|
+
b.docidentifier id[0]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def metadata_keywords(node, xml)
|
141
|
+
return unless node.attr("keywords")
|
142
|
+
|
143
|
+
node.attr("keywords").split(/,\s*/).each do |kw|
|
144
|
+
xml.keyword kw
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def metadata_classifications(node, xml)
|
149
|
+
csv_split(node.attr("classification"), ",")&.each do |c|
|
150
|
+
vals = c.split(/:/, 2)
|
151
|
+
vals.size == 1 and vals = ["default", vals[0]]
|
152
|
+
xml.classification vals[1], type: vals[0]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def metadata(node, xml)
|
157
|
+
title node, xml
|
158
|
+
metadata_source(node, xml)
|
159
|
+
metadata_id(node, xml)
|
160
|
+
metadata_other_id(node, xml)
|
161
|
+
metadata_date(node, xml)
|
162
|
+
metadata_author(node, xml)
|
163
|
+
metadata_publisher(node, xml)
|
164
|
+
metadata_version(node, xml)
|
165
|
+
metadata_note(node, xml)
|
166
|
+
metadata_language(node, xml)
|
167
|
+
metadata_script(node, xml)
|
168
|
+
metadata_status(node, xml)
|
169
|
+
metadata_copyright(node, xml)
|
170
|
+
metadata_relations(node, xml)
|
171
|
+
metadata_series(node, xml)
|
172
|
+
metadata_classifications(node, xml)
|
173
|
+
metadata_keywords(node, xml)
|
174
|
+
xml.ext do
|
175
|
+
metadata_ext(node, xml)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def metadata_ext(node, ext)
|
180
|
+
metadata_doctype(node, ext)
|
181
|
+
metadata_subdoctype(node, ext)
|
182
|
+
metadata_committee(node, ext)
|
183
|
+
metadata_ics(node, ext)
|
184
|
+
end
|
185
|
+
|
186
|
+
def metadata_doctype(node, xml)
|
187
|
+
xml.doctype doctype(node)
|
188
|
+
end
|
189
|
+
|
190
|
+
def metadata_subdoctype(node, xml)
|
191
|
+
s = node.attr("docsubtype") and xml.subdoctype s
|
192
|
+
end
|
193
|
+
|
194
|
+
def metadata_note(node, xml); end
|
195
|
+
|
196
|
+
def metadata_series(node, xml); end
|
197
|
+
|
198
|
+
def title(node, xml)
|
199
|
+
title_english(node, xml)
|
200
|
+
title_otherlangs(node, xml)
|
201
|
+
end
|
202
|
+
|
203
|
+
def title_english(node, xml)
|
204
|
+
["en"].each do |lang|
|
205
|
+
at = { language: lang, format: "text/plain" }
|
206
|
+
xml.title **attr_code(at) do |t|
|
207
|
+
t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
|
208
|
+
node.attr("title-en")) ||
|
209
|
+
node.title)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def title_otherlangs(node, xml)
|
215
|
+
node.attributes.each do |k, v|
|
216
|
+
next unless /^title-(?<titlelang>.+)$/ =~ k
|
217
|
+
next if titlelang == "en"
|
218
|
+
|
219
|
+
xml.title v, { language: titlelang, format: "text/plain" }
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require "date"
|
2
|
+
require "nokogiri"
|
3
|
+
require "htmlentities"
|
4
|
+
require "pathname"
|
5
|
+
require "csv"
|
6
|
+
|
7
|
+
module Metanorma
|
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
|
@@ -0,0 +1,232 @@
|
|
1
|
+
require "asciidoctor/extensions"
|
2
|
+
require "htmlentities"
|
3
|
+
require "unicode2latex"
|
4
|
+
require "mime/types"
|
5
|
+
require "base64"
|
6
|
+
require "English"
|
7
|
+
require "latexmath"
|
8
|
+
|
9
|
+
module Metanorma
|
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 then inline_anchor_ref node
|
19
|
+
when :xref then inline_anchor_xref node
|
20
|
+
when :link then inline_anchor_link node
|
21
|
+
when :bibref then inline_anchor_bibref node
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def inline_anchor_ref(node)
|
26
|
+
noko do |xml|
|
27
|
+
xml.bookmark nil, **attr_code(id: node.id)
|
28
|
+
end.join
|
29
|
+
end
|
30
|
+
|
31
|
+
def inline_anchor_xref(node)
|
32
|
+
noko do |xml|
|
33
|
+
attrs = inline_anchor_xref_attrs(node)
|
34
|
+
c = attrs[:text]
|
35
|
+
attrs.delete(:text) unless c.nil?
|
36
|
+
xml.xref **attr_code(attrs) do |x|
|
37
|
+
x << c
|
38
|
+
end
|
39
|
+
end.join
|
40
|
+
end
|
41
|
+
|
42
|
+
def inline_anchor_xref_attrs(node)
|
43
|
+
m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
|
44
|
+
(?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
|
45
|
+
t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2")
|
46
|
+
m.nil? and return { target: t, type: "inline", text: node.text }
|
47
|
+
droploc = m[:drop].nil? && m[:drop2].nil? ? nil : true
|
48
|
+
f = m[:fn].nil? ? "inline" : "footnote"
|
49
|
+
c = if %i[case fn drop drop2].any? do |x|
|
50
|
+
!m[x].nil?
|
51
|
+
end
|
52
|
+
m[:text]
|
53
|
+
else node.text
|
54
|
+
end
|
55
|
+
{ target: t, type: f, case: m[:case]&.sub(/%$/, ""), droploc: droploc,
|
56
|
+
text: c }
|
57
|
+
end
|
58
|
+
|
59
|
+
def inline_anchor_link(node)
|
60
|
+
contents = node.text
|
61
|
+
contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text
|
62
|
+
attributes = { target: node.target, alt: node.attr("title"),
|
63
|
+
"update-type": node.attr("updatetype") ||
|
64
|
+
node.attr("update-type") }
|
65
|
+
noko do |xml|
|
66
|
+
xml.link **attr_code(attributes) do |l|
|
67
|
+
l << contents
|
68
|
+
end
|
69
|
+
end.join
|
70
|
+
end
|
71
|
+
|
72
|
+
def inline_anchor_bibref(node)
|
73
|
+
eref_contents = (node.text || node.target || node.id)
|
74
|
+
&.sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
|
75
|
+
eref_attributes = { id: node.target || node.id }
|
76
|
+
@refids << (node.target || node.id)
|
77
|
+
noko do |xml|
|
78
|
+
xml.ref **attr_code(eref_attributes) do |r|
|
79
|
+
r << eref_contents
|
80
|
+
end
|
81
|
+
end.join
|
82
|
+
end
|
83
|
+
|
84
|
+
def inline_callout(node)
|
85
|
+
noko do |xml|
|
86
|
+
xml.callout node.text
|
87
|
+
end.join
|
88
|
+
end
|
89
|
+
|
90
|
+
def inline_footnote(node)
|
91
|
+
@fn_number ||= 0
|
92
|
+
noko do |xml|
|
93
|
+
@fn_number += 1
|
94
|
+
xml.fn **{ reference: @fn_number } do |fn|
|
95
|
+
fn.p { |p| p << node.text }
|
96
|
+
end
|
97
|
+
end.join
|
98
|
+
end
|
99
|
+
|
100
|
+
def inline_break(node)
|
101
|
+
noko do |xml|
|
102
|
+
xml << node.text
|
103
|
+
xml.br
|
104
|
+
end.join
|
105
|
+
end
|
106
|
+
|
107
|
+
def page_break(node)
|
108
|
+
attrs = {}
|
109
|
+
node.option?("landscape") and attrs[:orientation] = "landscape"
|
110
|
+
node.option?("portrait") and attrs[:orientation] = "portrait"
|
111
|
+
noko { |xml| xml.pagebreak **attr_code(attrs) }.join
|
112
|
+
end
|
113
|
+
|
114
|
+
def thematic_break(_node)
|
115
|
+
noko { |xml| xml.hr }.join
|
116
|
+
end
|
117
|
+
|
118
|
+
def xml_encode(text)
|
119
|
+
HTMLEntities.new.encode(text, :basic, :hexadecimal)
|
120
|
+
.gsub(/&gt;/, ">").gsub(/&lt;/, "<").gsub(/&amp;/, "&")
|
121
|
+
.gsub(/>/, ">").gsub(/</, "<").gsub(/&/, "&")
|
122
|
+
.gsub(/"/, '"').gsub(/
/, "\n").gsub(/&#/, "&#")
|
123
|
+
end
|
124
|
+
|
125
|
+
def latex_parse1(text)
|
126
|
+
lxm_input = Unicode2LaTeX.unicode2latex(HTMLEntities.new.decode(text))
|
127
|
+
results = Latexmath.parse(lxm_input).to_mathml
|
128
|
+
results.nil? and
|
129
|
+
@log.add("Math", nil,
|
130
|
+
"latexmlmath failed to process equation:\n#{lxm_input}")
|
131
|
+
results&.sub(%r{<math ([^>]+ )?display="block"}, "<math \\1")
|
132
|
+
end
|
133
|
+
|
134
|
+
def stem_parse(text, xml, style)
|
135
|
+
if /<([^:>&]+:)?math(\s+[^>&]+)?> |
|
136
|
+
<([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text
|
137
|
+
math = xml_encode(text)
|
138
|
+
xml.stem math, **{ type: "MathML" }
|
139
|
+
elsif style == :latexmath then latex_parse(text, xml)
|
140
|
+
else
|
141
|
+
xml.stem text&.gsub(/&#/, "&#"), **{ type: "AsciiMath" }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def latex_parse(text, xml)
|
146
|
+
latex = latex_parse1(text) or return xml.stem **{ type: "MathML" }
|
147
|
+
xml.stem **{ type: "MathML" } do |s|
|
148
|
+
math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, ""))
|
149
|
+
.elements[0]
|
150
|
+
math.delete("alttext")
|
151
|
+
s.parent.children = math
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def highlight_parse(text, xml)
|
156
|
+
xml << text
|
157
|
+
end
|
158
|
+
|
159
|
+
def inline_quoted(node)
|
160
|
+
noko do |xml|
|
161
|
+
case node.type
|
162
|
+
when :emphasis then xml.em { |s| s << node.text }
|
163
|
+
when :strong then xml.strong { |s| s << node.text }
|
164
|
+
when :monospaced then xml.tt { |s| s << node.text }
|
165
|
+
when :double then xml << "\"#{node.text}\""
|
166
|
+
when :single then xml << "'#{node.text}'"
|
167
|
+
when :superscript then xml.sup { |s| s << node.text }
|
168
|
+
when :subscript then xml.sub { |s| s << node.text }
|
169
|
+
when :asciimath then stem_parse(node.text, xml, :asciimath)
|
170
|
+
when :latexmath then stem_parse(node.text, xml, :latexmath)
|
171
|
+
when :mark then highlight_parse(node.text, xml)
|
172
|
+
else
|
173
|
+
case node.role
|
174
|
+
# the following three are legacy, they are now handled by macros
|
175
|
+
when "alt"
|
176
|
+
term_designation(xml, node, "admitted", node.text)
|
177
|
+
when "deprecated"
|
178
|
+
term_designation(xml, node, "deprecates", node.text)
|
179
|
+
when "domain" then xml.domain { |a| a << node.text }
|
180
|
+
|
181
|
+
when "strike" then xml.strike { |s| s << node.text }
|
182
|
+
when "underline" then xml.underline { |s| s << node.text }
|
183
|
+
when "smallcap" then xml.smallcap { |s| s << node.text }
|
184
|
+
when "keyword" then xml.keyword { |s| s << node.text }
|
185
|
+
else
|
186
|
+
xml << node.text
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end.join
|
190
|
+
end
|
191
|
+
|
192
|
+
def image_attributes(node)
|
193
|
+
uri = node.image_uri (node.attr("target") || node.target)
|
194
|
+
types = if /^data:/.match?(uri) then Metanorma::Utils::datauri2mime(uri)
|
195
|
+
else MIME::Types.type_for(uri)
|
196
|
+
end
|
197
|
+
type = types.first.to_s
|
198
|
+
uri = uri.sub(%r{^data:image/\*;}, "data:#{type};")
|
199
|
+
image_attributes1(node, uri, type)
|
200
|
+
end
|
201
|
+
|
202
|
+
def image_attributes1(node, uri, type)
|
203
|
+
attr_code(src: uri,
|
204
|
+
id: Metanorma::Utils::anchor_or_uuid,
|
205
|
+
mimetype: type,
|
206
|
+
height: node.attr("height") || "auto",
|
207
|
+
width: node.attr("width") || "auto",
|
208
|
+
filename: node.attr("filename"),
|
209
|
+
title: node.attr("titleattr"),
|
210
|
+
alt: node.alt == node.attr("default-alt") ? nil : node.alt)
|
211
|
+
end
|
212
|
+
|
213
|
+
def inline_image(node)
|
214
|
+
noko do |xml|
|
215
|
+
xml.image **image_attributes(node)
|
216
|
+
end.join
|
217
|
+
end
|
218
|
+
|
219
|
+
def inline_indexterm(node)
|
220
|
+
noko do |xml|
|
221
|
+
node.type == :visible and xml << node.text
|
222
|
+
terms = (node.attr("terms") || [node.text]).map { |x| xml_encode(x) }
|
223
|
+
xml.index do |i|
|
224
|
+
i.primary { |x| x << terms[0] }
|
225
|
+
a = terms[1] and i.secondary { |x| x << a }
|
226
|
+
a = terms[2] and i.tertiary { |x| x << a }
|
227
|
+
end
|
228
|
+
end.join
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|