metanorma-standoc 1.7.3 → 1.8.5
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 +11 -41
- data/.rubocop.yml +1 -1
- data/lib/asciidoctor/standoc/base.rb +34 -45
- data/lib/asciidoctor/standoc/basicdoc.rng +5 -3
- data/lib/asciidoctor/standoc/blocks.rb +20 -11
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -2
- data/lib/asciidoctor/standoc/cleanup.rb +29 -77
- data/lib/asciidoctor/standoc/cleanup_block.rb +39 -27
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +56 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +26 -29
- data/lib/asciidoctor/standoc/cleanup_maths.rb +123 -0
- data/lib/asciidoctor/standoc/cleanup_ref.rb +4 -98
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +94 -0
- data/lib/asciidoctor/standoc/cleanup_section.rb +5 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -2
- data/lib/asciidoctor/standoc/converter.rb +0 -1
- data/lib/asciidoctor/standoc/front.rb +2 -2
- data/lib/asciidoctor/standoc/inline.rb +8 -16
- data/lib/asciidoctor/standoc/isodoc.rng +108 -2
- data/lib/asciidoctor/standoc/lists.rb +2 -2
- data/lib/asciidoctor/standoc/macros_plantuml.rb +1 -1
- data/lib/asciidoctor/standoc/ref_sect.rb +2 -2
- data/lib/asciidoctor/standoc/reqt.rb +6 -1
- data/lib/asciidoctor/standoc/section.rb +12 -80
- data/lib/asciidoctor/standoc/table.rb +1 -1
- data/lib/asciidoctor/standoc/terms.rb +125 -0
- data/lib/asciidoctor/standoc/utils.rb +2 -120
- data/lib/asciidoctor/standoc/validate.rb +16 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/{asciidoctor-standoc → asciidoctor}/base_spec.rb +30 -1
- data/spec/{asciidoctor-standoc → asciidoctor}/blocks_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/cleanup_sections_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/cleanup_spec.rb +408 -6
- data/spec/{asciidoctor-standoc → asciidoctor}/datamodel/attributes_table_preprocessor_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/datamodel/diagram_preprocessor_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/inline_spec.rb +2 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/isobib_cache_spec.rb +4 -4
- data/spec/{asciidoctor-standoc → asciidoctor}/lists_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_json2text_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_lutaml_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_plantuml_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/macros_yaml2text_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/refs_dl_spec.rb +13 -1
- data/spec/{asciidoctor-standoc → asciidoctor}/refs_spec.rb +175 -153
- data/spec/{asciidoctor-standoc → asciidoctor}/section_spec.rb +22 -3
- data/spec/{asciidoctor-standoc → asciidoctor}/table_spec.rb +0 -0
- data/spec/{asciidoctor-standoc → asciidoctor}/validate_spec.rb +20 -0
- data/spec/fixtures/action_schemaexpg1.svg +122 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +47 -47
- data/spec/vcr_cassettes/isobib_get_123.yml +14 -14
- data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -27
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +36 -36
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_124.yml +13 -13
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +94 -30
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +45 -45
- metadata +49 -46
- data/lib/asciidoctor/standoc/log.rb +0 -59
@@ -54,7 +54,7 @@ module Asciidoctor
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def ol_attrs(node)
|
57
|
-
attr_code(keep_attrs(node).merge(id: Utils::anchor_or_uuid(node),
|
57
|
+
attr_code(keep_attrs(node).merge(id: Metanorma::Utils::anchor_or_uuid(node),
|
58
58
|
type: olist_style(node.style)))
|
59
59
|
end
|
60
60
|
|
@@ -88,7 +88,7 @@ module Asciidoctor
|
|
88
88
|
|
89
89
|
def dl_attrs(node)
|
90
90
|
attr_code(keep_attrs(node).
|
91
|
-
merge(id: Utils::anchor_or_uuid(node),
|
91
|
+
merge(id: Metanorma::Utils::anchor_or_uuid(node),
|
92
92
|
key: node.option?("key") ? "true" : nil))
|
93
93
|
end
|
94
94
|
|
@@ -30,7 +30,7 @@ module Asciidoctor
|
|
30
30
|
# plantuml process may finish earlier then dot, as result png file
|
31
31
|
# maybe not created yet after plantuml finish
|
32
32
|
def self.generate_file parent, reader
|
33
|
-
localdir = Utils::localdir(parent.document)
|
33
|
+
localdir = Metanorma::Utils::localdir(parent.document)
|
34
34
|
imagesdir = parent.document.attr('imagesdir')
|
35
35
|
umlfile, outfile = save_plantuml parent, reader, localdir
|
36
36
|
run(umlfile, outfile) or raise "No image output from PlantUML (#{umlfile}, #{outfile})!"
|
@@ -96,9 +96,9 @@ module Asciidoctor
|
|
96
96
|
xstr = x.to_xml(lang: opts[:lang])
|
97
97
|
xml = Nokogiri::XML(xstr)
|
98
98
|
emend_biblio(xml, code, opts[:title], opts[:usrlbl])
|
99
|
-
xml.xpath("//date").each { |d| Utils::endash_date(d) }
|
99
|
+
xml.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
|
100
100
|
xml.traverse do |n|
|
101
|
-
n.text? and n.replace(Utils::smartformat(n.text))
|
101
|
+
n.text? and n.replace(Metanorma::Utils::smartformat(n.text))
|
102
102
|
end
|
103
103
|
xml.to_xml.sub(/<\?[^>]+>/, "")
|
104
104
|
end
|
@@ -6,6 +6,11 @@ require "base64"
|
|
6
6
|
module Asciidoctor
|
7
7
|
module Standoc
|
8
8
|
module Blocks
|
9
|
+
def reqt_subpart(x)
|
10
|
+
%w(specification measurement-target verification import label
|
11
|
+
subject inherit classification title).include? x
|
12
|
+
end
|
13
|
+
|
9
14
|
def reqt_subpart_attrs(node)
|
10
15
|
attr_code(keep_attrs(node).merge(exclude: node.option?("exclude"),
|
11
16
|
type: node.attr("type")))
|
@@ -41,7 +46,7 @@ module Asciidoctor
|
|
41
46
|
|
42
47
|
def reqt_attrs(node)
|
43
48
|
attr_code(keep_attrs(node).merge(id_unnum_attrs(node)).merge(
|
44
|
-
id: Utils::anchor_or_uuid(node),
|
49
|
+
id: Metanorma::Utils::anchor_or_uuid(node),
|
45
50
|
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
46
51
|
number: node.attr("number"),
|
47
52
|
subsequence: node.attr("subsequence"),
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require "htmlentities"
|
2
1
|
require "uri"
|
3
2
|
require_relative "ref_sect"
|
3
|
+
require_relative "terms"
|
4
4
|
|
5
5
|
module Asciidoctor
|
6
6
|
module Standoc
|
@@ -9,10 +9,6 @@ module Asciidoctor
|
|
9
9
|
@term_def = false
|
10
10
|
@norm_ref = false
|
11
11
|
|
12
|
-
def in_terms?
|
13
|
-
@term_def
|
14
|
-
end
|
15
|
-
|
16
12
|
def sectiontype1(node)
|
17
13
|
node&.attr("heading")&.downcase || node.title.gsub(/<[^>]+>/, "").downcase
|
18
14
|
end
|
@@ -45,10 +41,11 @@ module Asciidoctor
|
|
45
41
|
end
|
46
42
|
|
47
43
|
def section_attributes(node)
|
48
|
-
ret = { id: Utils::anchor_or_uuid(node),
|
44
|
+
ret = { id: Metanorma::Utils::anchor_or_uuid(node),
|
49
45
|
language: node.attributes["language"],
|
50
46
|
script: node.attributes["script"],
|
51
47
|
number: node.attributes["number"],
|
48
|
+
type: node.attributes["type"],
|
52
49
|
annex: ( ((node.attr("style") == "appendix" || node.role == "appendix") &&
|
53
50
|
node.level == 1) ? true : nil),
|
54
51
|
preface: (
|
@@ -91,6 +88,8 @@ module Asciidoctor
|
|
91
88
|
bibliography_parse(a, xml, node)
|
92
89
|
elsif node.attr("style") == "abstract"
|
93
90
|
abstract_parse(a, xml, node)
|
91
|
+
elsif node.attr("style") == "index"
|
92
|
+
indexsect_parse(a, xml, node)
|
94
93
|
elsif node.attr("style") == "appendix" && node.level == 1
|
95
94
|
annex_parse(a, xml, node)
|
96
95
|
else
|
@@ -117,6 +116,13 @@ module Asciidoctor
|
|
117
116
|
end.join("\n")
|
118
117
|
end
|
119
118
|
|
119
|
+
def indexsect_parse(attrs, xml, node)
|
120
|
+
xml.indexsect **attr_code(attrs) do |xml_section|
|
121
|
+
xml_section.title { |name| name << node.title }
|
122
|
+
xml_section << node.content
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
120
126
|
def abstract_parse(attrs, xml, node)
|
121
127
|
xml.abstract **attr_code(attrs) do |xml_section|
|
122
128
|
xml_section << node.content
|
@@ -147,80 +153,6 @@ module Asciidoctor
|
|
147
153
|
end
|
148
154
|
end
|
149
155
|
|
150
|
-
def nonterm_symbols_parse(attrs, xml, node)
|
151
|
-
defs = @definitions
|
152
|
-
@definitions = false
|
153
|
-
clause_parse(attrs, xml, node)
|
154
|
-
@definitions = defs
|
155
|
-
end
|
156
|
-
|
157
|
-
def symbols_attrs(node, a)
|
158
|
-
case sectiontype1(node)
|
159
|
-
when "symbols" then a.merge(type: "symbols")
|
160
|
-
when "abbreviated terms", "abbreviations" then a.merge(type: "abbreviated_terms")
|
161
|
-
else
|
162
|
-
a
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def symbols_parse(attr, xml, node)
|
167
|
-
node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
|
168
|
-
xml.definitions **attr_code(attr) do |xml_section|
|
169
|
-
xml_section.title { |t| t << node.title }
|
170
|
-
defs = @definitions
|
171
|
-
termdefs = @term_def
|
172
|
-
@definitions = true
|
173
|
-
@term_def = false
|
174
|
-
xml_section << node.content
|
175
|
-
@definitions = defs
|
176
|
-
@term_def = termdefs
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def nonterm_term_def_subclause_parse(attrs, xml, node)
|
181
|
-
defs = @term_def
|
182
|
-
@term_def = false
|
183
|
-
clause_parse(attrs, xml, node)
|
184
|
-
@term_def = defs
|
185
|
-
end
|
186
|
-
|
187
|
-
def terms_boilerplate_parse(attrs, xml, node)
|
188
|
-
defs = @term_def
|
189
|
-
@term_def = false
|
190
|
-
clause_parse(attrs.merge(type: "boilerplate"), xml, node)
|
191
|
-
@term_def = defs
|
192
|
-
end
|
193
|
-
|
194
|
-
# subclause contains subclauses
|
195
|
-
def term_def_subclause_parse(attrs, xml, node)
|
196
|
-
node.role == "nonterm" and return nonterm_term_def_subclause_parse(attrs, xml, node)
|
197
|
-
node.role == "boilerplate" and return terms_boilerplate_parse(attrs, xml, node)
|
198
|
-
st = sectiontype(node, false)
|
199
|
-
return symbols_parse(attrs, xml, node) if @definitions
|
200
|
-
sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
|
201
|
-
sub.empty? || (return term_def_parse(attrs, xml, node, false))
|
202
|
-
st == "symbols and abbreviated terms" and (return symbols_parse(attrs, xml, node))
|
203
|
-
st == "terms and definitions" and return clause_parse(attrs, xml, node)
|
204
|
-
term_def_subclause_parse1(attrs, xml, node)
|
205
|
-
end
|
206
|
-
|
207
|
-
def term_def_subclause_parse1(attrs, xml, node)
|
208
|
-
xml.term **attr_code(attrs) do |xml_section|
|
209
|
-
xml_section.preferred { |name| name << node.title }
|
210
|
-
xml_section << node.content
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def term_def_parse(attrs, xml, node, toplevel)
|
215
|
-
xml.terms **attr_code(attrs) do |section|
|
216
|
-
section.title { |t| t << node.title }
|
217
|
-
(s = node.attr("source")) && s.split(/,/).each do |s1|
|
218
|
-
section.termdocsource(nil, **attr_code(bibitemid: s1))
|
219
|
-
end
|
220
|
-
section << node.content
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
156
|
def introduction_parse(attrs, xml, node)
|
225
157
|
xml.introduction **attr_code(attrs) do |xml_section|
|
226
158
|
xml_section.title { |t| t << @i18n.introduction }
|
@@ -2,7 +2,7 @@ module Asciidoctor
|
|
2
2
|
module Standoc
|
3
3
|
module Table
|
4
4
|
def table_attrs(node)
|
5
|
-
keep_attrs(node).merge( id: Utils::anchor_or_uuid(node),
|
5
|
+
keep_attrs(node).merge( id: Metanorma::Utils::anchor_or_uuid(node),
|
6
6
|
headerrows: node.attr("headerrows"),
|
7
7
|
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
8
8
|
number: node.attr("number"),
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
3
|
+
module Section
|
4
|
+
def in_terms?
|
5
|
+
@term_def
|
6
|
+
end
|
7
|
+
|
8
|
+
def nonterm_symbols_parse(attrs, xml, node)
|
9
|
+
defs = @definitions
|
10
|
+
@definitions = false
|
11
|
+
clause_parse(attrs, xml, node)
|
12
|
+
@definitions = defs
|
13
|
+
end
|
14
|
+
|
15
|
+
def symbols_attrs(node, a)
|
16
|
+
case sectiontype1(node)
|
17
|
+
when "symbols" then a.merge(type: "symbols")
|
18
|
+
when "abbreviated terms", "abbreviations" then a.merge(type: "abbreviated_terms")
|
19
|
+
else
|
20
|
+
a
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def symbols_parse(attr, xml, node)
|
25
|
+
node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
|
26
|
+
xml.definitions **attr_code(attr) do |xml_section|
|
27
|
+
xml_section.title { |t| t << node.title }
|
28
|
+
defs = @definitions
|
29
|
+
termdefs = @term_def
|
30
|
+
@definitions = true
|
31
|
+
@term_def = false
|
32
|
+
xml_section << node.content
|
33
|
+
@definitions = defs
|
34
|
+
@term_def = termdefs
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def nonterm_term_def_subclause_parse(attrs, xml, node)
|
39
|
+
defs = @term_def
|
40
|
+
@term_def = false
|
41
|
+
clause_parse(attrs, xml, node)
|
42
|
+
@term_def = defs
|
43
|
+
end
|
44
|
+
|
45
|
+
def terms_boilerplate_parse(attrs, xml, node)
|
46
|
+
defs = @term_def
|
47
|
+
@term_def = false
|
48
|
+
clause_parse(attrs.merge(type: "boilerplate"), xml, node)
|
49
|
+
@term_def = defs
|
50
|
+
end
|
51
|
+
|
52
|
+
# subclause contains subclauses
|
53
|
+
def term_def_subclause_parse(attrs, xml, node)
|
54
|
+
node.role == "nonterm" and return nonterm_term_def_subclause_parse(attrs, xml, node)
|
55
|
+
node.role == "boilerplate" and return terms_boilerplate_parse(attrs, xml, node)
|
56
|
+
st = sectiontype(node, false)
|
57
|
+
return symbols_parse(attrs, xml, node) if @definitions
|
58
|
+
sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
|
59
|
+
sub.empty? || (return term_def_parse(attrs, xml, node, false))
|
60
|
+
st == "symbols and abbreviated terms" and (return symbols_parse(attrs, xml, node))
|
61
|
+
st == "terms and definitions" and return clause_parse(attrs, xml, node)
|
62
|
+
term_def_subclause_parse1(attrs, xml, node)
|
63
|
+
end
|
64
|
+
|
65
|
+
def term_def_subclause_parse1(attrs, xml, node)
|
66
|
+
xml.term **attr_code(attrs) do |xml_section|
|
67
|
+
xml_section.preferred { |name| name << node.title }
|
68
|
+
xml_section << node.content
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def term_def_parse(attrs, xml, node, toplevel)
|
73
|
+
xml.terms **attr_code(attrs) do |section|
|
74
|
+
section.title { |t| t << node.title }
|
75
|
+
(s = node.attr("source")) && s.split(/,/).each do |s1|
|
76
|
+
section.termdocsource(nil, **attr_code(bibitemid: s1))
|
77
|
+
end
|
78
|
+
section << node.content
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def term_source_attrs(seen_xref)
|
83
|
+
{ bibitemid: seen_xref.children[0]["target"],
|
84
|
+
format: seen_xref.children[0]["format"], type: "inline" }
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_term_source(xml_t, seen_xref, m)
|
88
|
+
if seen_xref.children[0].name == "concept"
|
89
|
+
xml_t.origin { |o| o << seen_xref.children[0].to_xml }
|
90
|
+
else
|
91
|
+
xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attrs(seen_xref))
|
92
|
+
end
|
93
|
+
m[:text] && xml_t.modification do |mod|
|
94
|
+
mod.p { |p| p << m[:text].sub(/^\s+/, "") }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
TERM_REFERENCE_RE_STR = <<~REGEXP.freeze
|
99
|
+
^(?<xref><(xref|concept)[^>]+>([^<]*</(xref|concept)>)?)
|
100
|
+
(,\s(?<text>.*))?
|
101
|
+
$
|
102
|
+
REGEXP
|
103
|
+
TERM_REFERENCE_RE =
|
104
|
+
Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"),
|
105
|
+
Regexp::IGNORECASE | Regexp::MULTILINE)
|
106
|
+
|
107
|
+
def extract_termsource_refs(text, node)
|
108
|
+
matched = TERM_REFERENCE_RE.match text
|
109
|
+
matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}")
|
110
|
+
matched
|
111
|
+
end
|
112
|
+
|
113
|
+
def termsource(node)
|
114
|
+
matched = extract_termsource_refs(node.content, node) || return
|
115
|
+
noko do |xml|
|
116
|
+
attrs = { status: matched[:text] ? "modified" : "identical" }
|
117
|
+
xml.termsource **attrs do |xml_t|
|
118
|
+
seen_xref = Nokogiri::XML.fragment(matched[:xref])
|
119
|
+
add_term_source(xml_t, seen_xref, matched)
|
120
|
+
end
|
121
|
+
end.join("\n")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -5,105 +5,10 @@ require "json"
|
|
5
5
|
require "pathname"
|
6
6
|
require "open-uri"
|
7
7
|
require "uuidtools"
|
8
|
-
require "sterile"
|
9
|
-
require "mimemagic"
|
10
8
|
|
11
9
|
module Asciidoctor
|
12
10
|
module Standoc
|
13
11
|
module Utils
|
14
|
-
class << self
|
15
|
-
def anchor_or_uuid(node = nil)
|
16
|
-
uuid = UUIDTools::UUID.random_create
|
17
|
-
node.nil? || node.id.nil? || node.id.empty? ? "_" + uuid : node.id
|
18
|
-
end
|
19
|
-
|
20
|
-
def asciidoc_sub(x)
|
21
|
-
return nil if x.nil?
|
22
|
-
return "" if x.empty?
|
23
|
-
d = Asciidoctor::Document.new(x.lines.entries, { header_footer: false,
|
24
|
-
backend: :standoc })
|
25
|
-
b = d.parse.blocks.first
|
26
|
-
b.apply_subs(b.source)
|
27
|
-
end
|
28
|
-
|
29
|
-
def localdir(node)
|
30
|
-
docfile = node.attr("docfile")
|
31
|
-
docfile.nil? ? './' : Pathname.new(docfile).parent.to_s + '/'
|
32
|
-
end
|
33
|
-
|
34
|
-
# TODO needs internationalisation
|
35
|
-
def smartformat(n)
|
36
|
-
n.gsub(/ --? /, " — ").
|
37
|
-
gsub(/\'(\d\d)(?=[^\u2019\'\s<]+[’\'][\p{P}\p{Z}])([\p{P}\p{Z}])/, "\u2018\\1\\2").
|
38
|
-
gsub(/--/, "—").smart_format.gsub(/</, "<").gsub(/>/, ">")
|
39
|
-
end
|
40
|
-
|
41
|
-
def endash_date(elem)
|
42
|
-
elem.traverse do |n|
|
43
|
-
n.text? and n.replace(n.text.gsub(/\s+--?\s+/, "–").gsub(/--/, "–"))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Set hash value using keys path
|
48
|
-
# mod from https://stackoverflow.com/a/42425884
|
49
|
-
def set_nested_value(hash, keys, new_val)
|
50
|
-
key = keys[0]
|
51
|
-
if keys.length == 1
|
52
|
-
hash[key] = hash[key].is_a?(Array) ? (hash[key] << new_val) :
|
53
|
-
hash[key].nil? ? new_val : [hash[key], new_val]
|
54
|
-
return hash
|
55
|
-
end
|
56
|
-
if hash[key].is_a?(Array)
|
57
|
-
hash[key][-1] = {} if hash[key][-1].nil?
|
58
|
-
set_nested_value(hash[key][-1], keys[1..-1], new_val)
|
59
|
-
elsif hash[key].nil? || hash[key].empty?
|
60
|
-
hash[key] = {}
|
61
|
-
set_nested_value(hash[key], keys[1..-1], new_val)
|
62
|
-
elsif hash[key].is_a?(Hash) && !hash[key][keys[1]]
|
63
|
-
set_nested_value(hash[key], keys[1..-1], new_val)
|
64
|
-
elsif !hash[key][keys[1]]
|
65
|
-
hash[key] = [hash[key], {}]
|
66
|
-
set_nested_value(hash[key][-1], keys[1..-1], new_val)
|
67
|
-
else
|
68
|
-
set_nested_value(hash[key], keys[1..-1], new_val)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def flatten_rawtext_lines(node, result)
|
73
|
-
node.lines.each do |x|
|
74
|
-
if node.respond_to?(:context) && (node.context == :literal ||
|
75
|
-
node.context == :listing)
|
76
|
-
result << x.gsub(/</, "<").gsub(/>/, ">")
|
77
|
-
else
|
78
|
-
# strip not only HTML <tag>, and Asciidoc xrefs <<xref>>
|
79
|
-
result << x.gsub(/<[^>]*>+/, "")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
result
|
83
|
-
end
|
84
|
-
|
85
|
-
# if node contains blocks, flatten them into a single line;
|
86
|
-
# and extract only raw text
|
87
|
-
def flatten_rawtext(node)
|
88
|
-
result = []
|
89
|
-
if node.respond_to?(:blocks) && node.blocks?
|
90
|
-
node.blocks.each { |b| result << flatten_rawtext(b) }
|
91
|
-
elsif node.respond_to?(:lines)
|
92
|
-
result = flatten_rawtext_lines(node, result)
|
93
|
-
elsif node.respond_to?(:text)
|
94
|
-
result << node.text.gsub(/<[^>]*>+/, "")
|
95
|
-
else
|
96
|
-
result << node.content.gsub(/<[^>]*>+/, "")
|
97
|
-
end
|
98
|
-
result.reject(&:empty?)
|
99
|
-
end
|
100
|
-
|
101
|
-
def reqt_subpart(x)
|
102
|
-
%w(specification measurement-target verification import label
|
103
|
-
subject inherit classification title).include? x
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
12
|
def convert(node, transform = nil, opts = {})
|
108
13
|
transform ||= node.node_name
|
109
14
|
opts.empty? ? (send transform, node) : (send transform, node, opts)
|
@@ -151,40 +56,17 @@ module Asciidoctor
|
|
151
56
|
end
|
152
57
|
end
|
153
58
|
|
154
|
-
def datauri2mime(uri)
|
155
|
-
%r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri
|
156
|
-
type = nil
|
157
|
-
imgtype = "png" unless /^[a-z0-9]+$/.match imgtype
|
158
|
-
Tempfile.open(["imageuri", ".#{imgtype}"]) do |file|
|
159
|
-
type = datauri2mime1(file, imgdata)
|
160
|
-
end
|
161
|
-
[type]
|
162
|
-
end
|
163
|
-
|
164
|
-
def datauri2mime1(file, imgdata)
|
165
|
-
type = nil
|
166
|
-
begin
|
167
|
-
file.binmode
|
168
|
-
file.write(Base64.strict_decode64(imgdata))
|
169
|
-
file.rewind
|
170
|
-
type = MimeMagic.by_magic(file)
|
171
|
-
ensure
|
172
|
-
file.close!
|
173
|
-
end
|
174
|
-
type
|
175
|
-
end
|
176
|
-
|
177
59
|
SUBCLAUSE_XPATH = "//clause[not(parent::sections)]"\
|
178
60
|
"[not(ancestor::boilerplate)]".freeze
|
179
61
|
|
180
|
-
|
62
|
+
def isodoc(lang, script, i18nyaml = nil)
|
181
63
|
conv = html_converter(EmptyAttr.new)
|
182
64
|
i18n = conv.i18n_init(lang, script, i18nyaml)
|
183
65
|
conv.metadata_init(lang, script, i18n)
|
184
66
|
conv
|
185
67
|
end
|
186
68
|
|
187
|
-
|
69
|
+
class EmptyAttr
|
188
70
|
def attr(_x)
|
189
71
|
nil
|
190
72
|
end
|