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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 804da6a0cd7fbb0bf6fb9ec3b96f2ebdfba1c2c2cfe495a0f8163a7aa00ba2b6
4
- data.tar.gz: a83e9da845f9a0424e1d357238ad8729aa5f6a4a846582b7536f23df90f92410
3
+ metadata.gz: 4e95a39bfddb66aa733baf30ef52d730d91ba27bcea85511287d665481d84aae
4
+ data.tar.gz: 6c462647a07e2f004a1df85c343f4a2a6a53aac7e0aa3eea9a47aed46e7a5e1e
5
5
  SHA512:
6
- metadata.gz: dd5460a4a0f27b5e4452f71f3444092e81e45187b5011e7e6d815f80594957f1e3aa9851adee53bcfa7047066ed945c7f46f0c0b8c7645e153682491319070c8
7
- data.tar.gz: 11f9fdee478b91fca447bc75fd6da139a836ab39c5e66c5d1c90f0ab50ca359d9fc52191c6ce8e1d5c743a605b9b184ea2d0e709f5a4fe2d36fca023a0b045d3
6
+ metadata.gz: 392c83c6672ec4ecf4cf245649edd9be86af018bcc5f03c2206159577100224a01f6067289a85da0d2730c13706eacd8b3397ab97eb8a5069539d6d8e16985d8
7
+ data.tar.gz: 05af317f628941fc049c0bc9a0c470ed437eff7d76568d42ef0948434f2311661d904810b73e0ebf38e6773aa0af805e5efb3fbe27da121b7a0aff20a89c40fd
@@ -29,7 +29,6 @@ jobs:
29
29
  - name: Install LaTeXML
30
30
  run: |
31
31
  sudo snap install latexml
32
- sudo snap alias latexml.math latexmlmath
33
32
  - name: Install PlantUML
34
33
  run: |
35
34
  curl -L https://raw.githubusercontent.com/metanorma/plantuml-install/master/ubuntu.sh | sudo bash
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- metanorma-standoc (1.3.6)
5
- asciidoctor (~> 1.5.7)
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 (1.5.8)
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.15.1)
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.0)
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.6)
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.15)
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.4)
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.9)
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.11)
125
+ relaton-bib (0.3.12)
125
126
  addressable
126
127
  nokogiri
127
- relaton-gb (0.6.6)
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.9)
135
+ relaton-iec (0.4.10)
132
136
  addressable
133
137
  relaton-iso-bib (~> 0.3.0)
134
- relaton-ietf (0.6.7)
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.8)
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.11)
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.6)
149
+ relaton-itu (0.3.7)
146
150
  relaton-iso-bib (~> 0.3.0)
147
- relaton-nist (0.3.7)
151
+ relaton-nist (0.3.8)
148
152
  relaton-bib (~> 0.3.0)
149
153
  rubyzip
150
- relaton-ogc (0.1.3)
154
+ relaton-ogc (0.1.4)
151
155
  faraday
152
156
  relaton-iso-bib (~> 0.3.0)
153
157
  roman-numerals (0.3.0)
@@ -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://img.shields.io/travis/metanorma/metanorma-standoc/master.svg["Build Status", link="https://travis-ci.org/metanorma/metanorma-standoc"]
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://ci.appveyor.com/api/projects/status/qdadxv7rqfy33p66?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/ribose/metanorma-standoc"]
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
- <ref name="source"/>
513
+ <attribute name="class"/>
519
514
  </optional>
520
515
  <optional>
521
- <ref name="tname"/>
516
+ <ref name="source"/>
522
517
  </optional>
523
518
  <optional>
524
- <ref name="tclass"/>
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
- next unless n.ancestors("pre, tt, sourcecode, bibdata, on").empty?
73
- n.replace(Utils::smartformat(n.text))
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 do |x|
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 do |t|
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.target == node.text ? nil : node.text
56
- eref_attributes = { id: node.target }
57
- @refids << node.target
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
- rpbegin = '('
52
- rpend = ')'
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
- ref = fetch_ref xml, m[:code], m[:year], title: m[:text]
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], m[:year]))
57
- m[:year] and t.date **{ type: "published" } do |d|
58
- set_date_range(d, m[:year])
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
- hasyr = m.names.include?("year") && m[:year] != "--"
91
- noyr = m.names.include?("year") && m[:year] == "--"
92
- ref = fetch_ref xml, m[:code], hasyr ? m[:year] : nil,
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], m[:year]) + " (all parts)")
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, "no anchor on reference", item)
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
- (?<text>.*)$}xm
159
-
160
- ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
161
- \[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):--\]</ref>,?\s?
162
- <fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?(?<text>.*)$}xm
163
-
164
- ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
165
- \[(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)(:(?<year>--|[0-9][0-9-]+))?\s
166
- \(all\sparts\)\]</ref>,?\s
167
- (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
168
-
169
- NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
170
- \[(?<code>[^\]]+?)([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s
171
- (?<text>.*)$}xm
172
-
173
- # @param item [String]
174
- # @return [Array<MatchData>]
175
- def reference1_matches(item)
176
- matched = ISO_REF.match item
177
- matched2 = ISO_REF_NO_YEAR.match item
178
- matched3 = ISO_REF_ALL_PARTS.match item
179
- [matched, matched2, matched3]
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
- def reference(node)
197
- noko do |xml|
198
- node.items.each do |item|
199
- reference1(node, item.text, xml)
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.join("\n")
202
- end
206
+ end
203
207
 
204
- def global_ievcache_name
205
- "#{Dir.home}/.iev/cache"
206
- end
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
- def local_ievcache_name(cachename)
209
- return nil if cachename.nil?
210
- cachename += "_iev" unless cachename.empty?
211
- cachename = "iev" if cachename.empty?
212
- "#{cachename}/cache"
213
- end
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