metanorma-standoc 1.3.6 → 1.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ubuntu.yml +0 -1
- data/Gemfile.lock +22 -18
- data/README.adoc +4 -4
- data/lib/asciidoctor/standoc/base.rb +1 -0
- data/lib/asciidoctor/standoc/basicdoc.rng +6 -8
- data/lib/asciidoctor/standoc/blocks.rb +15 -0
- data/lib/asciidoctor/standoc/cleanup.rb +9 -16
- data/lib/asciidoctor/standoc/inline.rb +4 -3
- data/lib/asciidoctor/standoc/macros.rb +20 -2
- data/lib/asciidoctor/standoc/ref.rb +79 -67
- data/lib/asciidoctor/standoc/section.rb +1 -1
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- data/spec/asciidoctor-standoc/base_spec.rb +15 -3
- data/spec/asciidoctor-standoc/blocks_spec.rb +37 -41
- data/spec/asciidoctor-standoc/cleanup_spec.rb +62 -55
- data/spec/asciidoctor-standoc/inline_spec.rb +10 -10
- data/spec/asciidoctor-standoc/lists_spec.rb +3 -3
- data/spec/asciidoctor-standoc/macros_spec.rb +30 -7
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +3 -3
- data/spec/asciidoctor-standoc/refs_spec.rb +43 -13
- data/spec/asciidoctor-standoc/section_spec.rb +81 -63
- data/spec/asciidoctor-standoc/table_spec.rb +4 -4
- data/spec/spec_helper.rb +9 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e95a39bfddb66aa733baf30ef52d730d91ba27bcea85511287d665481d84aae
|
4
|
+
data.tar.gz: 6c462647a07e2f004a1df85c343f4a2a6a53aac7e0aa3eea9a47aed46e7a5e1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 392c83c6672ec4ecf4cf245649edd9be86af018bcc5f03c2206159577100224a01f6067289a85da0d2730c13706eacd8b3397ab97eb8a5069539d6d8e16985d8
|
7
|
+
data.tar.gz: 05af317f628941fc049c0bc9a0c470ed437eff7d76568d42ef0948434f2311661d904810b73e0ebf38e6773aa0af805e5efb3fbe27da121b7a0aff20a89c40fd
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
metanorma-standoc (1.3.
|
5
|
-
asciidoctor (~>
|
4
|
+
metanorma-standoc (1.3.7)
|
5
|
+
asciidoctor (~> 2.0.0)
|
6
6
|
concurrent-ruby
|
7
7
|
html2doc (~> 0.9.0)
|
8
8
|
iev (~> 0.2.1)
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
specs:
|
20
20
|
addressable (2.7.0)
|
21
21
|
public_suffix (>= 2.0.2, < 5.0)
|
22
|
-
asciidoctor (
|
22
|
+
asciidoctor (2.0.10)
|
23
23
|
asciimath (1.0.9)
|
24
24
|
ast (2.4.0)
|
25
25
|
byebug (11.0.1)
|
@@ -37,7 +37,7 @@ GEM
|
|
37
37
|
ffi (1.11.1)
|
38
38
|
formatador (0.2.5)
|
39
39
|
gb-agencies (0.0.6)
|
40
|
-
guard (2.
|
40
|
+
guard (2.16.1)
|
41
41
|
formatador (>= 0.2.4)
|
42
42
|
listen (>= 2.7, < 4.0)
|
43
43
|
lumberjack (>= 1.0.12, < 2.0)
|
@@ -52,7 +52,7 @@ GEM
|
|
52
52
|
guard-compat (~> 1.1)
|
53
53
|
rspec (>= 2.99.0, < 4.0)
|
54
54
|
hashdiff (1.0.0)
|
55
|
-
html2doc (0.9.
|
55
|
+
html2doc (0.9.1)
|
56
56
|
asciimath (~> 1.0.9)
|
57
57
|
htmlentities (~> 4.3.4)
|
58
58
|
image_size
|
@@ -64,7 +64,7 @@ GEM
|
|
64
64
|
iev (0.2.3)
|
65
65
|
nokogiri (>= 1.10.4)
|
66
66
|
image_size (2.0.2)
|
67
|
-
isodoc (1.0.
|
67
|
+
isodoc (1.0.7)
|
68
68
|
asciimath
|
69
69
|
html2doc (~> 0.9.0)
|
70
70
|
htmlentities (~> 4.3.4)
|
@@ -83,7 +83,7 @@ GEM
|
|
83
83
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
84
84
|
rb-inotify (~> 0.9, >= 0.9.10)
|
85
85
|
lumberjack (1.0.13)
|
86
|
-
metanorma (0.3.
|
86
|
+
metanorma (0.3.16)
|
87
87
|
asciidoctor
|
88
88
|
htmlentities
|
89
89
|
method_source (0.9.2)
|
@@ -94,7 +94,7 @@ GEM
|
|
94
94
|
mini_portile2 (2.4.0)
|
95
95
|
multipart-post (2.1.1)
|
96
96
|
nenv (0.3.0)
|
97
|
-
nokogiri (1.10.
|
97
|
+
nokogiri (1.10.5)
|
98
98
|
mini_portile2 (~> 2.4.0)
|
99
99
|
notiffany (0.1.3)
|
100
100
|
nenv (~> 0.1)
|
@@ -113,7 +113,8 @@ GEM
|
|
113
113
|
rb-fsevent (0.10.3)
|
114
114
|
rb-inotify (0.10.0)
|
115
115
|
ffi (~> 1.0)
|
116
|
-
relaton (0.5.
|
116
|
+
relaton (0.5.11)
|
117
|
+
relaton-calconnect (~> 0.1.0)
|
117
118
|
relaton-gb (~> 0.6.0)
|
118
119
|
relaton-iec (~> 0.4.0)
|
119
120
|
relaton-ietf (~> 0.6.0)
|
@@ -121,33 +122,36 @@ GEM
|
|
121
122
|
relaton-itu (~> 0.3.0)
|
122
123
|
relaton-nist (~> 0.3.0)
|
123
124
|
relaton-ogc (~> 0.1.0)
|
124
|
-
relaton-bib (0.3.
|
125
|
+
relaton-bib (0.3.12)
|
125
126
|
addressable
|
126
127
|
nokogiri
|
127
|
-
relaton-
|
128
|
+
relaton-calconnect (0.1.0)
|
129
|
+
faraday
|
130
|
+
relaton-iso-bib (~> 0.3.0)
|
131
|
+
relaton-gb (0.6.7)
|
128
132
|
cnccs (~> 0.1.1)
|
129
133
|
gb-agencies (~> 0.0.1)
|
130
134
|
relaton-iso-bib (~> 0.3.0)
|
131
|
-
relaton-iec (0.4.
|
135
|
+
relaton-iec (0.4.10)
|
132
136
|
addressable
|
133
137
|
relaton-iso-bib (~> 0.3.0)
|
134
|
-
relaton-ietf (0.6.
|
138
|
+
relaton-ietf (0.6.9)
|
135
139
|
relaton-bib (~> 0.3.0)
|
136
140
|
relaton-iev (0.1.1)
|
137
141
|
relaton (~> 0.5.0)
|
138
|
-
relaton-iso (0.6.
|
142
|
+
relaton-iso (0.6.9)
|
139
143
|
relaton-iec (~> 0.4.0)
|
140
144
|
relaton-iso-bib (~> 0.3.0)
|
141
|
-
relaton-iso-bib (0.3.
|
145
|
+
relaton-iso-bib (0.3.12)
|
142
146
|
isoics (~> 0.1.6)
|
143
147
|
relaton-bib (~> 0.3.0)
|
144
148
|
ruby_deep_clone (~> 0.8.0)
|
145
|
-
relaton-itu (0.3.
|
149
|
+
relaton-itu (0.3.7)
|
146
150
|
relaton-iso-bib (~> 0.3.0)
|
147
|
-
relaton-nist (0.3.
|
151
|
+
relaton-nist (0.3.8)
|
148
152
|
relaton-bib (~> 0.3.0)
|
149
153
|
rubyzip
|
150
|
-
relaton-ogc (0.1.
|
154
|
+
relaton-ogc (0.1.4)
|
151
155
|
faraday
|
152
156
|
relaton-iso-bib (~> 0.3.0)
|
153
157
|
roman-numerals (0.3.0)
|
data/README.adoc
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
= Metanorma-standoc
|
2
2
|
|
3
3
|
image:https://img.shields.io/gem/v/metanorma-standoc.svg["Gem Version", link="https://rubygems.org/gems/metanorma-standoc"]
|
4
|
-
image:https://
|
4
|
+
image:https://travis-ci.com/metanorma/metanorma-standoc.svg["Build Status", link="https://travis-ci.com/metanorma/metanorma-standoc"]
|
5
|
+
image:https://ci.appveyor.com/api/projects/status/dbt5mjpe69whcvpb?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/metanorma/metanorma-standoc"]
|
5
6
|
image:https://codeclimate.com/github/metanorma/metanorma-standoc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/metanorma-standoc"]
|
6
|
-
image:https://
|
7
|
-
|
8
|
-
WARNING: This gem is still under development.
|
7
|
+
image:https://img.shields.io/github/issues-pr-raw/metanorma/metanorma-standoc.svg["Pull Requests", link="https://github.com/metanorma/metanorma-standoc/pulls"]
|
8
|
+
image:https://img.shields.io/github/commits-since/metanorma/metanorma-standoc/latest.svg["Commits since latest",link="https://github.com/metanorma/metanorma-standoc/releases"]
|
9
9
|
|
10
10
|
Gem for serialising the https://github.com/metanorma/metanorma-model-standoc[Metanorma Standoc] model.
|
11
11
|
|
@@ -20,6 +20,7 @@ module Asciidoctor
|
|
20
20
|
block Asciidoctor::Standoc::ToDoAdmonitionBlock
|
21
21
|
treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
|
22
22
|
block Asciidoctor::Standoc::PlantUMLBlockMacro
|
23
|
+
block Asciidoctor::Standoc::PseudocodeBlockMacro
|
23
24
|
end
|
24
25
|
|
25
26
|
def content(node)
|
@@ -341,11 +341,6 @@
|
|
341
341
|
</oneOrMore>
|
342
342
|
</element>
|
343
343
|
</define>
|
344
|
-
<define name="tclass">
|
345
|
-
<element name="name">
|
346
|
-
<text/>
|
347
|
-
</element>
|
348
|
-
</define>
|
349
344
|
<define name="thead">
|
350
345
|
<element name="thead">
|
351
346
|
<ref name="tr"/>
|
@@ -515,19 +510,22 @@
|
|
515
510
|
<attribute name="subsequence"/>
|
516
511
|
</optional>
|
517
512
|
<optional>
|
518
|
-
<
|
513
|
+
<attribute name="class"/>
|
519
514
|
</optional>
|
520
515
|
<optional>
|
521
|
-
<ref name="
|
516
|
+
<ref name="source"/>
|
522
517
|
</optional>
|
523
518
|
<optional>
|
524
|
-
<ref name="
|
519
|
+
<ref name="tname"/>
|
525
520
|
</optional>
|
526
521
|
<choice>
|
527
522
|
<ref name="image"/>
|
528
523
|
<ref name="video"/>
|
529
524
|
<ref name="audio"/>
|
530
525
|
<ref name="pre"/>
|
526
|
+
<oneOrMore>
|
527
|
+
<ref name="paragraph-with-footnote"/>
|
528
|
+
</oneOrMore>
|
531
529
|
<zeroOrMore>
|
532
530
|
<ref name="figure"/>
|
533
531
|
</zeroOrMore>
|
@@ -147,6 +147,21 @@ module Asciidoctor
|
|
147
147
|
role = node.role || node.attr("style")
|
148
148
|
%w(recommendation requirement permission).include?(role) and
|
149
149
|
return requirement(node, role)
|
150
|
+
return pseudocode_example(node) if role == "pseudocode"
|
151
|
+
example_proper(node)
|
152
|
+
end
|
153
|
+
|
154
|
+
def pseudocode_example(node)
|
155
|
+
noko do |xml|
|
156
|
+
xml.figure **{id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node),
|
157
|
+
class: "pseudocode"} do |ex|
|
158
|
+
figure_title(node, ex)
|
159
|
+
wrap_in_para(node, ex)
|
160
|
+
end
|
161
|
+
end.join("\n")
|
162
|
+
end
|
163
|
+
|
164
|
+
def example_proper(node)
|
150
165
|
noko do |xml|
|
151
166
|
xml.example **id_unnum_attr(node) do |ex|
|
152
167
|
node.title.nil? or ex.name { |name| name << node.title }
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require "date"
|
2
1
|
require "nokogiri"
|
3
2
|
require "pathname"
|
4
3
|
require "open-uri"
|
5
4
|
require "html2doc"
|
6
|
-
require "pp"
|
7
5
|
require_relative "./cleanup_block.rb"
|
8
6
|
require_relative "./cleanup_footnotes.rb"
|
9
7
|
require_relative "./cleanup_ref.rb"
|
@@ -16,8 +14,6 @@ module Asciidoctor
|
|
16
14
|
def textcleanup(result)
|
17
15
|
text = result.flatten.map { |l| l.sub(/\s*$/, "") } * "\n"
|
18
16
|
if !@keepasciimath
|
19
|
-
#text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m,
|
20
|
-
#'<amathstem>\1</amathstem>')
|
21
17
|
text = text.gsub(%r{<stem type="AsciiMath">(.+?)</stem>}m) do |m|
|
22
18
|
"<amathstem>#{HTMLEntities.new.decode($1)}</amathstem>"
|
23
19
|
end
|
@@ -66,11 +62,14 @@ module Asciidoctor
|
|
66
62
|
end
|
67
63
|
|
68
64
|
def smartquotes_cleanup(xmldoc)
|
69
|
-
return unless @smartquotes
|
70
65
|
xmldoc.traverse do |n|
|
71
66
|
next unless n.text?
|
72
|
-
|
73
|
-
|
67
|
+
if @smartquotes
|
68
|
+
next unless n.ancestors("pre, tt, sourcecode, bibdata, on").empty?
|
69
|
+
n.replace(Utils::smartformat(n.text))
|
70
|
+
else
|
71
|
+
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'"))
|
72
|
+
end
|
74
73
|
end
|
75
74
|
xmldoc
|
76
75
|
end
|
@@ -89,9 +88,7 @@ module Asciidoctor
|
|
89
88
|
# because of its use in HTML. Bad nokogiri. Undoing that, since we use
|
90
89
|
# script as a normal tag
|
91
90
|
def script_cleanup(xmldoc)
|
92
|
-
xmldoc.xpath("//script").each
|
93
|
-
x.content = x.to_str
|
94
|
-
end
|
91
|
+
xmldoc.xpath("//script").each { |x| x.content = x.to_str }
|
95
92
|
end
|
96
93
|
|
97
94
|
def empty_element_cleanup(xmldoc)
|
@@ -177,9 +174,7 @@ module Asciidoctor
|
|
177
174
|
end
|
178
175
|
|
179
176
|
def termdef_subclause_cleanup(xmldoc)
|
180
|
-
xmldoc.xpath("//terms[terms]").each
|
181
|
-
t.name = "clause"
|
182
|
-
end
|
177
|
+
xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
|
183
178
|
end
|
184
179
|
|
185
180
|
def termdocsource_cleanup(xmldoc)
|
@@ -212,9 +207,7 @@ module Asciidoctor
|
|
212
207
|
|
213
208
|
def empty_text_before_first_element(x)
|
214
209
|
x.children.each do |c|
|
215
|
-
if c.text?
|
216
|
-
return false if /\S/.match(c.text)
|
217
|
-
end
|
210
|
+
return false if c.text? and /\S/.match(c.text)
|
218
211
|
return true if c.element?
|
219
212
|
end
|
220
213
|
true
|
@@ -52,9 +52,10 @@ module Asciidoctor
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def inline_anchor_bibref(node)
|
55
|
-
eref_contents = node.
|
56
|
-
|
57
|
-
|
55
|
+
eref_contents = (node.text || node.target || node.id)&.
|
56
|
+
sub(/^\[?([^\[\]]+?)\]?$/, "[\\1]")
|
57
|
+
eref_attributes = { id: node.target || node.id }
|
58
|
+
@refids << (node.target || node.id)
|
58
59
|
noko do |xml|
|
59
60
|
xml.ref **attr_code(eref_attributes) do |r|
|
60
61
|
r << eref_contents
|
@@ -40,6 +40,24 @@ module Asciidoctor
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
class PseudocodeBlockMacro < Asciidoctor::Extensions::BlockProcessor
|
44
|
+
use_dsl
|
45
|
+
named :pseudocode
|
46
|
+
on_context :example, :sourcecode
|
47
|
+
|
48
|
+
def init_indent(s)
|
49
|
+
/^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s
|
50
|
+
prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0").gsub(/ /, "\u00a0")
|
51
|
+
prefix + suffix
|
52
|
+
end
|
53
|
+
|
54
|
+
def process parent, reader, attrs
|
55
|
+
attrs['role'] = 'pseudocode'
|
56
|
+
create_block parent, :example, reader.lines.map { |m| init_indent(m) }, attrs,
|
57
|
+
content_model: :compound
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
43
61
|
class HTML5RubyMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
44
62
|
use_dsl
|
45
63
|
named :ruby
|
@@ -48,8 +66,8 @@ module Asciidoctor
|
|
48
66
|
option :pos_attrs, %w(rpbegin rt rpend)
|
49
67
|
|
50
68
|
def process(parent, target, attributes)
|
51
|
-
|
52
|
-
|
69
|
+
rpbegin = '('
|
70
|
+
rpend = ')'
|
53
71
|
if attributes.size == 1 and attributes.key?("text")
|
54
72
|
rt = attributes["text"]
|
55
73
|
elsif attributes.size == 2 and attributes.key?(1) and attributes.key?("rpbegin")
|
@@ -42,20 +42,26 @@ module Asciidoctor
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def docid(t, code)
|
45
|
-
type, code1 = /^\[\d+\]$|^\(.+\)$/.match(code) ?
|
45
|
+
type, code1 = /^\[\d+\]$|^\(.+\)$/.match(code) ?
|
46
46
|
["metanorma", code.sub(/^\(/, "[").sub(/\)$/, "]")] :
|
47
47
|
@bibdb&.docid_type(code) || [nil, code]
|
48
48
|
t.docidentifier code1, **attr_code(type: type)
|
49
49
|
end
|
50
50
|
|
51
|
+
def norm_year(yr)
|
52
|
+
return "--" if /^\&\#821[12];$/.match yr
|
53
|
+
yr
|
54
|
+
end
|
55
|
+
|
51
56
|
def isorefmatches(xml, m)
|
52
|
-
|
57
|
+
yr = norm_year(m[:year])
|
58
|
+
ref = fetch_ref xml, m[:code], yr, title: m[:text]
|
53
59
|
return use_my_anchor(ref, m[:anchor]) if ref
|
54
60
|
xml.bibitem **attr_code(ref_attributes(m)) do |t|
|
55
61
|
t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
|
56
|
-
docid(t, id_and_year(m[:code],
|
57
|
-
|
58
|
-
set_date_range(d,
|
62
|
+
docid(t, id_and_year(m[:code], yr))
|
63
|
+
yr and t.date **{ type: "published" } do |d|
|
64
|
+
set_date_range(d, yr)
|
59
65
|
end
|
60
66
|
iso_publisher(t, m[:code])
|
61
67
|
end
|
@@ -69,10 +75,10 @@ module Asciidoctor
|
|
69
75
|
t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
|
70
76
|
docid(t, id_and_year(m[:code], "--"))
|
71
77
|
t.date **{ type: "published" } do |d|
|
72
|
-
d.on "--"
|
78
|
+
d.on "--"
|
73
79
|
end
|
74
80
|
iso_publisher(t, m[:code])
|
75
|
-
t.note(**plaintxt) { |p| p << "ISO DATE: #{m[:fn]}" }
|
81
|
+
m[:fn].nil? or t.note(**plaintxt) { |p| p << "ISO DATE: #{m[:fn]}" }
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
@@ -81,20 +87,21 @@ module Asciidoctor
|
|
81
87
|
t.date(**{ type: "published" }) do |d|
|
82
88
|
if noyr then d.on "--"
|
83
89
|
else
|
84
|
-
set_date_range(d, m[:year])
|
90
|
+
set_date_range(d, norm_year(m[:year]))
|
85
91
|
end
|
86
92
|
end
|
87
93
|
end
|
88
94
|
|
89
95
|
def isorefmatches3(xml, m)
|
90
|
-
|
91
|
-
|
92
|
-
|
96
|
+
yr = norm_year(m[:year])
|
97
|
+
hasyr = m.names.include?("year") && yr != "--"
|
98
|
+
noyr = m.names.include?("year") && yr == "--"
|
99
|
+
ref = fetch_ref xml, m[:code], hasyr ? yr : nil,
|
93
100
|
all_parts: true, no_year: noyr, text: m[:text]
|
94
101
|
return use_my_anchor(ref, m[:anchor]) if ref
|
95
102
|
xml.bibitem(**attr_code(ref_attributes(m))) do |t|
|
96
103
|
t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
|
97
|
-
docid(t, id_and_year(m[:code],
|
104
|
+
docid(t, id_and_year(m[:code], yr) + " (all parts)")
|
98
105
|
conditional_date(t, m, noyr)
|
99
106
|
iso_publisher(t, m[:code])
|
100
107
|
m.names.include?("fn") && m[:fn] and
|
@@ -107,7 +114,7 @@ module Asciidoctor
|
|
107
114
|
|
108
115
|
def fetch_ref(xml, code, year, **opts)
|
109
116
|
return nil if opts[:no_year]
|
110
|
-
hit = @bibdb&.fetch(code, year, opts)
|
117
|
+
hit = @bibdb&.fetch(code, year, opts)
|
111
118
|
return nil if hit.nil?
|
112
119
|
xml.parent.add_child(Utils::smart_render_xml(hit, code, opts[:title]))
|
113
120
|
xml
|
@@ -125,14 +132,19 @@ module Asciidoctor
|
|
125
132
|
end
|
126
133
|
end
|
127
134
|
|
135
|
+
MALFORMED_REF =
|
136
|
+
"no anchor on reference, markup may be malformed: "\
|
137
|
+
"see https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
|
138
|
+
"https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
|
139
|
+
|
128
140
|
# TODO: alternative where only title is available
|
129
141
|
def refitem(xml, item, node)
|
130
142
|
unless m = NON_ISO_REF.match(item)
|
131
|
-
Utils::warning(node,
|
143
|
+
Utils::warning(node, MALFORMED_REF, item)
|
132
144
|
return
|
133
145
|
end
|
134
146
|
unless m[:code] && /^\d+$/.match(m[:code])
|
135
|
-
ref = fetch_ref xml, m[:code],
|
147
|
+
ref = fetch_ref xml, m[:code],
|
136
148
|
m.names.include?("year") ? m[:year] : nil, { title: m[:text] }
|
137
149
|
return use_my_anchor(ref, m[:anchor]) if ref
|
138
150
|
end
|
@@ -154,63 +166,63 @@ module Asciidoctor
|
|
154
166
|
|
155
167
|
ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
156
168
|
\[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
|
157
|
-
(:(?<year>[0-9][0-9-]+))?\]</ref>,?\s
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
\[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+)
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
# @param node [Asciidoctor::List]
|
183
|
-
# @param item [String]
|
184
|
-
# @param xml [Nokogiri::XML::Builder]
|
185
|
-
def reference1(node, item, xml)
|
186
|
-
matched, matched2, matched3 = reference1_matches(item)
|
187
|
-
if matched3.nil? && matched2.nil? && matched.nil?
|
188
|
-
refitem(xml, item, node)
|
189
|
-
# elsif fetch_ref(matched3 || matched2 || matched, xml)
|
190
|
-
elsif !matched.nil? then isorefmatches(xml, matched)
|
191
|
-
elsif !matched2.nil? then isorefmatches2(xml, matched2)
|
192
|
-
elsif !matched3.nil? then isorefmatches3(xml, matched3)
|
169
|
+
(:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*
|
170
|
+
(?<text>.*)$}xm
|
171
|
+
|
172
|
+
ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
|
173
|
+
\[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):(--|\&\#821[12]\;)\]</ref>,?\s*
|
174
|
+
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
|
175
|
+
|
176
|
+
ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
|
177
|
+
\[(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)(:(?<year>--|\&\#821[12]\;|[0-9][0-9-]+))?\s
|
178
|
+
\(all\sparts\)\]</ref>,?\s*
|
179
|
+
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
|
180
|
+
|
181
|
+
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
182
|
+
\[(?<code>[^\]]+?)([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s*
|
183
|
+
(?<text>.*)$}xm
|
184
|
+
|
185
|
+
# @param item [String]
|
186
|
+
# @return [Array<MatchData>]
|
187
|
+
def reference1_matches(item)
|
188
|
+
matched = ISO_REF.match item
|
189
|
+
matched2 = ISO_REF_NO_YEAR.match item
|
190
|
+
matched3 = ISO_REF_ALL_PARTS.match item
|
191
|
+
[matched, matched2, matched3]
|
193
192
|
end
|
194
|
-
end
|
195
193
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
194
|
+
# @param node [Asciidoctor::List]
|
195
|
+
# @param item [String]
|
196
|
+
# @param xml [Nokogiri::XML::Builder]
|
197
|
+
def reference1(node, item, xml)
|
198
|
+
matched, matched2, matched3 = reference1_matches(item)
|
199
|
+
if matched3.nil? && matched2.nil? && matched.nil?
|
200
|
+
refitem(xml, item, node)
|
201
|
+
# elsif fetch_ref(matched3 || matched2 || matched, xml)
|
202
|
+
elsif !matched.nil? then isorefmatches(xml, matched)
|
203
|
+
elsif !matched2.nil? then isorefmatches2(xml, matched2)
|
204
|
+
elsif !matched3.nil? then isorefmatches3(xml, matched3)
|
200
205
|
end
|
201
|
-
end
|
202
|
-
end
|
206
|
+
end
|
203
207
|
|
204
|
-
|
205
|
-
|
206
|
-
|
208
|
+
def reference(node)
|
209
|
+
noko do |xml|
|
210
|
+
node.items.each do |item|
|
211
|
+
reference1(node, item.text, xml)
|
212
|
+
end
|
213
|
+
end.join("\n")
|
214
|
+
end
|
207
215
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
216
|
+
def global_ievcache_name
|
217
|
+
"#{Dir.home}/.iev/cache"
|
218
|
+
end
|
219
|
+
|
220
|
+
def local_ievcache_name(cachename)
|
221
|
+
return nil if cachename.nil?
|
222
|
+
cachename += "_iev" unless cachename.empty?
|
223
|
+
cachename = "iev" if cachename.empty?
|
224
|
+
"#{cachename}/cache"
|
225
|
+
end
|
214
226
|
end
|
215
227
|
end
|
216
228
|
end
|