metanorma-standoc 1.8.5 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +5 -1
  4. data/Gemfile.devel +0 -0
  5. data/lib/asciidoctor/standoc/base.rb +41 -36
  6. data/lib/asciidoctor/standoc/biblio.rng +4 -6
  7. data/lib/asciidoctor/standoc/blocks.rb +27 -12
  8. data/lib/asciidoctor/standoc/blocks_notes.rb +20 -14
  9. data/lib/asciidoctor/standoc/cleanup.rb +32 -78
  10. data/lib/asciidoctor/standoc/cleanup_block.rb +56 -59
  11. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +32 -21
  12. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
  13. data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
  14. data/lib/asciidoctor/standoc/cleanup_maths.rb +37 -28
  15. data/lib/asciidoctor/standoc/cleanup_ref.rb +21 -13
  16. data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +1 -1
  17. data/lib/asciidoctor/standoc/cleanup_reqt.rb +47 -0
  18. data/lib/asciidoctor/standoc/cleanup_section.rb +21 -15
  19. data/lib/asciidoctor/standoc/converter.rb +3 -1
  20. data/lib/asciidoctor/standoc/front.rb +35 -18
  21. data/lib/asciidoctor/standoc/front_contributor.rb +5 -5
  22. data/lib/asciidoctor/standoc/inline.rb +1 -1
  23. data/lib/asciidoctor/standoc/isodoc.rng +130 -1
  24. data/lib/asciidoctor/standoc/lists.rb +4 -2
  25. data/lib/asciidoctor/standoc/macros.rb +40 -13
  26. data/lib/asciidoctor/standoc/ref.rb +87 -112
  27. data/lib/asciidoctor/standoc/ref_date_id.rb +62 -0
  28. data/lib/asciidoctor/standoc/ref_sect.rb +12 -12
  29. data/lib/asciidoctor/standoc/terms.rb +10 -6
  30. data/lib/asciidoctor/standoc/utils.rb +32 -6
  31. data/lib/asciidoctor/standoc/validate.rb +12 -12
  32. data/lib/metanorma/standoc/version.rb +5 -5
  33. data/metanorma-standoc.gemspec +11 -11
  34. data/spec/asciidoctor/base_spec.rb +78 -8
  35. data/spec/asciidoctor/blocks_spec.rb +10 -0
  36. data/spec/asciidoctor/cleanup_sections_spec.rb +14 -14
  37. data/spec/asciidoctor/cleanup_spec.rb +1860 -1874
  38. data/spec/asciidoctor/inline_spec.rb +272 -273
  39. data/spec/asciidoctor/macros_spec.rb +8 -2
  40. data/spec/asciidoctor/refs_spec.rb +135 -7
  41. data/spec/asciidoctor/section_spec.rb +670 -687
  42. data/spec/assets/html-override.css +1 -0
  43. data/spec/assets/word-override.css +1 -0
  44. data/spec/spec_helper.rb +11 -9
  45. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +60 -60
  46. data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
  47. data/spec/vcr_cassettes/isobib_get_123_1.yml +32 -32
  48. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +41 -41
  49. data/spec/vcr_cassettes/isobib_get_123_2001.yml +15 -15
  50. data/spec/vcr_cassettes/isobib_get_124.yml +17 -17
  51. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
  52. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +53 -49
  53. metadata +71 -68
  54. data/.rubocop.ribose.yml +0 -66
  55. data/.rubocop.tb.yml +0 -650
  56. data/spec/asciidoctor/macros_lutaml_spec.rb +0 -80
@@ -45,7 +45,7 @@ module Asciidoctor
45
45
 
46
46
  def inline_anchor_xref_attrs(node)
47
47
  m = /^(?<drop>droploc%)?(?<case>capital%|lowercase%)?(?<drop2>droploc%)?
48
- (?<fn>fn(:\s*(?<text>.*))?)?$/x.match node.text
48
+ (?<fn>fn:?\s*)?(?<text>.*)$/x.match node.text
49
49
  casing = m.nil? ? nil : m[:case]&.sub(/%$/, "")
50
50
  droploc = m.nil? ? nil : ((m[:drop].nil? && m[:drop2].nil?) ? nil: true)
51
51
  f = (m.nil? || m[:fn].nil?) ? "inline" : "footnote"
@@ -86,6 +86,35 @@
86
86
  <text/>
87
87
  </element>
88
88
  </define>
89
+ <define name="erefType">
90
+ <optional>
91
+ <attribute name="normative">
92
+ <data type="boolean"/>
93
+ </attribute>
94
+ </optional>
95
+ <attribute name="citeas"/>
96
+ <attribute name="type">
97
+ <ref name="ReferenceFormat"/>
98
+ </attribute>
99
+ <optional>
100
+ <attribute name="alt"/>
101
+ </optional>
102
+ <optional>
103
+ <attribute name="case">
104
+ <choice>
105
+ <value>capital</value>
106
+ <value>lowercase</value>
107
+ </choice>
108
+ </attribute>
109
+ </optional>
110
+ <optional>
111
+ <attribute name="droploc">
112
+ <data type="boolean"/>
113
+ </attribute>
114
+ </optional>
115
+ <ref name="CitationType"/>
116
+ <text/>
117
+ </define>
89
118
  <define name="ul">
90
119
  <element name="ul">
91
120
  <attribute name="id">
@@ -775,6 +804,78 @@
775
804
  <ref name="paragraph"/>
776
805
  </element>
777
806
  </define>
807
+ <define name="em">
808
+ <element name="em">
809
+ <zeroOrMore>
810
+ <choice>
811
+ <ref name="PureTextElement"/>
812
+ <ref name="stem"/>
813
+ <ref name="index"/>
814
+ </choice>
815
+ </zeroOrMore>
816
+ </element>
817
+ </define>
818
+ <define name="strong">
819
+ <element name="strong">
820
+ <zeroOrMore>
821
+ <choice>
822
+ <ref name="PureTextElement"/>
823
+ <ref name="stem"/>
824
+ <ref name="index"/>
825
+ </choice>
826
+ </zeroOrMore>
827
+ </element>
828
+ </define>
829
+ <define name="tt">
830
+ <element name="tt">
831
+ <zeroOrMore>
832
+ <choice>
833
+ <ref name="PureTextElement"/>
834
+ <ref name="index"/>
835
+ </choice>
836
+ </zeroOrMore>
837
+ </element>
838
+ </define>
839
+ <define name="keyword">
840
+ <element name="keyword">
841
+ <zeroOrMore>
842
+ <choice>
843
+ <ref name="PureTextElement"/>
844
+ <ref name="index"/>
845
+ </choice>
846
+ </zeroOrMore>
847
+ </element>
848
+ </define>
849
+ <define name="strike">
850
+ <element name="strike">
851
+ <zeroOrMore>
852
+ <choice>
853
+ <ref name="PureTextElement"/>
854
+ <ref name="index"/>
855
+ </choice>
856
+ </zeroOrMore>
857
+ </element>
858
+ </define>
859
+ <define name="underline">
860
+ <element name="underline">
861
+ <zeroOrMore>
862
+ <choice>
863
+ <ref name="PureTextElement"/>
864
+ <ref name="index"/>
865
+ </choice>
866
+ </zeroOrMore>
867
+ </element>
868
+ </define>
869
+ <define name="smallcap">
870
+ <element name="smallcap">
871
+ <zeroOrMore>
872
+ <choice>
873
+ <ref name="PureTextElement"/>
874
+ <ref name="index"/>
875
+ </choice>
876
+ </zeroOrMore>
877
+ </element>
878
+ </define>
778
879
  </include>
779
880
  <!-- end overrides -->
780
881
  <define name="colgroup">
@@ -793,7 +894,35 @@
793
894
  <value>internal</value>
794
895
  </define>
795
896
  <define name="TextElement" combine="choice">
796
- <ref name="concept"/>
897
+ <choice>
898
+ <ref name="concept"/>
899
+ <ref name="add"/>
900
+ <ref name="del"/>
901
+ </choice>
902
+ </define>
903
+ <define name="add">
904
+ <element name="add">
905
+ <choice>
906
+ <ref name="PureTextElement"/>
907
+ <ref name="eref"/>
908
+ <ref name="stem"/>
909
+ <ref name="keyword"/>
910
+ <ref name="xref"/>
911
+ <ref name="hyperlink"/>
912
+ </choice>
913
+ </element>
914
+ </define>
915
+ <define name="del">
916
+ <element name="del">
917
+ <choice>
918
+ <ref name="PureTextElement"/>
919
+ <ref name="eref"/>
920
+ <ref name="stem"/>
921
+ <ref name="keyword"/>
922
+ <ref name="xref"/>
923
+ <ref name="hyperlink"/>
924
+ </choice>
925
+ </element>
797
926
  </define>
798
927
  <define name="concept">
799
928
  <element name="concept">
@@ -28,14 +28,16 @@ module Asciidoctor
28
28
  end
29
29
 
30
30
  def ul_li_attrs(node)
31
+ c = node.attr?("checked")
31
32
  attr_code(
32
- uncheckedcheckbox: node.attr?("checkbox") ? !node.attr?("checked") : nil,
33
- checkedcheckbox: node.attr?("checkbox") ? node.attr?("checked") : nil,
33
+ uncheckedcheckbox: node.attr?("checkbox") ? !c : nil,
34
+ checkedcheckbox: node.attr?("checkbox") ? c : nil
34
35
  )
35
36
  end
36
37
 
37
38
  def ulist(node)
38
39
  return reference(node) if in_norm_ref? || in_biblio?
40
+
39
41
  noko do |xml|
40
42
  xml.ul **ul_attrs(node) do |xml_ul|
41
43
  node.items.each do |item|
@@ -2,10 +2,10 @@ require "asciidoctor/extensions"
2
2
  require "fileutils"
3
3
  require "uuidtools"
4
4
  require "yaml"
5
- require_relative "./macros_plantuml.rb"
6
- require_relative "./macros_terms.rb"
7
- require_relative "./datamodel/attributes_table_preprocessor.rb"
8
- require_relative "./datamodel/diagram_preprocessor.rb"
5
+ require_relative "./macros_plantuml"
6
+ require_relative "./macros_terms"
7
+ require_relative "./datamodel/attributes_table_preprocessor"
8
+ require_relative "./datamodel/diagram_preprocessor"
9
9
  require "metanorma-plugin-datastruct"
10
10
  require "metanorma-plugin-lutaml"
11
11
 
@@ -29,6 +29,7 @@ module Asciidoctor
29
29
 
30
30
  def preprocess_attrs(attrs)
31
31
  return unless attrs.size > 1 && attrs.size < 5
32
+
32
33
  ret = { primary: attrs[1], target: attrs[attrs.size] }
33
34
  ret[:secondary] = attrs[2] if attrs.size > 2
34
35
  ret[:tertiary] = attrs[3] if attrs.size > 3
@@ -37,7 +38,8 @@ module Asciidoctor
37
38
 
38
39
  def process(_parent, target, attr)
39
40
  args = preprocess_attrs(attr) or return
40
- ret = "<index-xref also='#{target == 'also'}'><primary>#{args[:primary]}</primary>"
41
+ ret = "<index-xref also='#{target == 'also'}'>"\
42
+ "<primary>#{args[:primary]}</primary>"
41
43
  ret += "<secondary>#{args[:secondary]}</secondary>" if args[:secondary]
42
44
  ret += "<tertiary>#{args[:tertiary]}</tertiary>" if args[:tertiary]
43
45
  ret + "<target>#{args[:target]}</target></index-xref>"
@@ -51,7 +53,7 @@ module Asciidoctor
51
53
 
52
54
  def process(parent, target, attr)
53
55
  text = attr["text"]
54
- text = "((#{text}))" unless /^\(\(.+\)\)$/.match(text)
56
+ text = "((#{text}))" unless /^\(\(.+\)\)$/.match?(text)
55
57
  out = parent.sub_macros(text)
56
58
  out.sub(/<index>/, "<index to='#{target}'>")
57
59
  end
@@ -62,8 +64,8 @@ module Asciidoctor
62
64
  named :pseudocode
63
65
  on_context :example, :sourcecode
64
66
 
65
- def init_indent(s)
66
- /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s
67
+ def init_indent(line)
68
+ /^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ line
67
69
  prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0")
68
70
  .gsub(/ /, "\u00a0")
69
71
  prefix + suffix
@@ -75,9 +77,10 @@ module Asciidoctor
75
77
  /^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/.match(l) &&
76
78
  (ignore = !ignore)
77
79
  next if l.empty? || l.match(/ \+$/)
78
- next if /^\[.*\]$/.match(l)
80
+ next if /^\[.*\]$/.match?(l)
79
81
  next if ignore
80
82
  next if i == lines.size - 1 || i < lines.size - 1 && lines[i + 1].empty?
83
+
81
84
  lines[i] += " +"
82
85
  end
83
86
  lines
@@ -86,9 +89,8 @@ module Asciidoctor
86
89
  def process(parent, reader, attrs)
87
90
  attrs["role"] = "pseudocode"
88
91
  lines = reader.lines.map { |m| init_indent(m) }
89
- ret = create_block(parent, :example, supply_br(lines),
90
- attrs, content_model: :compound)
91
- ret
92
+ create_block(parent, :example, supply_br(lines),
93
+ attrs, content_model: :compound)
92
94
  end
93
95
  end
94
96
 
@@ -98,6 +100,7 @@ module Asciidoctor
98
100
  parse_content_as :text
99
101
  option :pos_attrs, %w(rpbegin rt rpend)
100
102
 
103
+ # for example, html5ruby:楽聖少女[がくせいしょうじょ]
101
104
  def process(_parent, target, attributes)
102
105
  rpbegin = "("
103
106
  rpend = ")"
@@ -105,7 +108,6 @@ module Asciidoctor
105
108
  rt = attributes["text"]
106
109
  elsif (attributes.size == 2) && attributes.key?(1) &&
107
110
  attributes.key?("rpbegin")
108
- # for example, html5ruby:楽聖少女[がくせいしょうじょ]
109
111
  rt = attributes[1] || ""
110
112
  else
111
113
  rpbegin = attributes["rpbegin"]
@@ -135,6 +137,7 @@ module Asciidoctor
135
137
  def process(document)
136
138
  (document.find_by context: :paragraph).each do |para|
137
139
  next unless /^TODO: /.match para.lines[0]
140
+
138
141
  parent = para.parent
139
142
  para.set_attr("name", "todo")
140
143
  para.set_attr("caption", "TODO")
@@ -182,5 +185,29 @@ module Asciidoctor
182
185
  %{<footnoteblock>#{out}</footnoteblock>}
183
186
  end
184
187
  end
188
+
189
+ class AddMacro < Asciidoctor::Extensions::InlineMacroProcessor
190
+ use_dsl
191
+ named :add
192
+ parse_content_as :text
193
+ using_format :short
194
+
195
+ def process(parent, _target, attrs)
196
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
197
+ %{<add>#{out}</add>}
198
+ end
199
+ end
200
+
201
+ class DelMacro < Asciidoctor::Extensions::InlineMacroProcessor
202
+ use_dsl
203
+ named :del
204
+ parse_content_as :text
205
+ using_format :short
206
+
207
+ def process(parent, _target, attrs)
208
+ out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
209
+ %{<del>#{out}</del>}
210
+ end
211
+ end
185
212
  end
186
213
  end
@@ -1,12 +1,14 @@
1
+ require_relative "ref_date_id"
2
+
1
3
  module Asciidoctor
2
4
  module Standoc
3
5
  module Refs
4
- def iso_publisher(t, code)
6
+ def iso_publisher(bib, code)
5
7
  code.sub(/ .*$/, "").split(/\//).each do |abbrev|
6
- t.contributor do |c|
8
+ bib.contributor do |c|
7
9
  c.role **{ type: "publisher" }
8
10
  c.organization do |org|
9
- organization(org, abbrev)
11
+ organization(org, abbrev, true)
10
12
  end
11
13
  end
12
14
  end
@@ -20,58 +22,19 @@ module Asciidoctor
20
22
  { id: m[:anchor], type: "standard" }
21
23
  end
22
24
 
23
- def set_date_range(date, text)
24
- matched = /^(?<from>[0-9]+)(-+(?<to>[0-9]+))?$/.match text
25
- return unless matched[:from]
26
- if matched[:to]
27
- date.from matched[:from]
28
- date.to matched[:to]
29
- else
30
- date.on matched[:from]
31
- end
32
- end
33
-
34
- def use_my_anchor(ref, id)
35
- ref.parent.elements.last["id"] = id
36
- ref
37
- end
38
-
39
- def id_and_year(id, year)
40
- year ? "#{id}:#{year}" : id
41
- end
42
-
43
- def docid(t, code)
44
- type, code1 = /^\[\d+\]$|^\([^)]+\).*$/.match(code) ?
45
- ["metanorma", mn_code(code)] : @bibdb&.docid_type(code) || [nil, code]
46
- code1.sub!(/^nofetch\((.+)\)$/, "\\1")
47
- t.docidentifier **attr_code(type: type) do |d|
48
- d << code1
49
- end
50
- end
51
-
52
- def docnumber(t, code)
53
- t.docnumber do |d|
54
- d << HTMLEntities.new.decode(code).sub(/^[^\d]*/, "")
55
- end
56
- end
57
-
58
- def norm_year(yr)
59
- /^\&\#821[12];$/.match(yr) and return "--"
60
- /^\d\d\d\d-\d\d\d\d$/.match(yr) and return yr
61
- yr&.sub(/(?<=[0-9])-.*$/, "")
62
- end
63
-
64
- def isorefrender1(t, m, yr, allp = "")
65
- t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
66
- docid(t, m[:usrlbl]) if m[:usrlbl]
67
- docid(t, id_and_year(m[:code], yr) + allp)
68
- docnumber(t, m[:code])
25
+ def isorefrender1(bib, m, yr, allp = "")
26
+ bib.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
27
+ docid(bib, m[:usrlbl]) if m[:usrlbl]
28
+ docid(bib, id_and_year(m[:code], yr) + allp)
29
+ docnumber(bib, m[:code])
69
30
  end
70
31
 
71
32
  def isorefmatches(xml, m)
72
33
  yr = norm_year(m[:year])
73
- ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
34
+ ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl],
35
+ lang: (@lang || :all)
74
36
  return use_my_anchor(ref, m[:anchor]) if ref
37
+
75
38
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
76
39
  isorefrender1(t, m, yr)
77
40
  yr and t.date **{ type: "published" } do |d|
@@ -85,6 +48,7 @@ module Asciidoctor
85
48
  ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn],
86
49
  title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
87
50
  return use_my_anchor(ref, m[:anchor]) if ref
51
+
88
52
  isorefmatches2_1(xml, m)
89
53
  end
90
54
 
@@ -95,49 +59,51 @@ module Asciidoctor
95
59
  d.on "--"
96
60
  end
97
61
  iso_publisher(t, m[:code])
98
- m[:fn].nil? or t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
99
- p << "#{m[:fn]}"
62
+ unless m[:fn].nil?
63
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
64
+ p << (m[:fn]).to_s
65
+ end
100
66
  end
101
67
  end
102
68
  end
103
69
 
104
- def conditional_date(t, m, noyr)
105
- m.names.include?("year") and !m[:year].nil? and
106
- t.date(**{ type: "published" }) do |d|
107
- noyr and d.on "--" or set_date_range(d, norm_year(m[:year]))
108
- end
109
- end
110
-
111
70
  def isorefmatches3(xml, m)
112
71
  yr = norm_year(m[:year])
113
72
  hasyr = !yr.nil? && yr != "--"
114
- ref = fetch_ref xml, m[:code], hasyr ? yr : nil, all_parts: true,
115
- no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
73
+ ref = fetch_ref(xml, m[:code], hasyr ? yr : nil,
74
+ all_parts: true,
75
+ no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl],
76
+ lang: (@lang || :all))
116
77
  return use_my_anchor(ref, m[:anchor]) if ref
78
+
117
79
  isorefmatches3_1(xml, m, yr, hasyr, ref)
118
80
  end
119
81
 
120
- def isorefmatches3_1(xml, m, yr, hasyr, ref)
82
+ def isorefmatches3_1(xml, m, yr, _hasyr, _ref)
121
83
  xml.bibitem(**attr_code(ref_attributes(m))) do |t|
122
84
  isorefrender1(t, m, yr, " (all parts)")
123
85
  conditional_date(t, m, yr == "--")
124
86
  iso_publisher(t, m[:code])
125
- m.names.include?("fn") && m[:fn] and
126
- t.note(**plaintxt.merge(type: "Unpublished-Status")) { |p| p << "#{m[:fn]}" }
127
- t.extent **{ type: 'part' } do |e|
87
+ if m.names.include?("fn") && m[:fn]
88
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
89
+ p << (m[:fn]).to_s
90
+ end
91
+ end
92
+ t.extent **{ type: "part" } do |e|
128
93
  e.referenceFrom "all"
129
94
  end
130
95
  end
131
96
  end
132
97
 
133
- def refitem_render1(m, code, t)
98
+ def refitem_render1(m, code, bib)
134
99
  if code[:type] == "path"
135
- t.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
136
- t.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
100
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
101
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
137
102
  end
138
- docid(t, m[:usrlbl]) if m[:usrlbl]
139
- docid(t, /^\d+$/.match(code[:id]) ? "[#{code[:id]}]" : code[:id])
140
- code[:type] == "repo" and t.docidentifier code[:key], **{ type: "repository" }
103
+ docid(bib, m[:usrlbl]) if m[:usrlbl]
104
+ docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
105
+ code[:type] == "repo" and
106
+ bib.docidentifier code[:key], **{ type: "repository" }
141
107
  end
142
108
 
143
109
  def refitem_render(xml, m, code)
@@ -146,7 +112,7 @@ module Asciidoctor
146
112
  i << ref_normalise_no_format(m[:text])
147
113
  end
148
114
  refitem_render1(m, code, t)
149
- docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match(code[:id])
115
+ docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match?(code[:id])
150
116
  end
151
117
  end
152
118
 
@@ -156,25 +122,30 @@ module Asciidoctor
156
122
 
157
123
  def analyse_ref_nofetch(ret)
158
124
  return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
125
+
159
126
  ret.merge(id: m[:id], nofetch: true)
160
127
  end
161
128
 
162
129
  def analyse_ref_repo_path(ret)
163
- return ret unless m = /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
130
+ return ret unless m =
131
+ /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
132
+
164
133
  id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
165
134
  ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
166
135
  end
167
136
 
168
137
  def analyse_ref_numeric(ret)
169
- return ret unless /^\d+$/.match(ret[:id])
138
+ return ret unless /^\d+$/.match?(ret[:id])
139
+
170
140
  ret.merge(numeric: true)
171
141
  end
172
142
 
173
143
  # ref id = (usrlbl)code[:-]year
174
144
  # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
175
145
  def analyse_ref_code(code)
176
- ret = {id: code}
177
- return ret if code.nil? || code.empty?
146
+ ret = { id: code }
147
+ return ret if code.blank?
148
+
178
149
  analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
179
150
  end
180
151
 
@@ -185,11 +156,13 @@ module Asciidoctor
185
156
  nil
186
157
  end
187
158
 
188
- def refitem1(xml, item, m)
159
+ def refitem1(xml, _item, m)
189
160
  code = analyse_ref_code(m[:code])
190
161
  unless code[:id] && code[:numeric] || code[:nofetch]
191
- ref = fetch_ref xml, code[:id], m.names.include?("year") ? m[:year] : nil, title: m[:text],
192
- usrlbl: m[:usrlbl], lang: (@lang || :all)
162
+ ref = fetch_ref(xml, code[:id],
163
+ m.names.include?("year") ? m[:year] : nil,
164
+ title: m[:text],
165
+ usrlbl: m[:usrlbl], lang: (@lang || :all))
193
166
  return use_my_anchor(ref, m[:anchor]) if ref
194
167
  end
195
168
  refitem_render(xml, m, code)
@@ -203,44 +176,46 @@ module Asciidoctor
203
176
  ref.gsub(/&amp;amp;/, "&amp;")
204
177
  end
205
178
 
206
- ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
179
+ ISO_REF =
180
+ %r{^<ref\sid="(?<anchor>[^"]+)">
207
181
  \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
208
- (:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
182
+ (:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm.freeze
209
183
 
210
- ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
184
+ ISO_REF_NO_YEAR =
185
+ %r{^<ref\sid="(?<anchor>[^"]+)">
211
186
  \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
212
- (--|\&\#821[12]\;)\]</ref>,?\s*
187
+ (--|&\#821[12];)\]</ref>,?\s*
213
188
  (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
214
-
215
- ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
216
- \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
217
- (:(?<year>--|\&\#821[12]\;|[0-9][0-9-]+))?\s
218
- \(all\sparts\)\]</ref>,?\s*
219
- (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
220
-
221
- NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
222
- \[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
223
- ([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
224
-
225
- def reference1_matches(item)
226
- matched = ISO_REF.match item
227
- matched2 = ISO_REF_NO_YEAR.match item
228
- matched3 = ISO_REF_ALL_PARTS.match item
229
- [matched, matched2, matched3]
230
- end
231
-
232
- def reference1(node, item, xml)
233
- matched, matched2, matched3 = reference1_matches(item)
234
- if matched3.nil? && matched2.nil? && matched.nil? then refitem(xml, item, node)
235
- elsif !matched.nil? then isorefmatches(xml, matched)
236
- elsif !matched2.nil? then isorefmatches2(xml, matched2)
237
- elsif !matched3.nil? then isorefmatches3(xml, matched3)
238
- end
239
- end
240
-
241
- def mn_code(code)
242
- code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
189
+ .freeze
190
+
191
+ ISO_REF_ALL_PARTS =
192
+ %r{^<ref\sid="(?<anchor>[^"]+)">
193
+ \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
194
+ (:(?<year>--|&\#821[12];|[0-9][0-9-]+))?\s
195
+ \(all\sparts\)\]</ref>,?\s*
196
+ (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm.freeze
197
+
198
+ NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
199
+ \[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
200
+ ([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
201
+ .freeze
202
+
203
+ def reference1_matches(item)
204
+ matched = ISO_REF.match item
205
+ matched2 = ISO_REF_NO_YEAR.match item
206
+ matched3 = ISO_REF_ALL_PARTS.match item
207
+ [matched, matched2, matched3]
208
+ end
209
+
210
+ def reference1(node, item, xml)
211
+ matched, matched2, matched3 = reference1_matches(item)
212
+ if matched3.nil? && matched2.nil? && matched.nil?
213
+ refitem(xml, item, node)
214
+ elsif !matched.nil? then isorefmatches(xml, matched)
215
+ elsif !matched2.nil? then isorefmatches2(xml, matched2)
216
+ elsif !matched3.nil? then isorefmatches3(xml, matched3)
243
217
  end
218
+ end
244
219
  end
245
220
  end
246
221
  end