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
@@ -93,7 +93,7 @@ module Asciidoctor
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def metadata_script(node, xml)
|
96
|
-
xml.script (node.attr("script") || "
|
96
|
+
xml.script (node.attr("script") || default_script(node.attr("language")))
|
97
97
|
end
|
98
98
|
|
99
99
|
def relaton_relations
|
@@ -186,7 +186,7 @@ module Asciidoctor
|
|
186
186
|
["en"].each do |lang|
|
187
187
|
at = { language: lang, format: "text/plain" }
|
188
188
|
xml.title **attr_code(at) do |t|
|
189
|
-
t << (Utils::asciidoc_sub(node.attr("title") ||
|
189
|
+
t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
|
190
190
|
node.attr("title-en")) || node.title)
|
191
191
|
end
|
192
192
|
end
|
@@ -165,6 +165,7 @@ module Asciidoctor
|
|
165
165
|
when "domain" then xml.domain { |a| a << node.text }
|
166
166
|
|
167
167
|
when "strike" then xml.strike { |s| s << node.text }
|
168
|
+
when "underline" then xml.underline { |s| s << node.text }
|
168
169
|
when "smallcap" then xml.smallcap { |s| s << node.text }
|
169
170
|
when "keyword" then xml.keyword { |s| s << node.text }
|
170
171
|
else
|
@@ -193,7 +194,7 @@ module Asciidoctor
|
|
193
194
|
type = types.first.to_s
|
194
195
|
uri = uri.sub(%r{^data:image/\*;}, "data:#{type};")
|
195
196
|
attr_code(src: uri, #@datauriimage ? datauri(uri) : uri,
|
196
|
-
id: Utils::anchor_or_uuid,
|
197
|
+
id: Metanorma::Utils::anchor_or_uuid,
|
197
198
|
mimetype: type,
|
198
199
|
height: node.attr("height") || "auto",
|
199
200
|
width: node.attr("width") || "auto" ,
|
@@ -253,6 +253,9 @@
|
|
253
253
|
<data type="boolean"/>
|
254
254
|
</attribute>
|
255
255
|
</optional>
|
256
|
+
<optional>
|
257
|
+
<attribute name="width"/>
|
258
|
+
</optional>
|
256
259
|
<optional>
|
257
260
|
<ref name="colgroup"/>
|
258
261
|
</optional>
|
@@ -786,6 +789,9 @@
|
|
786
789
|
<attribute name="width"/>
|
787
790
|
</element>
|
788
791
|
</define>
|
792
|
+
<define name="BibItemType" combine="choice">
|
793
|
+
<value>internal</value>
|
794
|
+
</define>
|
789
795
|
<define name="TextElement" combine="choice">
|
790
796
|
<ref name="concept"/>
|
791
797
|
</define>
|
@@ -836,6 +842,9 @@
|
|
836
842
|
<data type="boolean"/>
|
837
843
|
</attribute>
|
838
844
|
</optional>
|
845
|
+
<optional>
|
846
|
+
<attribute name="number"/>
|
847
|
+
</optional>
|
839
848
|
<optional>
|
840
849
|
<attribute name="obligation">
|
841
850
|
<choice>
|
@@ -891,9 +900,11 @@
|
|
891
900
|
<element name="code">
|
892
901
|
<text/>
|
893
902
|
</element>
|
894
|
-
<
|
895
|
-
<text
|
896
|
-
|
903
|
+
<optional>
|
904
|
+
<element name="text">
|
905
|
+
<text/>
|
906
|
+
</element>
|
907
|
+
</optional>
|
897
908
|
</element>
|
898
909
|
</define>
|
899
910
|
<define name="standard-document">
|
@@ -1063,6 +1074,9 @@
|
|
1063
1074
|
</choice>
|
1064
1075
|
</attribute>
|
1065
1076
|
</optional>
|
1077
|
+
<optional>
|
1078
|
+
<attribute name="number"/>
|
1079
|
+
</optional>
|
1066
1080
|
<optional>
|
1067
1081
|
<attribute name="type"/>
|
1068
1082
|
</optional>
|
@@ -1116,6 +1130,9 @@
|
|
1116
1130
|
<optional>
|
1117
1131
|
<attribute name="type"/>
|
1118
1132
|
</optional>
|
1133
|
+
<optional>
|
1134
|
+
<attribute name="number"/>
|
1135
|
+
</optional>
|
1119
1136
|
<optional>
|
1120
1137
|
<ref name="section-title"/>
|
1121
1138
|
</optional>
|
@@ -1218,6 +1235,9 @@
|
|
1218
1235
|
<optional>
|
1219
1236
|
<attribute name="type"/>
|
1220
1237
|
</optional>
|
1238
|
+
<optional>
|
1239
|
+
<attribute name="number"/>
|
1240
|
+
</optional>
|
1221
1241
|
<optional>
|
1222
1242
|
<attribute name="obligation">
|
1223
1243
|
<choice>
|
@@ -1546,6 +1566,7 @@
|
|
1546
1566
|
<value>add</value>
|
1547
1567
|
<value>modify</value>
|
1548
1568
|
<value>delete</value>
|
1569
|
+
<value>replace</value>
|
1549
1570
|
</choice>
|
1550
1571
|
</attribute>
|
1551
1572
|
<optional>
|
@@ -1576,6 +1597,11 @@
|
|
1576
1597
|
</optional>
|
1577
1598
|
<optional>
|
1578
1599
|
<element name="newcontent">
|
1600
|
+
<optional>
|
1601
|
+
<attribute name="id">
|
1602
|
+
<data type="ID"/>
|
1603
|
+
</attribute>
|
1604
|
+
</optional>
|
1579
1605
|
<zeroOrMore>
|
1580
1606
|
<ref name="BasicBlock"/>
|
1581
1607
|
</zeroOrMore>
|
@@ -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,9 +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"],
|
47
|
+
number: node.attributes["number"],
|
48
|
+
type: node.attributes["type"],
|
51
49
|
annex: ( ((node.attr("style") == "appendix" || node.role == "appendix") &&
|
52
50
|
node.level == 1) ? true : nil),
|
53
51
|
preface: (
|
@@ -146,80 +144,6 @@ module Asciidoctor
|
|
146
144
|
end
|
147
145
|
end
|
148
146
|
|
149
|
-
def nonterm_symbols_parse(attrs, xml, node)
|
150
|
-
defs = @definitions
|
151
|
-
@definitions = false
|
152
|
-
clause_parse(attrs, xml, node)
|
153
|
-
@definitions = defs
|
154
|
-
end
|
155
|
-
|
156
|
-
def symbols_attrs(node, a)
|
157
|
-
case sectiontype1(node)
|
158
|
-
when "symbols" then a.merge(type: "symbols")
|
159
|
-
when "abbreviated terms", "abbreviations" then a.merge(type: "abbreviated_terms")
|
160
|
-
else
|
161
|
-
a
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def symbols_parse(attr, xml, node)
|
166
|
-
node.role == "nonterm" and return nonterm_symbols_parse(attr, xml, node)
|
167
|
-
xml.definitions **attr_code(attr) do |xml_section|
|
168
|
-
xml_section.title { |t| t << node.title }
|
169
|
-
defs = @definitions
|
170
|
-
termdefs = @term_def
|
171
|
-
@definitions = true
|
172
|
-
@term_def = false
|
173
|
-
xml_section << node.content
|
174
|
-
@definitions = defs
|
175
|
-
@term_def = termdefs
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
def nonterm_term_def_subclause_parse(attrs, xml, node)
|
180
|
-
defs = @term_def
|
181
|
-
@term_def = false
|
182
|
-
clause_parse(attrs, xml, node)
|
183
|
-
@term_def = defs
|
184
|
-
end
|
185
|
-
|
186
|
-
def terms_boilerplate_parse(attrs, xml, node)
|
187
|
-
defs = @term_def
|
188
|
-
@term_def = false
|
189
|
-
clause_parse(attrs.merge(type: "boilerplate"), xml, node)
|
190
|
-
@term_def = defs
|
191
|
-
end
|
192
|
-
|
193
|
-
# subclause contains subclauses
|
194
|
-
def term_def_subclause_parse(attrs, xml, node)
|
195
|
-
node.role == "nonterm" and return nonterm_term_def_subclause_parse(attrs, xml, node)
|
196
|
-
node.role == "boilerplate" and return terms_boilerplate_parse(attrs, xml, node)
|
197
|
-
st = sectiontype(node, false)
|
198
|
-
return symbols_parse(attrs, xml, node) if @definitions
|
199
|
-
sub = node.find_by(context: :section) { |s| s.level == node.level + 1 }
|
200
|
-
sub.empty? || (return term_def_parse(attrs, xml, node, false))
|
201
|
-
st == "symbols and abbreviated terms" and (return symbols_parse(attrs, xml, node))
|
202
|
-
st == "terms and definitions" and return clause_parse(attrs, xml, node)
|
203
|
-
term_def_subclause_parse1(attrs, xml, node)
|
204
|
-
end
|
205
|
-
|
206
|
-
def term_def_subclause_parse1(attrs, xml, node)
|
207
|
-
xml.term **attr_code(attrs) do |xml_section|
|
208
|
-
xml_section.preferred { |name| name << node.title }
|
209
|
-
xml_section << node.content
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
def term_def_parse(attrs, xml, node, toplevel)
|
214
|
-
xml.terms **attr_code(attrs) do |section|
|
215
|
-
section.title { |t| t << node.title }
|
216
|
-
(s = node.attr("source")) && s.split(/,/).each do |s1|
|
217
|
-
section.termdocsource(nil, **attr_code(bibitemid: s1))
|
218
|
-
end
|
219
|
-
section << node.content
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
147
|
def introduction_parse(attrs, xml, node)
|
224
148
|
xml.introduction **attr_code(attrs) do |xml_section|
|
225
149
|
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,11 @@ require "json"
|
|
5
5
|
require "pathname"
|
6
6
|
require "open-uri"
|
7
7
|
require "uuidtools"
|
8
|
-
require "sterile"
|
9
8
|
require "mimemagic"
|
10
9
|
|
11
10
|
module Asciidoctor
|
12
11
|
module Standoc
|
13
12
|
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
13
|
def convert(node, transform = nil, opts = {})
|
108
14
|
transform ||= node.node_name
|
109
15
|
opts.empty? ? (send transform, node) : (send transform, node, opts)
|
@@ -177,14 +83,14 @@ module Asciidoctor
|
|
177
83
|
SUBCLAUSE_XPATH = "//clause[not(parent::sections)]"\
|
178
84
|
"[not(ancestor::boilerplate)]".freeze
|
179
85
|
|
180
|
-
|
86
|
+
def isodoc(lang, script, i18nyaml = nil)
|
181
87
|
conv = html_converter(EmptyAttr.new)
|
182
88
|
i18n = conv.i18n_init(lang, script, i18nyaml)
|
183
89
|
conv.metadata_init(lang, script, i18n)
|
184
90
|
conv
|
185
91
|
end
|
186
92
|
|
187
|
-
|
93
|
+
class EmptyAttr
|
188
94
|
def attr(_x)
|
189
95
|
nil
|
190
96
|
end
|