metanorma-standoc 1.6.0 → 1.6.5
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 +66 -0
- data/README.adoc +1 -3
- data/lib/asciidoctor/standoc/base.rb +8 -16
- data/lib/asciidoctor/standoc/basicdoc.rng +32 -0
- data/lib/asciidoctor/standoc/cleanup.rb +52 -4
- data/lib/asciidoctor/standoc/cleanup_block.rb +41 -4
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +14 -0
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +25 -0
- data/lib/asciidoctor/standoc/cleanup_inline.rb +6 -2
- data/lib/asciidoctor/standoc/cleanup_ref.rb +18 -25
- data/lib/asciidoctor/standoc/cleanup_terms.rb +3 -0
- data/lib/asciidoctor/standoc/converter.rb +61 -3
- data/lib/asciidoctor/standoc/front.rb +9 -3
- data/lib/asciidoctor/standoc/front_contributor.rb +34 -10
- data/lib/asciidoctor/standoc/isodoc.rng +29 -44
- data/lib/asciidoctor/standoc/lists.rb +4 -2
- data/lib/asciidoctor/standoc/macros.rb +45 -63
- data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
- data/lib/asciidoctor/standoc/ref.rb +24 -36
- data/lib/asciidoctor/standoc/ref_sect.rb +16 -8
- data/lib/asciidoctor/standoc/section.rb +5 -9
- data/lib/asciidoctor/standoc/table.rb +12 -0
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
- data/lib/liquid/custom_blocks/with_json_nested_context.rb +18 -0
- data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +19 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +6 -3
- data/spec/asciidoctor-standoc/base_spec.rb +127 -8
- data/spec/asciidoctor-standoc/blocks_spec.rb +8 -8
- data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +1514 -0
- data/spec/asciidoctor-standoc/cleanup_spec.rb +450 -1554
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +22 -31
- data/spec/asciidoctor-standoc/lists_spec.rb +10 -1
- data/spec/asciidoctor-standoc/macros_json2text_spec.rb +1 -1
- data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +80 -0
- data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
- data/spec/asciidoctor-standoc/macros_spec.rb +378 -169
- data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +1 -1
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +8 -8
- data/spec/asciidoctor-standoc/refs_spec.rb +350 -101
- data/spec/asciidoctor-standoc/section_spec.rb +11 -11
- data/spec/asciidoctor-standoc/table_spec.rb +86 -0
- data/spec/asciidoctor-standoc/validate_spec.rb +26 -0
- data/spec/fixtures/diagram_definitions.lutaml +22 -0
- data/spec/fixtures/test.exp +121 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +156 -4
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -233
- data/spec/vcr_cassettes/isobib_get_123.yml +12 -58
- data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -119
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +361 -0
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -58
- data/spec/vcr_cassettes/isobib_get_124.yml +11 -57
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +276 -158
- metadata +61 -14
- data/.github/workflows/macos.yml +0 -41
- data/.github/workflows/ubuntu.yml +0 -45
- data/.github/workflows/windows.yml +0 -43
- data/lib/asciidoctor/standoc/base_structured_text_preprocessor.rb +0 -123
- data/lib/asciidoctor/standoc/json2_text_preprocessor.rb +0 -44
- data/lib/asciidoctor/standoc/yaml2_text_preprocessor.rb +0 -46
@@ -55,7 +55,7 @@ module Asciidoctor
|
|
55
55
|
|
56
56
|
def ol_attrs(node)
|
57
57
|
attr_code(keep_attrs(node).merge(id: Utils::anchor_or_uuid(node),
|
58
|
-
|
58
|
+
type: olist_style(node.style)))
|
59
59
|
end
|
60
60
|
|
61
61
|
def olist(node)
|
@@ -87,7 +87,9 @@ module Asciidoctor
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def dl_attrs(node)
|
90
|
-
attr_code(
|
90
|
+
attr_code(keep_attrs(node).
|
91
|
+
merge(id: Utils::anchor_or_uuid(node),
|
92
|
+
key: node.option?("key") ? "true" : nil))
|
91
93
|
end
|
92
94
|
|
93
95
|
def dlist(node)
|
@@ -3,49 +3,14 @@ require "fileutils"
|
|
3
3
|
require "uuidtools"
|
4
4
|
require "yaml"
|
5
5
|
require_relative "./macros_plantuml.rb"
|
6
|
+
require_relative "./macros_terms.rb"
|
6
7
|
require_relative "./datamodel/attributes_table_preprocessor.rb"
|
7
8
|
require_relative "./datamodel/diagram_preprocessor.rb"
|
8
|
-
|
9
|
-
|
9
|
+
require "metanorma-plugin-datastruct"
|
10
|
+
require "metanorma-plugin-lutaml"
|
10
11
|
|
11
12
|
module Asciidoctor
|
12
13
|
module Standoc
|
13
|
-
class AltTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
14
|
-
use_dsl
|
15
|
-
named :alt
|
16
|
-
parse_content_as :text
|
17
|
-
using_format :short
|
18
|
-
|
19
|
-
def process(parent, _target, attrs)
|
20
|
-
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
21
|
-
%{<admitted>#{out}</admitted>}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class DeprecatedTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
26
|
-
use_dsl
|
27
|
-
named :deprecated
|
28
|
-
parse_content_as :text
|
29
|
-
using_format :short
|
30
|
-
|
31
|
-
def process(parent, _target, attrs)
|
32
|
-
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
33
|
-
%{<deprecates>#{out}</deprecates>}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class DomainTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
38
|
-
use_dsl
|
39
|
-
named :domain
|
40
|
-
parse_content_as :text
|
41
|
-
using_format :short
|
42
|
-
|
43
|
-
def process(parent, _target, attrs)
|
44
|
-
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
45
|
-
%{<domain>#{out}</domain>}
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
14
|
class InheritInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
50
15
|
use_dsl
|
51
16
|
named :inherit
|
@@ -58,33 +23,24 @@ module Asciidoctor
|
|
58
23
|
end
|
59
24
|
end
|
60
25
|
|
61
|
-
class
|
26
|
+
class IndexInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
62
27
|
use_dsl
|
63
|
-
named :
|
64
|
-
name_positional_attributes "id", "word", "term"
|
65
|
-
# match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
|
66
|
-
match /\{\{(?<content>|.*?[^\\])\}\}/
|
67
|
-
using_format :short
|
28
|
+
named :index
|
68
29
|
|
69
|
-
# deal with locality attrs and their disruption of positional attrs
|
70
30
|
def preprocess_attrs(attrs)
|
71
|
-
attrs.
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
attrs
|
31
|
+
return unless attrs.size > 1 && attrs.size < 5
|
32
|
+
ret = { primary: attrs[1], target: attrs[attrs.size] }
|
33
|
+
ret[:secondary] = attrs[2] if attrs.size > 2
|
34
|
+
ret[:tertiary] = attrs[3] if attrs.size > 3
|
35
|
+
ret
|
77
36
|
end
|
78
37
|
|
79
|
-
def process(
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
join(",")
|
86
|
-
out = Asciidoctor::Inline.new(parent, :quoted, text).convert
|
87
|
-
%{<concept key="#{attr['id']}" term="#{attr['term']}">#{out}</concept>}
|
38
|
+
def process(_parent, target, attr)
|
39
|
+
args = preprocess_attrs(attr) or return
|
40
|
+
ret = "<index-xref also='#{target == 'also'}'><primary>#{args[:primary]}</primary>"
|
41
|
+
ret += "<secondary>#{args[:secondary]}</secondary>" if args[:secondary]
|
42
|
+
ret += "<tertiary>#{args[:tertiary]}</tertiary>" if args[:tertiary]
|
43
|
+
ret + "<target>#{args[:target]}</target></index-xref>"
|
88
44
|
end
|
89
45
|
end
|
90
46
|
|
@@ -135,7 +91,7 @@ module Asciidoctor
|
|
135
91
|
if (attributes.size == 1) && attributes.key?("text")
|
136
92
|
rt = attributes["text"]
|
137
93
|
elsif (attributes.size == 2) && attributes.key?(1) &&
|
138
|
-
|
94
|
+
attributes.key?("rpbegin")
|
139
95
|
# for example, html5ruby:楽聖少女[がくせいしょうじょ]
|
140
96
|
rt = attributes[1] || ""
|
141
97
|
else
|
@@ -158,7 +114,7 @@ module Asciidoctor
|
|
158
114
|
attrs["name"] = "todo"
|
159
115
|
attrs["caption"] = "TODO"
|
160
116
|
create_block parent, :admonition, reader.lines, attrs,
|
161
|
-
|
117
|
+
content_model: :compound
|
162
118
|
end
|
163
119
|
end
|
164
120
|
|
@@ -171,7 +127,7 @@ module Asciidoctor
|
|
171
127
|
para.set_attr("caption", "TODO")
|
172
128
|
para.lines[0].sub!(/^TODO: /, "")
|
173
129
|
todo = Block.new parent, :admonition, attributes: para.attributes,
|
174
|
-
|
130
|
+
source: para.lines, content_model: :compound
|
175
131
|
parent.blocks[parent.blocks.index(para)] = todo
|
176
132
|
end
|
177
133
|
end
|
@@ -187,5 +143,31 @@ module Asciidoctor
|
|
187
143
|
%{<autonumber type=#{target}>#{out}</autonumber>}
|
188
144
|
end
|
189
145
|
end
|
146
|
+
|
147
|
+
class VariantInlineMacro < Extensions::InlineMacroProcessor
|
148
|
+
use_dsl
|
149
|
+
named :lang
|
150
|
+
parse_content_as :text
|
151
|
+
|
152
|
+
def process(parent, target, attrs)
|
153
|
+
/^(?<lang>[^-]*)(-(?<script>.*))?$/ =~ target
|
154
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
155
|
+
script ?
|
156
|
+
%{<variant lang=#{lang} script=#{script}>#{out}</variant>} :
|
157
|
+
%{<variant lang=#{lang}>#{out}</variant>}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
class FootnoteBlockInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
162
|
+
use_dsl
|
163
|
+
named :footnoteblock
|
164
|
+
parse_content_as :text
|
165
|
+
using_format :short
|
166
|
+
|
167
|
+
def process(parent, _target, attrs)
|
168
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
169
|
+
%{<footnoteblock>#{out}</footnoteblock>}
|
170
|
+
end
|
171
|
+
end
|
190
172
|
end
|
191
173
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
3
|
+
class AltTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
4
|
+
use_dsl
|
5
|
+
named :alt
|
6
|
+
parse_content_as :text
|
7
|
+
using_format :short
|
8
|
+
|
9
|
+
def process(parent, _target, attrs)
|
10
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
11
|
+
%{<admitted>#{out}</admitted>}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class DeprecatedTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
16
|
+
use_dsl
|
17
|
+
named :deprecated
|
18
|
+
parse_content_as :text
|
19
|
+
using_format :short
|
20
|
+
|
21
|
+
def process(parent, _target, attrs)
|
22
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
23
|
+
%{<deprecates>#{out}</deprecates>}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class DomainTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
28
|
+
use_dsl
|
29
|
+
named :domain
|
30
|
+
parse_content_as :text
|
31
|
+
using_format :short
|
32
|
+
|
33
|
+
def process(parent, _target, attrs)
|
34
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
35
|
+
%{<domain>#{out}</domain>}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Macro to transform `term[X,Y]` into em, termxref xml
|
40
|
+
class TermRefInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
41
|
+
use_dsl
|
42
|
+
named :term
|
43
|
+
name_positional_attributes 'name', 'termxref'
|
44
|
+
using_format :short
|
45
|
+
|
46
|
+
def process(_parent, _target, attrs)
|
47
|
+
termref = attrs['termxref'] || attrs['name']
|
48
|
+
"<em>#{attrs['name']}</em> (<termxref>#{termref}</termxref>)"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ConceptInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
53
|
+
use_dsl
|
54
|
+
named :concept
|
55
|
+
name_positional_attributes "id", "word", "term"
|
56
|
+
# match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
|
57
|
+
match /\{\{(?<content>|.*?[^\\])\}\}/
|
58
|
+
using_format :short
|
59
|
+
|
60
|
+
# deal with locality attrs and their disruption of positional attrs
|
61
|
+
def preprocess_attrs(attrs)
|
62
|
+
attrs.delete("term") if attrs["term"] && !attrs["word"]
|
63
|
+
attrs.delete(3) if attrs[3] == attrs["term"]
|
64
|
+
a = attrs.keys.reject { |k| k.is_a?(String) || [1, 2].include?(k) }
|
65
|
+
attrs["word"] ||= attrs[a[0]] if !a.empty?
|
66
|
+
attrs["term"] ||= attrs[a[1]] if a.length > 1
|
67
|
+
attrs
|
68
|
+
end
|
69
|
+
|
70
|
+
def process(parent, _target, attr)
|
71
|
+
attr = preprocess_attrs(attr)
|
72
|
+
localities = attr.keys.reject { |k| %w(id word term).include? k }.
|
73
|
+
reject { |k| k.is_a? Numeric }.
|
74
|
+
map { |k| "#{k}=#{attr[k]}" }.join(",")
|
75
|
+
text = [localities, attr["word"]].reject{ |k| k.nil? || k.empty? }.
|
76
|
+
join(",")
|
77
|
+
out = Asciidoctor::Inline.new(parent, :quoted, text).convert
|
78
|
+
%{<concept key="#{attr['id']}" term="#{attr['term']}">#{out}</concept>}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Asciidoctor
|
2
2
|
module Standoc
|
3
|
-
module
|
3
|
+
module Refs
|
4
4
|
def iso_publisher(t, code)
|
5
5
|
code.sub(/ .*$/, "").split(/\//).each do |abbrev|
|
6
6
|
t.contributor do |c|
|
@@ -56,7 +56,9 @@ module Asciidoctor
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def norm_year(yr)
|
59
|
-
/^\&\#821[12];$/.match(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])-.*$/, "")
|
60
62
|
end
|
61
63
|
|
62
64
|
def isorefrender1(t, m, yr, allp = "")
|
@@ -68,7 +70,7 @@ module Asciidoctor
|
|
68
70
|
|
69
71
|
def isorefmatches(xml, m)
|
70
72
|
yr = norm_year(m[:year])
|
71
|
-
ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl]
|
73
|
+
ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
|
72
74
|
return use_my_anchor(ref, m[:anchor]) if ref
|
73
75
|
xml.bibitem **attr_code(ref_attributes(m)) do |t|
|
74
76
|
isorefrender1(t, m, yr)
|
@@ -81,7 +83,7 @@ module Asciidoctor
|
|
81
83
|
|
82
84
|
def isorefmatches2(xml, m)
|
83
85
|
ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn],
|
84
|
-
title: m[:text], usrlbl: m[:usrlbl]
|
86
|
+
title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
|
85
87
|
return use_my_anchor(ref, m[:anchor]) if ref
|
86
88
|
isorefmatches2_1(xml, m)
|
87
89
|
end
|
@@ -93,7 +95,7 @@ module Asciidoctor
|
|
93
95
|
d.on "--"
|
94
96
|
end
|
95
97
|
iso_publisher(t, m[:code])
|
96
|
-
m[:fn].nil? or t.note(**plaintxt.merge(type: "
|
98
|
+
m[:fn].nil? or t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
|
97
99
|
p << "#{m[:fn]}"
|
98
100
|
end
|
99
101
|
end
|
@@ -102,8 +104,7 @@ module Asciidoctor
|
|
102
104
|
def conditional_date(t, m, noyr)
|
103
105
|
m.names.include?("year") and !m[:year].nil? and
|
104
106
|
t.date(**{ type: "published" }) do |d|
|
105
|
-
noyr and d.on "--" or
|
106
|
-
set_date_range(d, norm_year(m[:year]))
|
107
|
+
noyr and d.on "--" or set_date_range(d, norm_year(m[:year]))
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
@@ -111,7 +112,7 @@ module Asciidoctor
|
|
111
112
|
yr = norm_year(m[:year])
|
112
113
|
hasyr = !yr.nil? && yr != "--"
|
113
114
|
ref = fetch_ref xml, m[:code], hasyr ? yr : nil, all_parts: true,
|
114
|
-
no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl]
|
115
|
+
no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
|
115
116
|
return use_my_anchor(ref, m[:anchor]) if ref
|
116
117
|
isorefmatches3_1(xml, m, yr, hasyr, ref)
|
117
118
|
end
|
@@ -122,7 +123,7 @@ module Asciidoctor
|
|
122
123
|
conditional_date(t, m, yr == "--")
|
123
124
|
iso_publisher(t, m[:code])
|
124
125
|
m.names.include?("fn") && m[:fn] and
|
125
|
-
t.note(**plaintxt.merge(type: "
|
126
|
+
t.note(**plaintxt.merge(type: "Unpublished-Status")) { |p| p << "#{m[:fn]}" }
|
126
127
|
t.extent **{ type: 'part' } do |e|
|
127
128
|
e.referenceFrom "all"
|
128
129
|
end
|
@@ -136,8 +137,7 @@ module Asciidoctor
|
|
136
137
|
end
|
137
138
|
docid(t, m[:usrlbl]) if m[:usrlbl]
|
138
139
|
docid(t, /^\d+$/.match(code[:id]) ? "[#{code[:id]}]" : code[:id])
|
139
|
-
code[:type] == "repo" and
|
140
|
-
t.docidentifier code[:key], **{ type: "repository" }
|
140
|
+
code[:type] == "repo" and t.docidentifier code[:key], **{ type: "repository" }
|
141
141
|
end
|
142
142
|
|
143
143
|
def refitem_render(xml, m, code)
|
@@ -151,9 +151,8 @@ module Asciidoctor
|
|
151
151
|
end
|
152
152
|
|
153
153
|
MALFORMED_REF = "no anchor on reference, markup may be malformed: see "\
|
154
|
-
"https://www.metanorma.com/author/topics/document-format/"\
|
155
|
-
"
|
156
|
-
"#bibliographies".freeze
|
154
|
+
"https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
|
155
|
+
"https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
|
157
156
|
|
158
157
|
def analyse_ref_nofetch(ret)
|
159
158
|
return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
|
@@ -161,9 +160,9 @@ module Asciidoctor
|
|
161
160
|
end
|
162
161
|
|
163
162
|
def analyse_ref_repo_path(ret)
|
164
|
-
return ret unless m =
|
165
|
-
|
166
|
-
ret.merge(id:
|
163
|
+
return ret unless m = /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
|
164
|
+
id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
|
165
|
+
ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
|
167
166
|
end
|
168
167
|
|
169
168
|
def analyse_ref_numeric(ret)
|
@@ -181,19 +180,16 @@ module Asciidoctor
|
|
181
180
|
|
182
181
|
# TODO: alternative where only title is available
|
183
182
|
def refitem(xml, item, node)
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
end
|
188
|
-
refitem1(xml, item, m)
|
183
|
+
m = NON_ISO_REF.match(item) and return refitem1(xml, item, m)
|
184
|
+
@log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
|
185
|
+
nil
|
189
186
|
end
|
190
187
|
|
191
188
|
def refitem1(xml, item, m)
|
192
189
|
code = analyse_ref_code(m[:code])
|
193
190
|
unless code[:id] && code[:numeric] || code[:nofetch]
|
194
|
-
ref = fetch_ref xml, code[:id],
|
195
|
-
|
196
|
-
usrlbl: m[:usrlbl]
|
191
|
+
ref = fetch_ref xml, code[:id], m.names.include?("year") ? m[:year] : nil, title: m[:text],
|
192
|
+
usrlbl: m[:usrlbl], lang: (@lang || :all)
|
197
193
|
return use_my_anchor(ref, m[:anchor]) if ref
|
198
194
|
end
|
199
195
|
refitem_render(xml, m, code)
|
@@ -209,8 +205,7 @@ module Asciidoctor
|
|
209
205
|
|
210
206
|
ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
211
207
|
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
|
212
|
-
(:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*
|
213
|
-
(?<text>.*)$}xm
|
208
|
+
(:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
|
214
209
|
|
215
210
|
ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
|
216
211
|
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
|
@@ -225,7 +220,7 @@ module Asciidoctor
|
|
225
220
|
|
226
221
|
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
227
222
|
\[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
|
228
|
-
([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s*(?<text>.*)$}xm
|
223
|
+
([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
|
229
224
|
|
230
225
|
def reference1_matches(item)
|
231
226
|
matched = ISO_REF.match item
|
@@ -236,20 +231,13 @@ module Asciidoctor
|
|
236
231
|
|
237
232
|
def reference1(node, item, xml)
|
238
233
|
matched, matched2, matched3 = reference1_matches(item)
|
239
|
-
if matched3.nil? && matched2.nil? && matched.nil?
|
240
|
-
refitem(xml, item, node)
|
234
|
+
if matched3.nil? && matched2.nil? && matched.nil? then refitem(xml, item, node)
|
241
235
|
elsif !matched.nil? then isorefmatches(xml, matched)
|
242
236
|
elsif !matched2.nil? then isorefmatches2(xml, matched2)
|
243
237
|
elsif !matched3.nil? then isorefmatches3(xml, matched3)
|
244
238
|
end
|
245
239
|
end
|
246
240
|
|
247
|
-
def reference(node)
|
248
|
-
noko do |xml|
|
249
|
-
node.items.each { |item| reference1(node, item.text, xml) }
|
250
|
-
end.join
|
251
|
-
end
|
252
|
-
|
253
241
|
def mn_code(code)
|
254
242
|
code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
|
255
243
|
end
|
@@ -9,14 +9,20 @@ module Asciidoctor
|
|
9
9
|
@norm_ref
|
10
10
|
end
|
11
11
|
|
12
|
+
def reference(node)
|
13
|
+
noko do |xml|
|
14
|
+
node.items.each { |item| reference1(node, item.text, xml) }
|
15
|
+
end.join
|
16
|
+
end
|
17
|
+
|
12
18
|
def bibliography_parse(attrs, xml, node)
|
13
19
|
node.option? "bibitem" and return bibitem_parse(attrs, xml, node)
|
14
20
|
node.attr("style") == "bibliography" or
|
15
21
|
@log.add("AsciiDoc Input", node, "Section not marked up as [bibliography]!")
|
16
22
|
@biblio = true
|
17
23
|
xml.references **attr_code(attrs.merge(normative: false)) do |xml_section|
|
18
|
-
title = node.level == 1 ? "Bibliography" : node.title
|
19
|
-
xml_section.title { |t| t << title }
|
24
|
+
#title = node.level == 1 ? "Bibliography" : node.title
|
25
|
+
xml_section.title { |t| t << node.title }
|
20
26
|
xml_section << node.content
|
21
27
|
end
|
22
28
|
@biblio = false
|
@@ -38,7 +44,8 @@ module Asciidoctor
|
|
38
44
|
@log.add("AsciiDoc Input", node, "Section not marked up as [bibliography]!")
|
39
45
|
@norm_ref = true
|
40
46
|
xml.references **attr_code(attrs.merge(normative: true)) do |xml_section|
|
41
|
-
xml_section.title { |t| t << "Normative References" }
|
47
|
+
#xml_section.title { |t| t << "Normative References" }
|
48
|
+
xml_section.title { |t| t << node.title }
|
42
49
|
xml_section << node.content
|
43
50
|
end
|
44
51
|
@norm_ref = false
|
@@ -58,10 +65,10 @@ module Asciidoctor
|
|
58
65
|
def fetch_ref(xml, code, year, **opts)
|
59
66
|
return nil if opts[:no_year]
|
60
67
|
code = code.sub(/^\([^)]+\)/, "")
|
68
|
+
#require "byebug"; byebug if opts[:lang] == "fr"
|
61
69
|
hit = @bibdb&.fetch(code, year, opts)
|
62
70
|
return nil if hit.nil?
|
63
|
-
xml.parent.add_child(smart_render_xml(hit, code, opts
|
64
|
-
opts[:usrlbl]))
|
71
|
+
xml.parent.add_child(smart_render_xml(hit, code, opts))
|
65
72
|
xml
|
66
73
|
rescue RelatonBib::RequestError
|
67
74
|
@log.add("Bibliography", nil, "Could not retrieve #{code}: "\
|
@@ -84,10 +91,11 @@ module Asciidoctor
|
|
84
91
|
"<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
|
85
92
|
end
|
86
93
|
|
87
|
-
def smart_render_xml(x, code,
|
88
|
-
|
94
|
+
def smart_render_xml(x, code, opts)
|
95
|
+
x.respond_to? :to_xml or return nil
|
96
|
+
xstr = x.to_xml(lang: opts[:lang])
|
89
97
|
xml = Nokogiri::XML(xstr)
|
90
|
-
emend_biblio(xml, code, title, usrlbl)
|
98
|
+
emend_biblio(xml, code, opts[:title], opts[:usrlbl])
|
91
99
|
xml.xpath("//date").each { |d| Utils::endash_date(d) }
|
92
100
|
xml.traverse do |n|
|
93
101
|
n.text? and n.replace(Utils::smartformat(n.text))
|