metanorma-standoc 1.8.8 → 1.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +3 -13
- data/.hound.yml +3 -1
- data/.rubocop.yml +3 -7
- data/Gemfile.devel +0 -0
- data/lib/asciidoctor/standoc/base.rb +42 -36
- data/lib/asciidoctor/standoc/biblio.rng +1 -0
- data/lib/asciidoctor/standoc/blocks.rb +25 -9
- data/lib/asciidoctor/standoc/blocks_notes.rb +41 -24
- data/lib/asciidoctor/standoc/cleanup.rb +59 -84
- data/lib/asciidoctor/standoc/cleanup_block.rb +63 -85
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +51 -29
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_image.rb +71 -0
- data/lib/asciidoctor/standoc/cleanup_maths.rb +36 -27
- data/lib/asciidoctor/standoc/cleanup_ref.rb +24 -15
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +47 -0
- data/lib/asciidoctor/standoc/cleanup_section.rb +77 -134
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +75 -0
- data/lib/asciidoctor/standoc/converter.rb +10 -3
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +67 -66
- data/lib/asciidoctor/standoc/front.rb +35 -18
- data/lib/asciidoctor/standoc/front_contributor.rb +70 -45
- data/lib/asciidoctor/standoc/inline.rb +30 -22
- data/lib/asciidoctor/standoc/isodoc.rng +321 -4
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +50 -23
- data/lib/asciidoctor/standoc/macros_form.rb +63 -0
- data/lib/asciidoctor/standoc/ref.rb +87 -112
- data/lib/asciidoctor/standoc/ref_date_id.rb +62 -0
- data/lib/asciidoctor/standoc/ref_sect.rb +20 -17
- data/lib/asciidoctor/standoc/section.rb +3 -1
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +31 -16
- data/lib/asciidoctor/standoc/terms.rb +27 -16
- data/lib/asciidoctor/standoc/utils.rb +35 -9
- data/lib/asciidoctor/standoc/validate.rb +30 -28
- data/lib/metanorma-standoc.rb +0 -1
- data/lib/metanorma/standoc/version.rb +5 -5
- data/metanorma-standoc.gemspec +11 -11
- data/spec/asciidoctor/base_spec.rb +715 -509
- data/spec/asciidoctor/blocks_spec.rb +830 -727
- data/spec/asciidoctor/cleanup_sections_spec.rb +51 -14
- data/spec/asciidoctor/cleanup_spec.rb +1836 -1673
- data/spec/asciidoctor/inline_spec.rb +330 -283
- data/spec/asciidoctor/isobib_cache_spec.rb +406 -358
- data/spec/asciidoctor/lists_spec.rb +3 -3
- data/spec/asciidoctor/macros_plantuml_spec.rb +8 -8
- data/spec/asciidoctor/macros_spec.rb +546 -444
- data/spec/asciidoctor/macros_yaml2text_spec.rb +1 -1
- data/spec/asciidoctor/refs_dl_spec.rb +4 -4
- data/spec/asciidoctor/refs_spec.rb +1528 -1533
- data/spec/asciidoctor/section_spec.rb +778 -689
- data/spec/asciidoctor/table_spec.rb +6 -6
- data/spec/asciidoctor/validate_spec.rb +296 -304
- data/spec/spec_helper.rb +13 -9
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +66 -66
- data/spec/vcr_cassettes/isobib_get_123.yml +17 -17
- data/spec/vcr_cassettes/isobib_get_123_1.yml +31 -31
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +40 -40
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +17 -17
- data/spec/vcr_cassettes/isobib_get_124.yml +16 -16
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +78 -66
- metadata +69 -67
- data/lib/liquid/custom_blocks/key_iterator.rb +0 -21
- data/lib/liquid/custom_blocks/with_json_nested_context.rb +0 -18
- data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +0 -19
- data/lib/liquid/custom_filters/values.rb +0 -7
@@ -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") ? !
|
33
|
-
checkedcheckbox: node.attr?("checkbox") ?
|
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,11 @@ require "asciidoctor/extensions"
|
|
2
2
|
require "fileutils"
|
3
3
|
require "uuidtools"
|
4
4
|
require "yaml"
|
5
|
-
require_relative "./macros_plantuml
|
6
|
-
require_relative "./macros_terms
|
7
|
-
require_relative "./
|
8
|
-
require_relative "./datamodel/
|
5
|
+
require_relative "./macros_plantuml"
|
6
|
+
require_relative "./macros_terms"
|
7
|
+
require_relative "./macros_form"
|
8
|
+
require_relative "./datamodel/attributes_table_preprocessor"
|
9
|
+
require_relative "./datamodel/diagram_preprocessor"
|
9
10
|
require "metanorma-plugin-datastruct"
|
10
11
|
require "metanorma-plugin-lutaml"
|
11
12
|
|
@@ -29,6 +30,7 @@ module Asciidoctor
|
|
29
30
|
|
30
31
|
def preprocess_attrs(attrs)
|
31
32
|
return unless attrs.size > 1 && attrs.size < 5
|
33
|
+
|
32
34
|
ret = { primary: attrs[1], target: attrs[attrs.size] }
|
33
35
|
ret[:secondary] = attrs[2] if attrs.size > 2
|
34
36
|
ret[:tertiary] = attrs[3] if attrs.size > 3
|
@@ -37,7 +39,8 @@ module Asciidoctor
|
|
37
39
|
|
38
40
|
def process(_parent, target, attr)
|
39
41
|
args = preprocess_attrs(attr) or return
|
40
|
-
ret = "<index-xref also='#{target == 'also'}'
|
42
|
+
ret = "<index-xref also='#{target == 'also'}'>"\
|
43
|
+
"<primary>#{args[:primary]}</primary>"
|
41
44
|
ret += "<secondary>#{args[:secondary]}</secondary>" if args[:secondary]
|
42
45
|
ret += "<tertiary>#{args[:tertiary]}</tertiary>" if args[:tertiary]
|
43
46
|
ret + "<target>#{args[:target]}</target></index-xref>"
|
@@ -51,7 +54,7 @@ module Asciidoctor
|
|
51
54
|
|
52
55
|
def process(parent, target, attr)
|
53
56
|
text = attr["text"]
|
54
|
-
text = "((#{text}))" unless /^\(\(.+\)\)$/.match(text)
|
57
|
+
text = "((#{text}))" unless /^\(\(.+\)\)$/.match?(text)
|
55
58
|
out = parent.sub_macros(text)
|
56
59
|
out.sub(/<index>/, "<index to='#{target}'>")
|
57
60
|
end
|
@@ -62,8 +65,8 @@ module Asciidoctor
|
|
62
65
|
named :pseudocode
|
63
66
|
on_context :example, :sourcecode
|
64
67
|
|
65
|
-
def init_indent(
|
66
|
-
/^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~
|
68
|
+
def init_indent(line)
|
69
|
+
/^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ line
|
67
70
|
prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0")
|
68
71
|
.gsub(/ /, "\u00a0")
|
69
72
|
prefix + suffix
|
@@ -72,12 +75,12 @@ module Asciidoctor
|
|
72
75
|
def supply_br(lines)
|
73
76
|
ignore = false
|
74
77
|
lines.each_with_index do |l, i|
|
75
|
-
/^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)
|
76
|
-
(ignore = !ignore)
|
77
|
-
next if l.empty? || l.match(/ \+$/)
|
78
|
-
next if
|
79
|
-
|
80
|
-
|
78
|
+
/^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/
|
79
|
+
.match(l) && (ignore = !ignore)
|
80
|
+
next if l.empty? || l.match(/ \+$/) || /^\[.*\]$/.match?(l) || ignore
|
81
|
+
next if i == lines.size - 1 ||
|
82
|
+
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
|
-
|
90
|
-
|
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"]
|
@@ -126,21 +128,22 @@ module Asciidoctor
|
|
126
128
|
def process(parent, reader, attrs)
|
127
129
|
attrs["name"] = "todo"
|
128
130
|
attrs["caption"] = "TODO"
|
129
|
-
create_block
|
130
|
-
|
131
|
+
create_block(parent, :admonition, reader.lines, attrs,
|
132
|
+
content_model: :compound)
|
131
133
|
end
|
132
134
|
end
|
133
135
|
|
134
136
|
class ToDoInlineAdmonitionBlock < Extensions::Treeprocessor
|
135
137
|
def process(document)
|
136
138
|
(document.find_by context: :paragraph).each do |para|
|
137
|
-
next unless /^TODO: /.match para.lines[0]
|
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")
|
141
144
|
para.lines[0].sub!(/^TODO: /, "")
|
142
|
-
todo = Block.new
|
143
|
-
|
145
|
+
todo = Block.new(parent, :admonition, attributes: para.attributes,
|
146
|
+
source: para.lines, content_model: :compound)
|
144
147
|
parent.blocks[parent.blocks.index(para)] = todo
|
145
148
|
end
|
146
149
|
end
|
@@ -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
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
3
|
+
class FormInputMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
4
|
+
use_dsl
|
5
|
+
named :input
|
6
|
+
|
7
|
+
def process(_parent, target, attr)
|
8
|
+
m = %w(id name value disabled readonly checked maxlength minlength)
|
9
|
+
.map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
|
10
|
+
%{<input type='#{target}' #{m.join}/>}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class FormLabelMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
15
|
+
use_dsl
|
16
|
+
named :label
|
17
|
+
parse_content_as :text
|
18
|
+
|
19
|
+
def process(parent, target, attr)
|
20
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
|
21
|
+
%{<label for="#{target}">#{out}</label>}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class FormTextareaMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
26
|
+
use_dsl
|
27
|
+
named :textarea
|
28
|
+
using_format :short
|
29
|
+
|
30
|
+
def process(_parent, _target, attr)
|
31
|
+
m = %w(id name rows cols value)
|
32
|
+
.map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
|
33
|
+
%{<textarea #{m.join}/>}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class FormSelectMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
38
|
+
use_dsl
|
39
|
+
named :select
|
40
|
+
using_format :short
|
41
|
+
|
42
|
+
def process(parent, _target, attr)
|
43
|
+
m = %w(id name size disabled multiple value)
|
44
|
+
.map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
|
45
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
|
46
|
+
%{<select #{m.join}>#{out}</select>}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class FormOptionMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
51
|
+
use_dsl
|
52
|
+
named :option
|
53
|
+
using_format :short
|
54
|
+
|
55
|
+
def process(parent, _target, attr)
|
56
|
+
m = %w(disabled value)
|
57
|
+
.map { |a| attr[a] ? " #{a}='#{attr[a]}'" : nil }.compact
|
58
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attr["text"]).convert
|
59
|
+
%{<option #{m.join}">#{out}</option>}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
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(
|
6
|
+
def iso_publisher(bib, code)
|
5
7
|
code.sub(/ .*$/, "").split(/\//).each do |abbrev|
|
6
|
-
|
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
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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],
|
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?
|
99
|
-
|
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
|
115
|
-
|
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,
|
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]
|
126
|
-
t.note(**plaintxt.merge(type: "Unpublished-Status"))
|
127
|
-
|
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,
|
98
|
+
def refitem_render1(m, code, bib)
|
134
99
|
if code[:type] == "path"
|
135
|
-
|
136
|
-
|
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(
|
139
|
-
docid(
|
140
|
-
code[:type] == "repo" and
|
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 =
|
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.
|
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,
|
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
|
192
|
-
|
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;/, "&")
|
204
177
|
end
|
205
178
|
|
206
|
-
ISO_REF =
|
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
|
-
|
184
|
+
ISO_REF_NO_YEAR =
|
185
|
+
%r{^<ref\sid="(?<anchor>[^"]+)">
|
211
186
|
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
|
212
|
-
(
|
187
|
+
(--|&\#821[12];)\]</ref>,?\s*
|
213
188
|
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
(
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
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
|