metanorma-standoc 1.5.1 → 1.6.2
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 +62 -0
- data/lib/asciidoctor/standoc/base.rb +7 -2
- data/lib/asciidoctor/standoc/basicdoc.rng +23 -0
- data/lib/asciidoctor/standoc/cleanup.rb +32 -12
- data/lib/asciidoctor/standoc/cleanup_amend.rb +54 -0
- data/lib/asciidoctor/standoc/cleanup_block.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +14 -0
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +11 -3
- data/lib/asciidoctor/standoc/cleanup_inline.rb +62 -1
- data/lib/asciidoctor/standoc/cleanup_ref.rb +6 -5
- data/lib/asciidoctor/standoc/cleanup_section.rb +19 -3
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -2
- data/lib/asciidoctor/standoc/converter.rb +4 -2
- data/lib/asciidoctor/standoc/front.rb +9 -3
- data/lib/asciidoctor/standoc/front_contributor.rb +58 -18
- data/lib/asciidoctor/standoc/inline.rb +21 -31
- data/lib/asciidoctor/standoc/isodoc.rng +125 -58
- data/lib/asciidoctor/standoc/log.rb +10 -1
- data/lib/asciidoctor/standoc/macros.rb +44 -33
- data/lib/asciidoctor/standoc/ref.rb +39 -44
- data/lib/asciidoctor/standoc/ref_sect.rb +12 -5
- data/lib/asciidoctor/standoc/section.rb +11 -10
- data/lib/asciidoctor/standoc/table.rb +3 -2
- data/lib/asciidoctor/standoc/utils.rb +2 -1
- data/lib/asciidoctor/standoc/validate.rb +30 -18
- data/lib/asciidoctor/standoc/validate_section.rb +1 -1
- data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +10 -10
- data/lib/liquid/custom_blocks/key_iterator.rb +21 -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/liquid/custom_filters/values.rb +7 -0
- data/lib/metanorma/standoc.rb +0 -5
- data/lib/metanorma/standoc/version.rb +20 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/asciidoctor-standoc/base_spec.rb +248 -10
- data/spec/asciidoctor-standoc/blocks_spec.rb +263 -144
- data/spec/asciidoctor-standoc/cleanup_spec.rb +199 -50
- data/spec/asciidoctor-standoc/inline_spec.rb +132 -5
- data/spec/asciidoctor-standoc/isobib_cache_spec.rb +13 -27
- data/spec/asciidoctor-standoc/macros_json2text_spec.rb +10 -0
- data/spec/asciidoctor-standoc/macros_spec.rb +43 -23
- data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +6 -561
- data/spec/asciidoctor-standoc/refs_dl_spec.rb +5 -3
- data/spec/asciidoctor-standoc/refs_spec.rb +268 -57
- data/spec/asciidoctor-standoc/section_spec.rb +0 -1
- data/spec/asciidoctor-standoc/table_spec.rb +119 -113
- data/spec/asciidoctor-standoc/validate_spec.rb +27 -1
- data/spec/examples/codes_table.html +1365 -1365
- data/spec/fixtures/macros_datamodel/address_class_profile.xml +46 -46
- data/spec/fixtures/macros_datamodel/address_component_profile.xml +21 -21
- data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +21 -21
- data/spec/spec_helper.rb +115 -109
- data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +781 -0
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +54 -238
- data/spec/vcr_cassettes/isobib_get_123.yml +14 -60
- data/spec/vcr_cassettes/isobib_get_123_1.yml +24 -116
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +361 -0
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +14 -60
- 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 +39 -37
- metadata +42 -11
- data/.github/workflows/macos.yml +0 -46
- data/.github/workflows/ubuntu.yml +0 -49
- data/.github/workflows/windows.yml +0 -53
- data/lib/asciidoctor/standoc/macros_yaml2text.rb +0 -165
- data/lib/metanorma/standoc/latexml_requirement.rb +0 -62
- data/lib/metanorma/standoc/requirement.rb +0 -13
@@ -8,7 +8,8 @@ module Asciidoctor
|
|
8
8
|
def add(category, loc, msg)
|
9
9
|
return if @novalid
|
10
10
|
@log[category] = [] unless @log[category]
|
11
|
-
@log[category] << { location: current_location(loc), message: msg
|
11
|
+
@log[category] << { location: current_location(loc), message: msg,
|
12
|
+
context: context(loc) }
|
12
13
|
loc = loc.nil? ? "" : "(#{current_location(loc)}): "
|
13
14
|
warn "#{category}: #{loc}#{msg}"
|
14
15
|
end
|
@@ -31,6 +32,13 @@ module Asciidoctor
|
|
31
32
|
"??"
|
32
33
|
end
|
33
34
|
|
35
|
+
def context(n)
|
36
|
+
return nil if n.is_a? String
|
37
|
+
n.respond_to?(:to_xml) and return n.to_xml
|
38
|
+
n.respond_to?(:to_s) and return n.to_s
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
34
42
|
def write(file)
|
35
43
|
File.open(file, "w:UTF-8") do |f|
|
36
44
|
f.puts "#{file} errors"
|
@@ -41,6 +49,7 @@ module Asciidoctor
|
|
41
49
|
end.each do |n|
|
42
50
|
loc = n[:location] ? "(#{n[:location]}): " : ""
|
43
51
|
f.puts "#{loc}#{n[:message]}"
|
52
|
+
n[:context]&.split(/\n/)&.first(5)&.each { |l| f.puts "\t#{l}" }
|
44
53
|
end
|
45
54
|
end
|
46
55
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require "asciidoctor/extensions"
|
2
2
|
require "fileutils"
|
3
3
|
require "uuidtools"
|
4
|
-
require
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
|
4
|
+
require "yaml"
|
5
|
+
require_relative "./macros_plantuml.rb"
|
6
|
+
require_relative "./datamodel/attributes_table_preprocessor.rb"
|
7
|
+
require_relative "./datamodel/diagram_preprocessor.rb"
|
8
|
+
require "metanorma-plugin-datastruct"
|
9
9
|
|
10
10
|
module Asciidoctor
|
11
11
|
module Standoc
|
@@ -61,17 +61,17 @@ module Asciidoctor
|
|
61
61
|
use_dsl
|
62
62
|
named :concept
|
63
63
|
name_positional_attributes "id", "word", "term"
|
64
|
-
#match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
|
64
|
+
# match %r{concept:(?<target>[^\[]*)\[(?<content>|.*?[^\\])\]$}
|
65
65
|
match /\{\{(?<content>|.*?[^\\])\}\}/
|
66
66
|
using_format :short
|
67
67
|
|
68
68
|
# deal with locality attrs and their disruption of positional attrs
|
69
69
|
def preprocess_attrs(attrs)
|
70
|
-
attrs.delete("term") if attrs["term"]
|
70
|
+
attrs.delete("term") if attrs["term"] && !attrs["word"]
|
71
71
|
attrs.delete(3) if attrs[3] == attrs["term"]
|
72
|
-
a = attrs.keys.reject { |k| k.is_a?
|
73
|
-
attrs["word"] ||= attrs[a[0]] if a.
|
74
|
-
attrs["term"] ||= attrs[a[1]] if a.length
|
72
|
+
a = attrs.keys.reject { |k| k.is_a?(String) || [1, 2].include?(k) }
|
73
|
+
attrs["word"] ||= attrs[a[0]] if !a.empty?
|
74
|
+
attrs["term"] ||= attrs[a[1]] if a.length > 1
|
75
75
|
attrs
|
76
76
|
end
|
77
77
|
|
@@ -94,30 +94,30 @@ module Asciidoctor
|
|
94
94
|
|
95
95
|
def init_indent(s)
|
96
96
|
/^(?<prefix>[ \t]*)(?<suffix>.*)$/ =~ s
|
97
|
-
prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0")
|
98
|
-
gsub(/ /, "\u00a0")
|
97
|
+
prefix = prefix.gsub(/\t/, "\u00a0\u00a0\u00a0\u00a0")
|
98
|
+
.gsub(/ /, "\u00a0")
|
99
99
|
prefix + suffix
|
100
100
|
end
|
101
101
|
|
102
102
|
def supply_br(lines)
|
103
103
|
ignore = false
|
104
104
|
lines.each_with_index do |l, i|
|
105
|
-
/^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/.match(l)
|
106
|
-
ignore = !ignore
|
105
|
+
/^(--+|====+|\|===|\.\.\.\.+|\*\*\*\*+|\+\+\+\++|\`\`\`\`+|____\+)$/.match(l) &&
|
106
|
+
(ignore = !ignore)
|
107
107
|
next if l.empty? || l.match(/ \+$/)
|
108
108
|
next if /^\[.*\]$/.match(l)
|
109
109
|
next if ignore
|
110
|
-
next if i == lines.size - 1 || i < lines.size - 1 && lines[i+1].empty?
|
110
|
+
next if i == lines.size - 1 || i < lines.size - 1 && lines[i + 1].empty?
|
111
111
|
lines[i] += " +"
|
112
112
|
end
|
113
113
|
lines
|
114
114
|
end
|
115
115
|
|
116
|
-
def process
|
117
|
-
attrs[
|
116
|
+
def process(parent, reader, attrs)
|
117
|
+
attrs["role"] = "pseudocode"
|
118
118
|
lines = reader.lines.map { |m| init_indent(m) }
|
119
119
|
ret = create_block(parent, :example, supply_br(lines),
|
120
|
-
|
120
|
+
attrs, content_model: :compound)
|
121
121
|
ret
|
122
122
|
end
|
123
123
|
end
|
@@ -128,19 +128,19 @@ module Asciidoctor
|
|
128
128
|
parse_content_as :text
|
129
129
|
option :pos_attrs, %w(rpbegin rt rpend)
|
130
130
|
|
131
|
-
def process(
|
132
|
-
rpbegin =
|
133
|
-
rpend =
|
134
|
-
if attributes.size == 1
|
131
|
+
def process(_parent, target, attributes)
|
132
|
+
rpbegin = "("
|
133
|
+
rpend = ")"
|
134
|
+
if (attributes.size == 1) && attributes.key?("text")
|
135
135
|
rt = attributes["text"]
|
136
|
-
elsif attributes.size == 2
|
137
|
-
|
136
|
+
elsif (attributes.size == 2) && attributes.key?(1) &&
|
137
|
+
attributes.key?("rpbegin")
|
138
138
|
# for example, html5ruby:楽聖少女[がくせいしょうじょ]
|
139
139
|
rt = attributes[1] || ""
|
140
140
|
else
|
141
|
-
rpbegin = attributes[
|
142
|
-
rt = attributes[
|
143
|
-
rpend = attributes[
|
141
|
+
rpbegin = attributes["rpbegin"]
|
142
|
+
rt = attributes["rt"]
|
143
|
+
rpend = attributes["rpend"]
|
144
144
|
end
|
145
145
|
|
146
146
|
"<ruby>#{target}<rp>#{rpbegin}</rp><rt>#{rt}</rt>"\
|
@@ -153,16 +153,16 @@ module Asciidoctor
|
|
153
153
|
named :TODO
|
154
154
|
on_contexts :example, :paragraph
|
155
155
|
|
156
|
-
def process
|
157
|
-
attrs[
|
158
|
-
attrs[
|
156
|
+
def process(parent, reader, attrs)
|
157
|
+
attrs["name"] = "todo"
|
158
|
+
attrs["caption"] = "TODO"
|
159
159
|
create_block parent, :admonition, reader.lines, attrs,
|
160
|
-
|
160
|
+
content_model: :compound
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
164
|
class ToDoInlineAdmonitionBlock < Extensions::Treeprocessor
|
165
|
-
def process
|
165
|
+
def process(document)
|
166
166
|
(document.find_by context: :paragraph).each do |para|
|
167
167
|
next unless /^TODO: /.match para.lines[0]
|
168
168
|
parent = para.parent
|
@@ -170,10 +170,21 @@ module Asciidoctor
|
|
170
170
|
para.set_attr("caption", "TODO")
|
171
171
|
para.lines[0].sub!(/^TODO: /, "")
|
172
172
|
todo = Block.new parent, :admonition, attributes: para.attributes,
|
173
|
-
|
173
|
+
source: para.lines, content_model: :compound
|
174
174
|
parent.blocks[parent.blocks.index(para)] = todo
|
175
175
|
end
|
176
176
|
end
|
177
177
|
end
|
178
|
+
|
179
|
+
class AutonumberInlineMacro < Extensions::InlineMacroProcessor
|
180
|
+
use_dsl
|
181
|
+
named :autonumber
|
182
|
+
parse_content_as :text
|
183
|
+
|
184
|
+
def process(parent, target, attrs)
|
185
|
+
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
186
|
+
%{<autonumber type=#{target}>#{out}</autonumber>}
|
187
|
+
end
|
188
|
+
end
|
178
189
|
end
|
179
190
|
end
|
@@ -42,8 +42,7 @@ module Asciidoctor
|
|
42
42
|
|
43
43
|
def docid(t, code)
|
44
44
|
type, code1 = /^\[\d+\]$|^\([^)]+\).*$/.match(code) ?
|
45
|
-
["metanorma", mn_code(code)] :
|
46
|
-
@bibdb&.docid_type(code) || [nil, code]
|
45
|
+
["metanorma", mn_code(code)] : @bibdb&.docid_type(code) || [nil, code]
|
47
46
|
code1.sub!(/^nofetch\((.+)\)$/, "\\1")
|
48
47
|
t.docidentifier **attr_code(type: type) do |d|
|
49
48
|
d << code1
|
@@ -69,7 +68,8 @@ module Asciidoctor
|
|
69
68
|
|
70
69
|
def isorefmatches(xml, m)
|
71
70
|
yr = norm_year(m[:year])
|
72
|
-
ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl]
|
71
|
+
ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl],
|
72
|
+
lang: (@lang || :all)
|
73
73
|
return use_my_anchor(ref, m[:anchor]) if ref
|
74
74
|
xml.bibitem **attr_code(ref_attributes(m)) do |t|
|
75
75
|
isorefrender1(t, m, yr)
|
@@ -82,8 +82,12 @@ module Asciidoctor
|
|
82
82
|
|
83
83
|
def isorefmatches2(xml, m)
|
84
84
|
ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn],
|
85
|
-
title: m[:text], usrlbl: m[:usrlbl]
|
85
|
+
title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
|
86
86
|
return use_my_anchor(ref, m[:anchor]) if ref
|
87
|
+
isorefmatches2_1(xml, m)
|
88
|
+
end
|
89
|
+
|
90
|
+
def isorefmatches2_1(xml, m)
|
87
91
|
xml.bibitem **attr_code(ref_attributes(m)) do |t|
|
88
92
|
isorefrender1(t, m, "--")
|
89
93
|
t.date **{ type: "published" } do |d|
|
@@ -106,13 +110,15 @@ module Asciidoctor
|
|
106
110
|
|
107
111
|
def isorefmatches3(xml, m)
|
108
112
|
yr = norm_year(m[:year])
|
109
|
-
#hasyr = m.names.include?("year") && yr != "--"
|
110
113
|
hasyr = !yr.nil? && yr != "--"
|
111
|
-
#noyr = m.names.include?("year") && yr == "--"
|
112
114
|
ref = fetch_ref xml, m[:code], hasyr ? yr : nil, all_parts: true,
|
113
|
-
no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl]
|
115
|
+
no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl],
|
116
|
+
lang: (@lang || :all)
|
114
117
|
return use_my_anchor(ref, m[:anchor]) if ref
|
118
|
+
isorefmatches3_1(xml, m, yr, hasyr, ref)
|
119
|
+
end
|
115
120
|
|
121
|
+
def isorefmatches3_1(xml, m, yr, hasyr, ref)
|
116
122
|
xml.bibitem(**attr_code(ref_attributes(m))) do |t|
|
117
123
|
isorefrender1(t, m, yr, " (all parts)")
|
118
124
|
conditional_date(t, m, yr == "--")
|
@@ -147,30 +153,24 @@ module Asciidoctor
|
|
147
153
|
end
|
148
154
|
|
149
155
|
MALFORMED_REF = "no anchor on reference, markup may be malformed: see "\
|
150
|
-
"https://www.metanorma.com/author/topics/document-format/
|
151
|
-
"https://www.metanorma.com/author/iso/topics/markup
|
156
|
+
"https://www.metanorma.com/author/topics/document-format/"\
|
157
|
+
"bibliography/ , https://www.metanorma.com/author/iso/topics/markup/"\
|
158
|
+
"#bibliographies".freeze
|
152
159
|
|
153
160
|
def analyse_ref_nofetch(ret)
|
154
161
|
return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
|
155
|
-
ret
|
156
|
-
ret[:nofetch] = true
|
157
|
-
ret
|
162
|
+
ret.merge(id: m[:id], nofetch: true)
|
158
163
|
end
|
159
164
|
|
160
165
|
def analyse_ref_repo_path(ret)
|
161
166
|
return ret unless m =
|
162
167
|
/^(?<type>repo|path):\((?<key>[^,]+),(?<id>.+)\)$/.match(ret[:id])
|
163
|
-
ret[:id]
|
164
|
-
ret[:type] = m[:type]
|
165
|
-
ret[:key] = m[:key]
|
166
|
-
ret[:nofetch] = true
|
167
|
-
ret
|
168
|
+
ret.merge(id: m[:id], type: m[:type], key: m[:key], nofetch: true)
|
168
169
|
end
|
169
170
|
|
170
171
|
def analyse_ref_numeric(ret)
|
171
172
|
return ret unless /^\d+$/.match(ret[:id])
|
172
|
-
ret
|
173
|
-
ret
|
173
|
+
ret.merge(numeric: true)
|
174
174
|
end
|
175
175
|
|
176
176
|
# ref id = (usrlbl)code[:-]year
|
@@ -178,23 +178,22 @@ module Asciidoctor
|
|
178
178
|
def analyse_ref_code(code)
|
179
179
|
ret = {id: code}
|
180
180
|
return ret if code.nil? || code.empty?
|
181
|
-
|
182
|
-
ret = analyse_ref_repo_path(ret)
|
183
|
-
ret = analyse_ref_numeric(ret)
|
184
|
-
ret
|
181
|
+
analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
|
185
182
|
end
|
186
183
|
|
187
184
|
# TODO: alternative where only title is available
|
188
185
|
def refitem(xml, item, node)
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
186
|
+
m = NON_ISO_REF.match(item) and return refitem1(xml, item, m)
|
187
|
+
@log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
|
188
|
+
nil
|
189
|
+
end
|
190
|
+
|
191
|
+
def refitem1(xml, item, m)
|
193
192
|
code = analyse_ref_code(m[:code])
|
194
193
|
unless code[:id] && code[:numeric] || code[:nofetch]
|
195
194
|
ref = fetch_ref xml, code[:id],
|
196
195
|
m.names.include?("year") ? m[:year] : nil, title: m[:text],
|
197
|
-
usrlbl: m[:usrlbl]
|
196
|
+
usrlbl: m[:usrlbl], lang: (@lang || :all)
|
198
197
|
return use_my_anchor(ref, m[:anchor]) if ref
|
199
198
|
end
|
200
199
|
refitem_render(xml, m, code)
|
@@ -214,23 +213,25 @@ module Asciidoctor
|
|
214
213
|
(?<text>.*)$}xm
|
215
214
|
|
216
215
|
ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
|
217
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
|
216
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
|
217
|
+
(--|\&\#821[12]\;)\]</ref>,?\s*
|
218
218
|
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
|
219
219
|
|
220
220
|
ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
|
221
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
|
221
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
|
222
|
+
(:(?<year>--|\&\#821[12]\;|[0-9][0-9-]+))?\s
|
222
223
|
\(all\sparts\)\]</ref>,?\s*
|
223
224
|
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
|
224
225
|
|
225
226
|
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
226
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
227
|
+
\[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
|
228
|
+
([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s*(?<text>.*)$}xm
|
229
|
+
|
230
|
+
def reference1_matches(item)
|
231
|
+
matched = ISO_REF.match item
|
232
|
+
matched2 = ISO_REF_NO_YEAR.match item
|
233
|
+
matched3 = ISO_REF_ALL_PARTS.match item
|
234
|
+
[matched, matched2, matched3]
|
234
235
|
end
|
235
236
|
|
236
237
|
def reference1(node, item, xml)
|
@@ -243,12 +244,6 @@ module Asciidoctor
|
|
243
244
|
end
|
244
245
|
end
|
245
246
|
|
246
|
-
def reference(node)
|
247
|
-
noko do |xml|
|
248
|
-
node.items.each { |item| reference1(node, item.text, xml) }
|
249
|
-
end.join
|
250
|
-
end
|
251
|
-
|
252
247
|
def mn_code(code)
|
253
248
|
code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
|
254
249
|
end
|
@@ -9,6 +9,12 @@ 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
|
@@ -58,10 +64,10 @@ module Asciidoctor
|
|
58
64
|
def fetch_ref(xml, code, year, **opts)
|
59
65
|
return nil if opts[:no_year]
|
60
66
|
code = code.sub(/^\([^)]+\)/, "")
|
67
|
+
#require "byebug"; byebug if opts[:lang] == "fr"
|
61
68
|
hit = @bibdb&.fetch(code, year, opts)
|
62
69
|
return nil if hit.nil?
|
63
|
-
xml.parent.add_child(smart_render_xml(hit, code, opts
|
64
|
-
opts[:usrlbl]))
|
70
|
+
xml.parent.add_child(smart_render_xml(hit, code, opts))
|
65
71
|
xml
|
66
72
|
rescue RelatonBib::RequestError
|
67
73
|
@log.add("Bibliography", nil, "Could not retrieve #{code}: "\
|
@@ -84,10 +90,11 @@ module Asciidoctor
|
|
84
90
|
"<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
|
85
91
|
end
|
86
92
|
|
87
|
-
def smart_render_xml(x, code,
|
88
|
-
|
93
|
+
def smart_render_xml(x, code, opts)
|
94
|
+
x.respond_to? :to_xml or return nil
|
95
|
+
xstr = x.to_xml(lang: opts[:lang])
|
89
96
|
xml = Nokogiri::XML(xstr)
|
90
|
-
emend_biblio(xml, code, title, usrlbl)
|
97
|
+
emend_biblio(xml, code, opts[:title], opts[:usrlbl])
|
91
98
|
xml.xpath("//date").each { |d| Utils::endash_date(d) }
|
92
99
|
xml.traverse do |n|
|
93
100
|
n.text? and n.replace(Utils::smartformat(n.text))
|
@@ -46,7 +46,7 @@ module Asciidoctor
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def section_attributes(node)
|
49
|
-
{ id: Utils::anchor_or_uuid(node),
|
49
|
+
ret = { id: Utils::anchor_or_uuid(node),
|
50
50
|
language: node.attributes["language"],
|
51
51
|
script: node.attributes["script"],
|
52
52
|
annex: (
|
@@ -55,8 +55,12 @@ module Asciidoctor
|
|
55
55
|
),
|
56
56
|
preface: (
|
57
57
|
(node.role == "preface" || node.attr("style") == "preface") ?
|
58
|
-
true : nil)
|
59
|
-
|
58
|
+
true : nil) }
|
59
|
+
return ret unless node.attributes["change"]
|
60
|
+
ret.merge(change: node.attributes["change"],
|
61
|
+
path: node.attributes["path"],
|
62
|
+
path_end: node.attributes["path_end"],
|
63
|
+
title: node.attributes["title"])
|
60
64
|
end
|
61
65
|
|
62
66
|
def section(node)
|
@@ -100,13 +104,10 @@ module Asciidoctor
|
|
100
104
|
end
|
101
105
|
|
102
106
|
def set_obligation(attrs, node)
|
103
|
-
attrs[:obligation] =
|
104
|
-
node.attr("obligation")
|
105
|
-
|
106
|
-
node.parent.attr("obligation")
|
107
|
-
else
|
108
|
-
"normative"
|
109
|
-
end
|
107
|
+
attrs[:obligation] = node.attributes.has_key?("obligation") ?
|
108
|
+
node.attr("obligation") :
|
109
|
+
node.parent.attributes.has_key?("obligation") ?
|
110
|
+
node.parent.attr("obligation") : "normative"
|
110
111
|
end
|
111
112
|
|
112
113
|
def preamble(node)
|
@@ -45,8 +45,9 @@ module Asciidoctor
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def table_cell(c, xml_tr, tblsec)
|
48
|
-
cell_attributes =
|
49
|
-
|
48
|
+
cell_attributes =
|
49
|
+
{ id: c.id, colspan: c.colspan, valign: c.attr("valign"),
|
50
|
+
rowspan: c.rowspan, align: c.attr("halign") }
|
50
51
|
cell_tag = "td"
|
51
52
|
cell_tag = "th" if tblsec == :head || c.style == :header
|
52
53
|
xml_tr.send cell_tag, **attr_code(cell_attributes) do |thd|
|
@@ -128,7 +128,8 @@ module Asciidoctor
|
|
128
128
|
::Nokogiri::XML::Builder.with fragment, &block
|
129
129
|
fragment.to_xml(encoding: "US-ASCII", indent: 0).lines.map do |l|
|
130
130
|
l.gsub(/>\n$/, ">").gsub(/\s*\n$/m, " ").gsub("–", "\u0096").
|
131
|
-
gsub("—", "\u0097")
|
131
|
+
gsub("—", "\u0097").gsub("–", "\u0096").
|
132
|
+
gsub("—", "\u0097")
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|