metanorma-standoc 1.7.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +17 -0
- data/lib/asciidoctor/standoc/base.rb +33 -44
- data/lib/asciidoctor/standoc/basicdoc.rng +5 -3
- data/lib/asciidoctor/standoc/blocks.rb +7 -7
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -2
- data/lib/asciidoctor/standoc/cleanup.rb +28 -77
- data/lib/asciidoctor/standoc/cleanup_block.rb +5 -15
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +56 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +22 -26
- data/lib/asciidoctor/standoc/cleanup_maths.rb +86 -0
- data/lib/asciidoctor/standoc/cleanup_ref.rb +0 -85
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +94 -0
- data/lib/asciidoctor/standoc/converter.rb +0 -61
- data/lib/asciidoctor/standoc/front.rb +2 -2
- data/lib/asciidoctor/standoc/inline.rb +2 -1
- data/lib/asciidoctor/standoc/isodoc.rng +29 -3
- 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 +4 -80
- data/lib/asciidoctor/standoc/table.rb +1 -1
- data/lib/asciidoctor/standoc/terms.rb +125 -0
- data/lib/asciidoctor/standoc/utils.rb +2 -96
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +2 -3
- data/spec/asciidoctor-standoc/base_spec.rb +34 -5
- data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +5 -5
- data/spec/asciidoctor-standoc/cleanup_spec.rb +178 -4
- data/spec/asciidoctor-standoc/inline_spec.rb +2 -0
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +4 -4
- data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +1 -1
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +17 -5
- data/spec/asciidoctor-standoc/refs_spec.rb +12 -12
- data/spec/asciidoctor-standoc/section_spec.rb +143 -3
- data/spec/asciidoctor-standoc/table_spec.rb +60 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +48 -48
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123_1.yml +26 -26
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +36 -36
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -14
- data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +56 -56
- metadata +19 -32
- data/lib/asciidoctor/standoc/log.rb +0 -59
- data/spec/asciidoctor-standoc/converter_spec.rb +0 -8
@@ -106,6 +106,7 @@ module Asciidoctor
|
|
106
106
|
def bibdata_cleanup(xmldoc)
|
107
107
|
bibdata_anchor_cleanup(xmldoc)
|
108
108
|
bibdata_docidentifier_cleanup(xmldoc)
|
109
|
+
biblio_indirect_erefs(xmldoc, @internal_eref_namespaces&.uniq)
|
109
110
|
end
|
110
111
|
|
111
112
|
def bibdata_anchor_cleanup(xmldoc)
|
@@ -122,6 +123,61 @@ module Asciidoctor
|
|
122
123
|
ins = ins.next
|
123
124
|
end
|
124
125
|
end
|
126
|
+
|
127
|
+
def gather_indirect_erefs(xmldoc, prefix)
|
128
|
+
xmldoc.xpath("//eref[@type = '#{prefix}']").each_with_object({}) do |e, m|
|
129
|
+
e.delete("type")
|
130
|
+
m[e["bibitemid"]] = true
|
131
|
+
end.keys
|
132
|
+
end
|
133
|
+
|
134
|
+
def insert_indirect_biblio(xmldoc, refs, prefix)
|
135
|
+
ins = xmldoc.at("bibliography") or
|
136
|
+
xmldoc.root << "<bibliography/>" and ins = xmldoc.at("bibliography")
|
137
|
+
ins = ins.add_child("<references hidden='true' normative='false'/>").first
|
138
|
+
refs.each do |x|
|
139
|
+
ins << <<~END
|
140
|
+
<bibitem id="#{x}" type="internal">
|
141
|
+
<docidentifier type="repository">#{x.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
|
142
|
+
</bibitem>
|
143
|
+
END
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def indirect_eref_to_xref(e, id)
|
148
|
+
loc = e&.at("./localityStack[locality[@type = 'anchor']]")&.remove&.text ||
|
149
|
+
e&.at("./locality[@type = 'anchor']")&.remove&.text || id
|
150
|
+
e.name = "xref"
|
151
|
+
e.delete("bibitemid")
|
152
|
+
e.delete("citeas")
|
153
|
+
e["target"] = loc
|
154
|
+
unless e.document.at("//*[@id = '#{loc}']")
|
155
|
+
e.children = %(** Missing target #{loc})
|
156
|
+
e["target"] = id
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def resolve_local_indirect_erefs(xmldoc, refs, prefix)
|
161
|
+
refs.each_with_object([]) do |r, m|
|
162
|
+
id = r.sub(/^#{prefix}_/, "")
|
163
|
+
if xmldoc.at("//*[@id = '#{id}'][@type = '#{prefix}']")
|
164
|
+
xmldoc.xpath("//eref[@bibitemid = '#{r}']").each do |e|
|
165
|
+
indirect_eref_to_xref(e, id)
|
166
|
+
end
|
167
|
+
else
|
168
|
+
m << r
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def biblio_indirect_erefs(xmldoc, prefixes)
|
174
|
+
prefixes&.each do |prefix|
|
175
|
+
refs = gather_indirect_erefs(xmldoc, prefix)
|
176
|
+
refs = resolve_local_indirect_erefs(xmldoc, refs, prefix)
|
177
|
+
refs.empty? and next
|
178
|
+
insert_indirect_biblio(xmldoc, refs, prefix)
|
179
|
+
end
|
180
|
+
end
|
125
181
|
end
|
126
182
|
end
|
127
183
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "metanorma-utils"
|
2
|
+
|
1
3
|
module Asciidoctor
|
2
4
|
module Standoc
|
3
5
|
module Cleanup
|
@@ -82,6 +84,8 @@ module Asciidoctor
|
|
82
84
|
|
83
85
|
def xref_cleanup(xmldoc)
|
84
86
|
xmldoc.xpath("//xref").each do |x|
|
87
|
+
/:/.match(x["target"]) and xref_to_internal_eref(x)
|
88
|
+
next unless x.name == "xref"
|
85
89
|
if refid? x["target"]
|
86
90
|
x.name = "eref"
|
87
91
|
xref_to_eref(x)
|
@@ -91,6 +95,18 @@ module Asciidoctor
|
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
98
|
+
def xref_to_internal_eref(x)
|
99
|
+
a = x["target"].split(":", 3)
|
100
|
+
unless a.size < 2 || a[0].empty? || a[1].empty?
|
101
|
+
x["target"] = "#{a[0]}_#{a[1]}"
|
102
|
+
a.size > 2 and x.children = %{anchor="#{a[2..-1].join("")}",#{x&.children&.text}}
|
103
|
+
x["type"] = a[0]
|
104
|
+
@internal_eref_namespaces << a[0]
|
105
|
+
x.name = "eref"
|
106
|
+
xref_to_eref(x)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
94
110
|
def quotesource_cleanup(xmldoc)
|
95
111
|
xmldoc.xpath("//quote/source | //terms/source").each do |x|
|
96
112
|
xref_to_eref(x)
|
@@ -139,29 +155,11 @@ module Asciidoctor
|
|
139
155
|
extract_localities(x.first_element_child)
|
140
156
|
end
|
141
157
|
|
142
|
-
NAMECHAR = "\u0000-\u0022\u0024\u002c\u002f\u003a-\u0040\\u005b-\u005e"\
|
143
|
-
"\u0060\u007b-\u00b6\u00b8-\u00bf\u00d7\u00f7\u037e\u2000-\u200b"\
|
144
|
-
"\u200e-\u203e\u2041-\u206f\u2190-\u2bff\u2ff0-\u3000".freeze
|
145
|
-
#"\ud800-\uf8ff\ufdd0-\ufdef\ufffe-\uffff".freeze
|
146
|
-
NAMESTARTCHAR = "\\u002d\u002e\u0030-\u0039\u00b7\u0300-\u036f"\
|
147
|
-
"\u203f-\u2040".freeze
|
148
|
-
|
149
|
-
def to_ncname(s)
|
150
|
-
start = s[0]
|
151
|
-
ret1 = %r([#{NAMECHAR}#]).match(start) ? "_" :
|
152
|
-
(%r([#{NAMESTARTCHAR}#]).match(start) ? "_#{start}" : start)
|
153
|
-
ret2 = s[1..-1] || ""
|
154
|
-
ret = (ret1 || "") + ret2.gsub(%r([#{NAMECHAR}#]), "_")
|
155
|
-
ret
|
156
|
-
end
|
157
|
-
|
158
|
-
module_function :to_ncname
|
159
|
-
|
160
158
|
def to_xreftarget(s)
|
161
|
-
return to_ncname(s) unless /^[^#]+#.+$/.match(s)
|
159
|
+
return Metanorma::Utils::to_ncname(s) unless /^[^#]+#.+$/.match(s)
|
162
160
|
/^(?<pref>[^#]+)#(?<suff>.+)$/ =~ s
|
163
|
-
pref = pref.gsub(%r([#{NAMECHAR}]), "_")
|
164
|
-
suff = suff.gsub(%r([#{NAMECHAR}]), "_")
|
161
|
+
pref = pref.gsub(%r([#{Metanorma::Utils::NAMECHAR}]), "_")
|
162
|
+
suff = suff.gsub(%r([#{Metanorma::Utils::NAMECHAR}]), "_")
|
165
163
|
"#{pref}##{suff}"
|
166
164
|
end
|
167
165
|
|
@@ -175,12 +173,11 @@ module Asciidoctor
|
|
175
173
|
|
176
174
|
def anchor_cleanup1(x)
|
177
175
|
x.xpath(IDREF).each do |s|
|
178
|
-
if (ret = to_ncname(s.value)) != (orig = s.value)
|
176
|
+
if (ret = Metanorma::Utils::to_ncname(s.value)) != (orig = s.value)
|
179
177
|
s.value = ret
|
180
178
|
output = s.parent.dup
|
181
179
|
output.children.remove
|
182
|
-
@log.add("Anchors", s.parent, "normalised identifier in #{output} "
|
183
|
-
"from #{orig}")
|
180
|
+
@log.add("Anchors", s.parent, "normalised identifier in #{output} from #{orig}")
|
184
181
|
end
|
185
182
|
end
|
186
183
|
end
|
@@ -191,8 +188,7 @@ module Asciidoctor
|
|
191
188
|
s.value = ret
|
192
189
|
output = s.parent.dup
|
193
190
|
output.children.remove
|
194
|
-
@log.add("Anchors", s.parent, "normalised identifier in #{output} "
|
195
|
-
"from #{orig}")
|
191
|
+
@log.add("Anchors", s.parent, "normalised identifier in #{output} from #{orig}")
|
196
192
|
end
|
197
193
|
end
|
198
194
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "pathname"
|
3
|
+
require "open-uri"
|
4
|
+
require "html2doc"
|
5
|
+
require_relative "./cleanup_block.rb"
|
6
|
+
require_relative "./cleanup_footnotes.rb"
|
7
|
+
require_relative "./cleanup_ref.rb"
|
8
|
+
require_relative "./cleanup_ref_dl.rb"
|
9
|
+
require_relative "./cleanup_boilerplate.rb"
|
10
|
+
require_relative "./cleanup_section.rb"
|
11
|
+
require_relative "./cleanup_terms.rb"
|
12
|
+
require_relative "./cleanup_inline.rb"
|
13
|
+
require_relative "./cleanup_amend.rb"
|
14
|
+
require "relaton_iev"
|
15
|
+
|
16
|
+
module Asciidoctor
|
17
|
+
module Standoc
|
18
|
+
module Cleanup
|
19
|
+
def asciimath2mathml(text)
|
20
|
+
text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do |m|
|
21
|
+
"<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
|
22
|
+
end
|
23
|
+
text = Html2Doc.asciimath_to_mathml(text, ["<amathstem>", "</amathstem>"])
|
24
|
+
x = Nokogiri::XML(text)
|
25
|
+
x.xpath("//*[local-name() = 'math'][not(parent::stem)]").each do |y|
|
26
|
+
y.wrap("<stem type='MathML'></stem>")
|
27
|
+
end
|
28
|
+
x.to_xml
|
29
|
+
end
|
30
|
+
|
31
|
+
def xml_unescape_mathml(x)
|
32
|
+
return if x.children.any? { |y| y.element? }
|
33
|
+
math = x.text.gsub(/</, "<").gsub(/>/, ">").gsub(/"/, '"').gsub(/'/, "'").gsub(/&/, "&").
|
34
|
+
gsub(/<[^: \r\n\t\/]+:/, "<").gsub(/<\/[^ \r\n\t:]+:/, "</")
|
35
|
+
x.children = math
|
36
|
+
end
|
37
|
+
|
38
|
+
MATHML_NS = "http://www.w3.org/1998/Math/MathML".freeze
|
39
|
+
|
40
|
+
def mathml_preserve_space(m)
|
41
|
+
m.xpath(".//m:mtext", "m" => MATHML_NS).each do |x|
|
42
|
+
x.children = x.children.to_xml.gsub(/^\s/, " ").gsub(/\s$/, " ")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def mathml_namespace(stem)
|
47
|
+
stem.xpath("./math", ).each { |x| x.default_namespace = MATHML_NS }
|
48
|
+
end
|
49
|
+
|
50
|
+
def mathml_mi_italics
|
51
|
+
{ uppergreek: true, upperroman: true,
|
52
|
+
lowergreek: true, lowerroman: true }
|
53
|
+
end
|
54
|
+
|
55
|
+
# presuppose multichar mi upright, singlechar mi MathML default italic
|
56
|
+
def mathml_italicise(x)
|
57
|
+
x.xpath(".//m:mi[not(ancestor::*[@mathvariant])]", "m" => MATHML_NS).each do |i|
|
58
|
+
char = HTMLEntities.new.decode(i.text)
|
59
|
+
i["mathvariant"] = "normal" if mi_italicise?(char)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def mi_italicise?(c)
|
64
|
+
return false if c.length > 1
|
65
|
+
if /\p{Greek}/.match(c)
|
66
|
+
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowergreek] ||
|
67
|
+
/\p{Upper}/.match(c) && !mathml_mi_italics[:uppergreek]
|
68
|
+
elsif /\p{Latin}/.match(c)
|
69
|
+
/\p{Lower}/.match(c) && !mathml_mi_italics[:lowerroman] ||
|
70
|
+
/\p{Upper}/.match(c) && !mathml_mi_italics[:upperroman]
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def mathml_cleanup(xmldoc)
|
77
|
+
xmldoc.xpath("//stem[@type = 'MathML']").each do |x|
|
78
|
+
xml_unescape_mathml(x)
|
79
|
+
mathml_namespace(x)
|
80
|
+
mathml_preserve_space(x)
|
81
|
+
mathml_italicise(x)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -120,91 +120,6 @@ module Asciidoctor
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
def ref_dl_cleanup(xmldoc)
|
124
|
-
xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
|
125
|
-
bib = dl_bib_extract(c) or next
|
126
|
-
validate_ref_dl(bib, c)
|
127
|
-
bibitemxml = RelatonBib::BibliographicItem.new(RelatonBib::HashConverter::hash_to_bib(bib)).to_xml or next
|
128
|
-
bibitem = Nokogiri::XML(bibitemxml)
|
129
|
-
bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
|
130
|
-
c.replace(bibitem.root)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def validate_ref_dl(bib, c)
|
135
|
-
id = bib["id"]
|
136
|
-
id ||= c["id"] unless /^_/.match(c["id"]) # do not accept implicit id
|
137
|
-
unless id
|
138
|
-
@log.add("Anchors", c, "The following reference is missing an anchor:\n" + c.to_xml)
|
139
|
-
return
|
140
|
-
end
|
141
|
-
bib["title"] or @log.add("Bibliography", c, "Reference #{id} is missing a title")
|
142
|
-
bib["docid"] or @log.add("Bibliography", c, "Reference #{id} is missing a document identifier (docid)")
|
143
|
-
end
|
144
|
-
|
145
|
-
def extract_from_p(tag, bib, key)
|
146
|
-
return unless bib[tag]
|
147
|
-
"<#{key}>#{bib[tag].at('p').children}</#{key}>"
|
148
|
-
end
|
149
|
-
|
150
|
-
# if the content is a single paragraph, replace it with its children
|
151
|
-
# single links replaced with uri
|
152
|
-
def p_unwrap(p)
|
153
|
-
elems = p.elements
|
154
|
-
if elems.size == 1 && elems[0].name == "p"
|
155
|
-
link_unwrap(elems[0]).children.to_xml.strip
|
156
|
-
else
|
157
|
-
p.to_xml.strip
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def link_unwrap(p)
|
162
|
-
elems = p.elements
|
163
|
-
if elems.size == 1 && elems[0].name == "link"
|
164
|
-
p.at("./link").replace(elems[0]["target"].strip)
|
165
|
-
end
|
166
|
-
p
|
167
|
-
end
|
168
|
-
|
169
|
-
def dd_bib_extract(dtd)
|
170
|
-
return nil if dtd.children.empty?
|
171
|
-
dtd.at("./dl") and return dl_bib_extract(dtd)
|
172
|
-
elems = dtd.remove.elements
|
173
|
-
return p_unwrap(dtd) unless elems.size == 1 && %w(ol ul).include?(elems[0].name)
|
174
|
-
ret = []
|
175
|
-
elems[0].xpath("./li").each do |li|
|
176
|
-
ret << p_unwrap(li)
|
177
|
-
end
|
178
|
-
ret
|
179
|
-
end
|
180
|
-
|
181
|
-
def add_to_hash(bib, key, val)
|
182
|
-
Utils::set_nested_value(bib, key.split(/\./), val)
|
183
|
-
end
|
184
|
-
|
185
|
-
# definition list, with at most one level of unordered lists
|
186
|
-
def dl_bib_extract(c, nested = false)
|
187
|
-
dl = c.at("./dl") or return
|
188
|
-
bib = {}
|
189
|
-
key = ""
|
190
|
-
dl.xpath("./dt | ./dd").each do |dtd|
|
191
|
-
dtd.name == "dt" and key = dtd.text.sub(/:+$/, "") or add_to_hash(bib, key, dd_bib_extract(dtd))
|
192
|
-
end
|
193
|
-
c.xpath("./clause").each do |c1|
|
194
|
-
key = c1&.at("./title")&.text&.downcase&.strip
|
195
|
-
next unless %w(contributor relation series).include? key
|
196
|
-
add_to_hash(bib, key, dl_bib_extract(c1, true))
|
197
|
-
end
|
198
|
-
if !nested and c.at("./title")
|
199
|
-
title = c.at("./title").remove.children.to_xml
|
200
|
-
bib["title"] = [bib["title"]] if bib["title"].is_a? Hash
|
201
|
-
bib["title"] = [bib["title"]] if bib["title"].is_a? String
|
202
|
-
bib["title"] = [] unless bib["title"]
|
203
|
-
bib["title"] << title if !title.empty?
|
204
|
-
end
|
205
|
-
bib
|
206
|
-
end
|
207
|
-
|
208
123
|
def fetch_termbase(termbase, id)
|
209
124
|
""
|
210
125
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "set"
|
2
|
+
require "relaton_bib"
|
3
|
+
|
4
|
+
module Asciidoctor
|
5
|
+
module Standoc
|
6
|
+
module Cleanup
|
7
|
+
def ref_dl_cleanup(xmldoc)
|
8
|
+
xmldoc.xpath("//clause[@bibitem = 'true']").each do |c|
|
9
|
+
bib = dl_bib_extract(c) or next
|
10
|
+
validate_ref_dl(bib, c)
|
11
|
+
bibitemxml = RelatonBib::BibliographicItem.new(RelatonBib::HashConverter::hash_to_bib(bib)).to_xml or next
|
12
|
+
bibitem = Nokogiri::XML(bibitemxml)
|
13
|
+
bibitem.root["id"] = c["id"] if c["id"] && !/^_/.match(c["id"])
|
14
|
+
c.replace(bibitem.root)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate_ref_dl(bib, c)
|
19
|
+
id = bib["id"]
|
20
|
+
id ||= c["id"] unless /^_/.match(c["id"]) # do not accept implicit id
|
21
|
+
unless id
|
22
|
+
@log.add("Anchors", c, "The following reference is missing an anchor:\n" + c.to_xml)
|
23
|
+
return
|
24
|
+
end
|
25
|
+
@refids << id
|
26
|
+
bib["title"] or @log.add("Bibliography", c, "Reference #{id} is missing a title")
|
27
|
+
bib["docid"] or @log.add("Bibliography", c, "Reference #{id} is missing a document identifier (docid)")
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_from_p(tag, bib, key)
|
31
|
+
return unless bib[tag]
|
32
|
+
"<#{key}>#{bib[tag].at('p').children}</#{key}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
# if the content is a single paragraph, replace it with its children
|
36
|
+
# single links replaced with uri
|
37
|
+
def p_unwrap(p)
|
38
|
+
elems = p.elements
|
39
|
+
if elems.size == 1 && elems[0].name == "p"
|
40
|
+
link_unwrap(elems[0]).children.to_xml.strip
|
41
|
+
else
|
42
|
+
p.to_xml.strip
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def link_unwrap(p)
|
47
|
+
elems = p.elements
|
48
|
+
if elems.size == 1 && elems[0].name == "link"
|
49
|
+
p.at("./link").replace(elems[0]["target"].strip)
|
50
|
+
end
|
51
|
+
p
|
52
|
+
end
|
53
|
+
|
54
|
+
def dd_bib_extract(dtd)
|
55
|
+
return nil if dtd.children.empty?
|
56
|
+
dtd.at("./dl") and return dl_bib_extract(dtd)
|
57
|
+
elems = dtd.remove.elements
|
58
|
+
return p_unwrap(dtd) unless elems.size == 1 && %w(ol ul).include?(elems[0].name)
|
59
|
+
ret = []
|
60
|
+
elems[0].xpath("./li").each do |li|
|
61
|
+
ret << p_unwrap(li)
|
62
|
+
end
|
63
|
+
ret
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_to_hash(bib, key, val)
|
67
|
+
Metanorma::Utils::set_nested_value(bib, key.split(/\./), val)
|
68
|
+
end
|
69
|
+
|
70
|
+
# definition list, with at most one level of unordered lists
|
71
|
+
def dl_bib_extract(c, nested = false)
|
72
|
+
dl = c.at("./dl") or return
|
73
|
+
bib = {}
|
74
|
+
key = ""
|
75
|
+
dl.xpath("./dt | ./dd").each do |dtd|
|
76
|
+
dtd.name == "dt" and key = dtd.text.sub(/:+$/, "") or add_to_hash(bib, key, dd_bib_extract(dtd))
|
77
|
+
end
|
78
|
+
c.xpath("./clause").each do |c1|
|
79
|
+
key = c1&.at("./title")&.text&.downcase&.strip
|
80
|
+
next unless %w(contributor relation series).include? key
|
81
|
+
add_to_hash(bib, key, dl_bib_extract(c1, true))
|
82
|
+
end
|
83
|
+
if !nested and c.at("./title")
|
84
|
+
title = c.at("./title").remove.children.to_xml
|
85
|
+
bib["title"] = [bib["title"]] if bib["title"].is_a? Hash
|
86
|
+
bib["title"] = [bib["title"]] if bib["title"].is_a? String
|
87
|
+
bib["title"] = [] unless bib["title"]
|
88
|
+
bib["title"] << title if !title.empty?
|
89
|
+
end
|
90
|
+
bib
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -1,6 +1,4 @@
|
|
1
1
|
require "asciidoctor"
|
2
|
-
require "fontist"
|
3
|
-
require "fontist/manifest/install"
|
4
2
|
require "metanorma/util"
|
5
3
|
require "metanorma/standoc/version"
|
6
4
|
require "asciidoctor/standoc/base"
|
@@ -16,7 +14,6 @@ require "asciidoctor/standoc/utils"
|
|
16
14
|
require "asciidoctor/standoc/cleanup"
|
17
15
|
require "asciidoctor/standoc/reqt"
|
18
16
|
require_relative "./macros.rb"
|
19
|
-
require_relative "./log.rb"
|
20
17
|
|
21
18
|
module Asciidoctor
|
22
19
|
module Standoc
|
@@ -73,8 +70,6 @@ module Asciidoctor
|
|
73
70
|
basebackend "html"
|
74
71
|
outfilesuffix ".xml"
|
75
72
|
@libdir = File.dirname(self.class::_file || __FILE__)
|
76
|
-
|
77
|
-
install_fonts(opts)
|
78
73
|
end
|
79
74
|
|
80
75
|
class << self
|
@@ -90,62 +85,6 @@ module Asciidoctor
|
|
90
85
|
File.join(@libdir, "../../isodoc/html", file)
|
91
86
|
end
|
92
87
|
|
93
|
-
def flavor_name
|
94
|
-
self.class.name.split("::")&.[](-2).downcase.to_sym
|
95
|
-
end
|
96
|
-
|
97
|
-
def fonts_manifest
|
98
|
-
flavor = flavor_name
|
99
|
-
registry = Metanorma::Registry.instance
|
100
|
-
processor = registry.find_processor(flavor)
|
101
|
-
|
102
|
-
if processor.nil?
|
103
|
-
Metanorma::Util.log("[fontist] #{flavor} processor not found. " \
|
104
|
-
"Please go to github.com/metanorma/metanorma/issues to report " \
|
105
|
-
"this issue.", :warn)
|
106
|
-
return nil
|
107
|
-
elsif !defined? processor.fonts_manifest
|
108
|
-
Metanorma::Util.log("[fontist] #{flavor} processor don't require " \
|
109
|
-
"specific fonts", :debug)
|
110
|
-
return nil
|
111
|
-
end
|
112
|
-
|
113
|
-
processor.fonts_manifest
|
114
|
-
end
|
115
|
-
|
116
|
-
def install_fonts(options={})
|
117
|
-
if options[:no_install_fonts]
|
118
|
-
Metanorma::Util.log("[fontist] Skip font installation because" \
|
119
|
-
" --no-install-fonts argument passed", :debug)
|
120
|
-
return
|
121
|
-
end
|
122
|
-
|
123
|
-
manifest = fonts_manifest
|
124
|
-
return if manifest.nil?
|
125
|
-
|
126
|
-
begin
|
127
|
-
Fontist::Manifest::Install.from_hash(
|
128
|
-
fonts_manifest,
|
129
|
-
confirmation: options[:agree_to_terms] ? "yes" : "no"
|
130
|
-
)
|
131
|
-
rescue Fontist::Errors::LicensingError
|
132
|
-
if !options[:agree_to_terms]
|
133
|
-
Metanorma::Util.log("[fontist] --agree-to-terms option missing." \
|
134
|
-
" You must accept font licenses to install fonts.", :debug)
|
135
|
-
elsif options[:continue_without_fonts]
|
136
|
-
Metanorma::Util.log("[fontist] Processing will continue without" \
|
137
|
-
" fonts installed", :debug)
|
138
|
-
else
|
139
|
-
Metanorma::Util.log("[fontist] Aborting without proper fonts" \
|
140
|
-
" installed", :fatal)
|
141
|
-
end
|
142
|
-
rescue Fontist::Errors::NonSupportedFontError
|
143
|
-
Metanorma::Util.log("[fontist] '#{font}' font is not supported. " \
|
144
|
-
"Please go to github.com/metanorma/metanorma-#{flavor_name}/issues" \
|
145
|
-
" to report this issue.", :info)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
88
|
alias_method :embedded, :content
|
150
89
|
alias_method :verse, :quote
|
151
90
|
alias_method :audio, :skip
|