metanorma-standoc 1.11.1 → 2.0.0
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 -31
- data/.gitignore +23 -0
- data/Gemfile +2 -0
- data/lib/asciidoctor/standoc/base.rb +2 -241
- data/lib/asciidoctor/standoc/blocks.rb +2 -238
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -100
- data/lib/asciidoctor/standoc/cleanup.rb +2 -207
- data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
- data/lib/asciidoctor/standoc/cleanup_block.rb +2 -173
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -204
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +2 -108
- data/lib/asciidoctor/standoc/cleanup_image.rb +2 -69
- data/lib/asciidoctor/standoc/cleanup_inline.rb +2 -179
- data/lib/asciidoctor/standoc/cleanup_maths.rb +2 -221
- data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -169
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +2 -93
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -110
- data/lib/asciidoctor/standoc/cleanup_section.rb +2 -184
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -91
- data/lib/asciidoctor/standoc/cleanup_symbols.rb +2 -47
- data/lib/asciidoctor/standoc/cleanup_table.rb +2 -67
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -113
- data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -161
- data/lib/asciidoctor/standoc/cleanup_text.rb +2 -95
- data/lib/asciidoctor/standoc/cleanup_toc.rb +3 -0
- data/lib/asciidoctor/standoc/cleanup_xref.rb +2 -106
- data/lib/asciidoctor/standoc/converter.rb +2 -123
- data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +2 -56
- data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +2 -102
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +3 -404
- data/lib/asciidoctor/standoc/deprecated.rb +5 -0
- data/lib/asciidoctor/standoc/front.rb +2 -219
- data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
- data/lib/asciidoctor/standoc/inline.rb +2 -229
- data/lib/asciidoctor/standoc/lists.rb +2 -119
- data/lib/asciidoctor/standoc/macros.rb +2 -203
- data/lib/asciidoctor/standoc/macros_form.rb +2 -62
- data/lib/asciidoctor/standoc/macros_note.rb +2 -44
- data/lib/asciidoctor/standoc/macros_plantuml.rb +2 -112
- data/lib/asciidoctor/standoc/macros_terms.rb +2 -180
- data/lib/asciidoctor/standoc/ref.rb +2 -225
- data/lib/asciidoctor/standoc/ref_sect.rb +2 -143
- data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
- data/lib/asciidoctor/standoc/render.rb +3 -0
- data/lib/asciidoctor/standoc/reqt.rb +2 -89
- data/lib/asciidoctor/standoc/section.rb +2 -190
- data/lib/asciidoctor/standoc/table.rb +2 -84
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +2 -178
- data/lib/asciidoctor/standoc/terms.rb +2 -153
- data/lib/asciidoctor/standoc/utils.rb +2 -116
- data/lib/asciidoctor/standoc/validate.rb +2 -157
- data/lib/asciidoctor/standoc/validate_section.rb +2 -54
- data/lib/isodoc/html/htmlstyle.css +20 -11
- data/lib/isodoc/html/htmlstyle.scss +11 -11
- data/lib/metanorma/standoc/base.rb +149 -0
- data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +0 -0
- data/lib/metanorma/standoc/blocks.rb +239 -0
- data/lib/metanorma/standoc/blocks_notes.rb +101 -0
- data/lib/metanorma/standoc/cleanup.rb +146 -0
- data/lib/metanorma/standoc/cleanup_amend.rb +54 -0
- data/lib/metanorma/standoc/cleanup_block.rb +173 -0
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +213 -0
- data/lib/metanorma/standoc/cleanup_footnotes.rb +109 -0
- data/lib/metanorma/standoc/cleanup_image.rb +70 -0
- data/lib/metanorma/standoc/cleanup_inline.rb +190 -0
- data/lib/metanorma/standoc/cleanup_maths.rb +222 -0
- data/lib/metanorma/standoc/cleanup_ref.rb +170 -0
- data/lib/metanorma/standoc/cleanup_ref_dl.rb +104 -0
- data/lib/metanorma/standoc/cleanup_reqt.rb +111 -0
- data/lib/metanorma/standoc/cleanup_section.rb +212 -0
- data/lib/metanorma/standoc/cleanup_section_names.rb +92 -0
- data/lib/metanorma/standoc/cleanup_symbols.rb +48 -0
- data/lib/metanorma/standoc/cleanup_table.rb +68 -0
- data/lib/metanorma/standoc/cleanup_terms.rb +140 -0
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +199 -0
- data/lib/metanorma/standoc/cleanup_text.rb +96 -0
- data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
- data/lib/metanorma/standoc/cleanup_xref.rb +107 -0
- data/lib/metanorma/standoc/converter.rb +124 -0
- data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +57 -0
- data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +103 -0
- data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +409 -0
- data/lib/metanorma/standoc/front.rb +224 -0
- data/lib/metanorma/standoc/front_contributor.rb +192 -0
- data/lib/metanorma/standoc/inline.rb +232 -0
- data/lib/{asciidoctor → metanorma}/standoc/isodoc.rng +90 -18
- data/lib/metanorma/standoc/lists.rb +120 -0
- data/lib/metanorma/standoc/macros.rb +204 -0
- data/lib/metanorma/standoc/macros_form.rb +63 -0
- data/lib/metanorma/standoc/macros_note.rb +45 -0
- data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
- data/lib/metanorma/standoc/macros_terms.rb +181 -0
- data/lib/metanorma/standoc/ref.rb +243 -0
- data/lib/metanorma/standoc/ref_sect.rb +153 -0
- data/lib/metanorma/standoc/ref_utility.rb +129 -0
- data/lib/metanorma/standoc/render.rb +115 -0
- data/lib/metanorma/standoc/reqt.rb +90 -0
- data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
- data/lib/metanorma/standoc/section.rb +209 -0
- data/lib/metanorma/standoc/table.rb +85 -0
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +179 -0
- data/lib/metanorma/standoc/terms.rb +160 -0
- data/lib/metanorma/standoc/utils.rb +101 -0
- data/lib/metanorma/standoc/validate.rb +158 -0
- data/lib/metanorma/standoc/validate_section.rb +55 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
- data/lib/metanorma-standoc.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/{asciidoctor → metanorma}/base_spec.rb +73 -8
- data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/blocks_spec.rb +49 -20
- data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +25 -1
- data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +2 -2
- data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +9 -9
- data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +528 -91
- data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +22 -22
- data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +17 -17
- data/spec/{asciidoctor → metanorma}/inline_spec.rb +175 -6
- data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +5 -9
- data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
- data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
- data/spec/{asciidoctor → metanorma}/macros_spec.rb +8 -8
- data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
- data/spec/metanorma/refs_dl_spec.rb +863 -0
- data/spec/{asciidoctor → metanorma}/refs_spec.rb +1277 -687
- data/spec/{asciidoctor → metanorma}/section_spec.rb +90 -3
- data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +179 -179
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +98 -98
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +111 -111
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
- metadata +89 -38
- data/lib/asciidoctor/standoc/ref_date_id.rb +0 -62
- data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -1,181 +1,3 @@
|
|
1
|
-
require "
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/macros_terms"
|
2
3
|
|
3
|
-
module Asciidoctor
|
4
|
-
module Standoc
|
5
|
-
class PreferredTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
6
|
-
use_dsl
|
7
|
-
named :preferred
|
8
|
-
parse_content_as :text
|
9
|
-
using_format :short
|
10
|
-
|
11
|
-
def process(parent, _target, attrs)
|
12
|
-
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
|
13
|
-
%{<preferred><expression><name>#{out}</name></expression></preferred>}
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class AltTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
18
|
-
use_dsl
|
19
|
-
named :alt
|
20
|
-
parse_content_as :text
|
21
|
-
using_format :short
|
22
|
-
|
23
|
-
def process(parent, _target, attrs)
|
24
|
-
out = Asciidoctor::Inline.new(parent, :quoted,
|
25
|
-
attrs["text"]).convert
|
26
|
-
%{<admitted><expression><name>#{out}</name></expression></admitted>}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class DeprecatedTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
31
|
-
use_dsl
|
32
|
-
named :deprecated
|
33
|
-
parse_content_as :text
|
34
|
-
using_format :short
|
35
|
-
|
36
|
-
def process(parent, _target, attrs)
|
37
|
-
out = Asciidoctor::Inline.new(parent, :quoted,
|
38
|
-
attrs["text"]).convert
|
39
|
-
%{<deprecates><expression><name>#{out}</name></expression></deprecates>}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class DomainTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
44
|
-
use_dsl
|
45
|
-
named :domain
|
46
|
-
parse_content_as :text
|
47
|
-
using_format :short
|
48
|
-
|
49
|
-
def process(parent, _target, attrs)
|
50
|
-
out = Asciidoctor::Inline.new(parent, :quoted,
|
51
|
-
attrs["text"]).convert
|
52
|
-
%{<domain>#{out}</domain>}
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class TermRefInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
57
|
-
use_dsl
|
58
|
-
named :term
|
59
|
-
name_positional_attributes "name", "termxref"
|
60
|
-
using_format :short
|
61
|
-
|
62
|
-
def process(_parent, _target, attrs)
|
63
|
-
termref = attrs["termxref"] || attrs["name"]
|
64
|
-
"<concept type='term'><termxref>#{attrs['name']}</termxref>"\
|
65
|
-
"<renderterm>#{termref}</renderterm><xrefrender/></concept>"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class SymbolRefInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
70
|
-
use_dsl
|
71
|
-
named :symbol
|
72
|
-
name_positional_attributes "name", "termxref"
|
73
|
-
using_format :short
|
74
|
-
|
75
|
-
def process(_parent, _target, attrs)
|
76
|
-
termref = attrs["termxref"] || attrs["name"]
|
77
|
-
"<concept type='symbol'><termxref>#{attrs['name']}</termxref>"\
|
78
|
-
"<renderterm>#{termref}</renderterm><xrefrender/></concept>"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# Possibilities:
|
83
|
-
# {{<<id>>, term}}
|
84
|
-
# {{<<id>>, term, text}}
|
85
|
-
# {{<<termbase:id>>, term}}
|
86
|
-
# {{<<termbase:id>>, term, text}}
|
87
|
-
# {{term}} equivalent to term:[term]
|
88
|
-
# {{term, text}} equivalent to term:[term, text]
|
89
|
-
# text may optionally be followed by crossreference-rendering, options=""
|
90
|
-
class ConceptInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
91
|
-
use_dsl
|
92
|
-
named :concept
|
93
|
-
match /\{\{(?<content>|.*?[^\\])\}\}/
|
94
|
-
using_format :short
|
95
|
-
|
96
|
-
def preprocess_attrs(target)
|
97
|
-
m = /^(?<id><<.+?>>)?(?<rest>.*)$/.match(target)
|
98
|
-
ret = { id: m[:id]&.sub(/^<</, "")&.sub(/>>$/, "") }
|
99
|
-
if m2 = /^(?<rest>.*?)(?<opt>,opt(ion)?s=.+)$/
|
100
|
-
.match(m[:rest].sub(/^,/, ""))
|
101
|
-
ret[:opt] = CSV.parse_line(m2[:opt].sub(/^,opt(ion)?s=/, "")
|
102
|
-
.sub(/^"(.+)"$/, "\\1").sub(/^'(.+)'$/, "\\1"))
|
103
|
-
begin
|
104
|
-
attrs = CSV.parse_line(m2[:rest]) || []
|
105
|
-
rescue StandardError
|
106
|
-
raise "error processing #{m2[:rest]} as CSV"
|
107
|
-
end
|
108
|
-
else
|
109
|
-
begin
|
110
|
-
attrs = CSV.parse_line(m[:rest].sub(/^,/, "")) || []
|
111
|
-
rescue StandardError
|
112
|
-
raise "error processing #{m[:rest]} as CSV"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
ret.merge(term: attrs[0], word: attrs[1] || attrs[0],
|
116
|
-
render: attrs[2])
|
117
|
-
end
|
118
|
-
|
119
|
-
def generate_attrs(opts)
|
120
|
-
ret = ""
|
121
|
-
opts.include?("noital") and ret += " ital='false'"
|
122
|
-
opts.include?("noref") and ret += " ref='false'"
|
123
|
-
opts.include?("ital") and ret += " ital='true'"
|
124
|
-
opts.include?("ref") and ret += " ref='true'"
|
125
|
-
opts.include?("nolinkmention") and ret += " linkmention='false'"
|
126
|
-
opts.include?("linkmention") and ret += " linkmention='true'"
|
127
|
-
opts.include?("nolinkref") and ret += " linkref='false'"
|
128
|
-
opts.include?("linkref") and ret += " linkref='true'"
|
129
|
-
ret
|
130
|
-
end
|
131
|
-
|
132
|
-
def process(parent, target, _attrs)
|
133
|
-
attrs = preprocess_attrs(target)
|
134
|
-
term = Asciidoctor::Inline.new(parent, :quoted,
|
135
|
-
attrs[:term]).convert
|
136
|
-
word = Asciidoctor::Inline.new(parent, :quoted,
|
137
|
-
attrs[:word]).convert
|
138
|
-
xref = Asciidoctor::Inline.new(parent, :quoted,
|
139
|
-
attrs[:render]).convert
|
140
|
-
opt = generate_attrs(attrs[:opt] || [])
|
141
|
-
if attrs[:id] then "<concept#{opt} key='#{attrs[:id]}'><refterm>"\
|
142
|
-
"#{term}</refterm><renderterm>#{word}</renderterm>"\
|
143
|
-
"<xrefrender>#{xref}</xrefrender></concept>"
|
144
|
-
else "<concept#{opt}><termxref>#{term}</termxref><renderterm>"\
|
145
|
-
"#{word}</renderterm><xrefrender>#{xref}</xrefrender></concept>"
|
146
|
-
end
|
147
|
-
rescue StandardError => e
|
148
|
-
raise("processing {{#{target}}}: #{e.message}")
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
# Possibilities:
|
153
|
-
# related:relation[<<id>>, term]
|
154
|
-
# related:relation[<<termbase:id>>, term]
|
155
|
-
# related:relation[term] equivalent to a crossreference to term:[term]
|
156
|
-
class RelatedTermInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
157
|
-
use_dsl
|
158
|
-
named :related
|
159
|
-
parse_content_as :text
|
160
|
-
|
161
|
-
def preprocess_attrs(target)
|
162
|
-
m = /^(?<id><<.+?>>, ?)?(?<rest>.*)$/.match(target)
|
163
|
-
{ id: m[:id]&.sub(/^<</, "")&.sub(/>>, ?$/, ""),
|
164
|
-
term: m[:rest] }
|
165
|
-
end
|
166
|
-
|
167
|
-
def process(parent, target, attrs)
|
168
|
-
out = preprocess_attrs(attrs["text"])
|
169
|
-
term = Asciidoctor::Inline.new(parent, :quoted,
|
170
|
-
out[:term]).convert
|
171
|
-
if out[:id] then "<related type='#{target}' key='#{out[:id]}'>"\
|
172
|
-
"<refterm>#{term}</refterm></related>"
|
173
|
-
else "<related type='#{target}'><termxref>#{term}</termxref>"\
|
174
|
-
"<xrefrender>#{term}</xrefrender></related>"
|
175
|
-
end
|
176
|
-
rescue StandardError => e
|
177
|
-
raise("processing related:#{target}[#{attrs['text']}]: #{e.message}")
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
@@ -1,225 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Asciidoctor
|
4
|
-
module Standoc
|
5
|
-
module Refs
|
6
|
-
def iso_publisher(bib, code)
|
7
|
-
code.sub(/ .*$/, "").split("/").each do |abbrev|
|
8
|
-
bib.contributor do |c|
|
9
|
-
c.role **{ type: "publisher" }
|
10
|
-
c.organization do |org|
|
11
|
-
organization(org, abbrev, true)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def plaintxt
|
18
|
-
{ format: "text/plain" }
|
19
|
-
end
|
20
|
-
|
21
|
-
def ref_attributes(match)
|
22
|
-
{ id: match[:anchor], type: "standard" }
|
23
|
-
end
|
24
|
-
|
25
|
-
def isorefrender1(bib, match, yr, allp = "")
|
26
|
-
bib.title(**plaintxt) { |i| i << ref_normalise(match[:text]) }
|
27
|
-
docid(bib, match[:usrlbl]) if match[:usrlbl]
|
28
|
-
docid(bib, id_and_year(match[:code], yr) + allp)
|
29
|
-
docnumber(bib, match[:code])
|
30
|
-
end
|
31
|
-
|
32
|
-
def isorefmatches(xml, match)
|
33
|
-
yr = norm_year(match[:year])
|
34
|
-
ref = fetch_ref xml, match[:code], yr,
|
35
|
-
title: match[:text], usrlbl: match[:usrlbl],
|
36
|
-
lang: (@lang || :all)
|
37
|
-
return use_my_anchor(ref, match[:anchor]) if ref
|
38
|
-
|
39
|
-
xml.bibitem **attr_code(ref_attributes(match)) do |t|
|
40
|
-
isorefrender1(t, match, yr)
|
41
|
-
yr and t.date **{ type: "published" } do |d|
|
42
|
-
set_date_range(d, yr)
|
43
|
-
end
|
44
|
-
iso_publisher(t, match[:code])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def isorefmatches2(xml, match)
|
49
|
-
ref = fetch_ref xml, match[:code], nil,
|
50
|
-
no_year: true, note: match[:fn],
|
51
|
-
title: match[:text], usrlbl: match[:usrlbl],
|
52
|
-
lang: (@lang || :all)
|
53
|
-
return use_my_anchor(ref, match[:anchor]) if ref
|
54
|
-
|
55
|
-
isorefmatches2_1(xml, match)
|
56
|
-
end
|
57
|
-
|
58
|
-
def isorefmatches2_1(xml, match)
|
59
|
-
xml.bibitem **attr_code(ref_attributes(match)) do |t|
|
60
|
-
isorefrender1(t, match, "--")
|
61
|
-
t.date **{ type: "published" } do |d|
|
62
|
-
d.on "--"
|
63
|
-
end
|
64
|
-
iso_publisher(t, match[:code])
|
65
|
-
unless match[:fn].nil?
|
66
|
-
t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
|
67
|
-
p << (match[:fn]).to_s
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def isorefmatches3(xml, match)
|
74
|
-
yr = norm_year(match[:year])
|
75
|
-
hasyr = !yr.nil? && yr != "--"
|
76
|
-
ref = fetch_ref(xml, match[:code], hasyr ? yr : nil,
|
77
|
-
all_parts: true, no_year: yr == "--",
|
78
|
-
text: match[:text], usrlbl: match[:usrlbl],
|
79
|
-
lang: (@lang || :all))
|
80
|
-
return use_my_anchor(ref, match[:anchor]) if ref
|
81
|
-
|
82
|
-
isorefmatches3_1(xml, match, yr, hasyr, ref)
|
83
|
-
end
|
84
|
-
|
85
|
-
def isorefmatches3_1(xml, match, yr, _hasyr, _ref)
|
86
|
-
xml.bibitem(**attr_code(ref_attributes(match))) do |t|
|
87
|
-
isorefrender1(t, match, yr, " (all parts)")
|
88
|
-
conditional_date(t, match, yr == "--")
|
89
|
-
iso_publisher(t, match[:code])
|
90
|
-
if match.names.include?("fn") && match[:fn]
|
91
|
-
t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
|
92
|
-
p << (match[:fn]).to_s
|
93
|
-
end
|
94
|
-
end
|
95
|
-
t.extent **{ type: "part" } do |e|
|
96
|
-
e.referenceFrom "all"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def refitem_render1(match, code, bib)
|
102
|
-
if code[:type] == "path"
|
103
|
-
bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
|
104
|
-
bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
|
105
|
-
end
|
106
|
-
docid(bib, match[:usrlbl]) if match[:usrlbl]
|
107
|
-
docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
|
108
|
-
code[:type] == "repo" and
|
109
|
-
bib.docidentifier code[:key], **{ type: "repository" }
|
110
|
-
end
|
111
|
-
|
112
|
-
def refitem_render(xml, match, code)
|
113
|
-
xml.bibitem **attr_code(id: match[:anchor]) do |t|
|
114
|
-
t.formattedref **{ format: "application/x-isodoc+xml" } do |i|
|
115
|
-
i << ref_normalise_no_format(match[:text])
|
116
|
-
end
|
117
|
-
refitem_render1(match, code, t)
|
118
|
-
docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match?(code[:id])
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
MALFORMED_REF = "no anchor on reference, markup may be malformed: see "\
|
123
|
-
"https://www.metanorma.com/author/topics/document-format/bibliography/ , "\
|
124
|
-
"https://www.metanorma.com/author/iso/topics/markup/#bibliographies".freeze
|
125
|
-
|
126
|
-
def analyse_ref_nofetch(ret)
|
127
|
-
return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
|
128
|
-
|
129
|
-
ret.merge(id: m[:id], nofetch: true)
|
130
|
-
end
|
131
|
-
|
132
|
-
def analyse_ref_repo_path(ret)
|
133
|
-
return ret unless m =
|
134
|
-
/^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
|
135
|
-
|
136
|
-
id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
|
137
|
-
ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
|
138
|
-
end
|
139
|
-
|
140
|
-
def analyse_ref_numeric(ret)
|
141
|
-
return ret unless /^\d+$/.match?(ret[:id])
|
142
|
-
|
143
|
-
ret.merge(numeric: true)
|
144
|
-
end
|
145
|
-
|
146
|
-
# ref id = (usrlbl)code[:-]year
|
147
|
-
# code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
|
148
|
-
def analyse_ref_code(code)
|
149
|
-
ret = { id: code }
|
150
|
-
return ret if code.blank?
|
151
|
-
|
152
|
-
analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
|
153
|
-
end
|
154
|
-
|
155
|
-
# TODO: alternative where only title is available
|
156
|
-
def refitem(xml, item, node)
|
157
|
-
m = NON_ISO_REF.match(item) and return refitem1(xml, item, m)
|
158
|
-
@log.add("AsciiDoc Input", node, "#{MALFORMED_REF}: #{item}")
|
159
|
-
nil
|
160
|
-
end
|
161
|
-
|
162
|
-
def refitem1(xml, _item, match)
|
163
|
-
code = analyse_ref_code(match[:code])
|
164
|
-
unless (code[:id] && code[:numeric]) || code[:nofetch]
|
165
|
-
ref = fetch_ref(xml, code[:id],
|
166
|
-
match.names.include?("year") ? match[:year] : nil,
|
167
|
-
title: match[:text],
|
168
|
-
usrlbl: match[:usrlbl], lang: (@lang || :all)) and
|
169
|
-
return use_my_anchor(ref, match[:anchor])
|
170
|
-
end
|
171
|
-
|
172
|
-
refitem_render(xml, match, code)
|
173
|
-
end
|
174
|
-
|
175
|
-
def ref_normalise(ref)
|
176
|
-
ref.gsub(/&amp;/, "&").gsub(%r{^<em>(.*)</em>}, "\\1")
|
177
|
-
end
|
178
|
-
|
179
|
-
def ref_normalise_no_format(ref)
|
180
|
-
ref.gsub(/&amp;/, "&")
|
181
|
-
end
|
182
|
-
|
183
|
-
ISO_REF =
|
184
|
-
%r{^<ref\sid="(?<anchor>[^"]+)">
|
185
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
|
186
|
-
(:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm.freeze
|
187
|
-
|
188
|
-
ISO_REF_NO_YEAR =
|
189
|
-
%r{^<ref\sid="(?<anchor>[^"]+)">
|
190
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
|
191
|
-
(--|&\#821[12];)\]</ref>,?\s*
|
192
|
-
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
|
193
|
-
.freeze
|
194
|
-
|
195
|
-
ISO_REF_ALL_PARTS =
|
196
|
-
%r{^<ref\sid="(?<anchor>[^"]+)">
|
197
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
|
198
|
-
(:(?<year>--|&\#821[12];|[0-9][0-9-]+))?\s
|
199
|
-
\(all\sparts\)\]</ref>,?\s*
|
200
|
-
(<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm.freeze
|
201
|
-
|
202
|
-
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
203
|
-
\[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
|
204
|
-
([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
|
205
|
-
.freeze
|
206
|
-
|
207
|
-
def reference1_matches(item)
|
208
|
-
matched = ISO_REF.match item
|
209
|
-
matched2 = ISO_REF_NO_YEAR.match item
|
210
|
-
matched3 = ISO_REF_ALL_PARTS.match item
|
211
|
-
[matched, matched2, matched3]
|
212
|
-
end
|
213
|
-
|
214
|
-
def reference1(node, item, xml)
|
215
|
-
matched, matched2, matched3 = reference1_matches(item)
|
216
|
-
if matched3.nil? && matched2.nil? && matched.nil?
|
217
|
-
refitem(xml, item, node)
|
218
|
-
elsif !matched.nil? then isorefmatches(xml, matched)
|
219
|
-
elsif !matched2.nil? then isorefmatches2(xml, matched2)
|
220
|
-
elsif !matched3.nil? then isorefmatches3(xml, matched3)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/ref"
|
@@ -1,143 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Section
|
4
|
-
def in_biblio?
|
5
|
-
@biblio
|
6
|
-
end
|
7
|
-
|
8
|
-
def in_norm_ref?
|
9
|
-
@norm_ref
|
10
|
-
end
|
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
|
-
|
18
|
-
def bibliography_parse(attrs, xml, node)
|
19
|
-
x = biblio_prep(attrs, xml, node) and return x
|
20
|
-
@biblio = true
|
21
|
-
attrs = attrs.merge(normative: node.attr("normative") || false)
|
22
|
-
xml.references **attr_code(attrs) do |xml_section|
|
23
|
-
xml_section.title { |t| t << node.title }
|
24
|
-
xml_section << node.content
|
25
|
-
end
|
26
|
-
@biblio = false
|
27
|
-
end
|
28
|
-
|
29
|
-
def bibitem_parse(attrs, xml, node)
|
30
|
-
norm_ref = @norm_ref
|
31
|
-
biblio = @biblio
|
32
|
-
@biblio = false
|
33
|
-
@norm_ref = false
|
34
|
-
ret = clause_parse(attrs, xml, node)
|
35
|
-
@biblio = biblio
|
36
|
-
@norm_ref = norm_ref
|
37
|
-
ret
|
38
|
-
end
|
39
|
-
|
40
|
-
def norm_ref_parse(attrs, xml, node)
|
41
|
-
x = biblio_prep(attrs, xml, node) and return x
|
42
|
-
@norm_ref = true
|
43
|
-
attrs = attrs.merge(normative: node.attr("normative") || true)
|
44
|
-
xml.references **attr_code(attrs) do |xml_section|
|
45
|
-
xml_section.title { |t| t << node.title }
|
46
|
-
xml_section << node.content
|
47
|
-
end
|
48
|
-
@norm_ref = false
|
49
|
-
end
|
50
|
-
|
51
|
-
def biblio_prep(attrs, xml, node)
|
52
|
-
if node.option? "bibitem"
|
53
|
-
bibitem_parse(attrs, xml, node)
|
54
|
-
else
|
55
|
-
node.attr("style") == "bibliography" or
|
56
|
-
@log.add("AsciiDoc Input", node,
|
57
|
-
"Section not marked up as [bibliography]!")
|
58
|
-
nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def global_ievcache_name
|
63
|
-
"#{Dir.home}/.iev/cache"
|
64
|
-
end
|
65
|
-
|
66
|
-
def local_ievcache_name(cachename)
|
67
|
-
return nil if cachename.nil?
|
68
|
-
|
69
|
-
cachename += "_iev" unless cachename.empty?
|
70
|
-
cachename = "iev" if cachename.empty?
|
71
|
-
"#{cachename}/cache"
|
72
|
-
end
|
73
|
-
|
74
|
-
def fetch_ref(xml, code, year, **opts)
|
75
|
-
return nil if opts[:no_year]
|
76
|
-
|
77
|
-
code = code.sub(/^\([^)]+\)/, "")
|
78
|
-
hit = @bibdb&.fetch(code, year, opts)
|
79
|
-
return nil if hit.nil?
|
80
|
-
|
81
|
-
xml.parent.add_child(smart_render_xml(hit, code, opts))
|
82
|
-
xml
|
83
|
-
rescue RelatonBib::RequestError
|
84
|
-
@log.add("Bibliography", nil, "Could not retrieve #{code}: "\
|
85
|
-
"no access to online site")
|
86
|
-
nil
|
87
|
-
end
|
88
|
-
|
89
|
-
def emend_biblio(xml, code, title, usrlbl)
|
90
|
-
unless xml.at("/bibitem/docidentifier[not(@type = 'DOI')][text()]")
|
91
|
-
@log.add("Bibliography", nil,
|
92
|
-
"ERROR: No document identifier retrieved for #{code}")
|
93
|
-
xml.root << "<docidentifier>#{code}</docidentifier>"
|
94
|
-
end
|
95
|
-
unless xml.at("/bibitem/title[text()]")
|
96
|
-
@log.add("Bibliography", nil,
|
97
|
-
"ERROR: No title retrieved for #{code}")
|
98
|
-
xml.root << "<title>#{title || '(MISSING TITLE)'}</title>"
|
99
|
-
end
|
100
|
-
usrlbl and xml.at("/bibitem/docidentifier").next =
|
101
|
-
"<docidentifier type='metanorma'>#{mn_code(usrlbl)}</docidentifier>"
|
102
|
-
end
|
103
|
-
|
104
|
-
def smart_render_xml(xml, code, opts)
|
105
|
-
xml.respond_to? :to_xml or return nil
|
106
|
-
xml = Nokogiri::XML(xml.to_xml(lang: opts[:lang]))
|
107
|
-
emend_biblio(xml, code, opts[:title], opts[:usrlbl])
|
108
|
-
xml.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
|
109
|
-
xml.traverse do |n|
|
110
|
-
n.text? and n.replace(Metanorma::Utils::smartformat(n.text))
|
111
|
-
end
|
112
|
-
xml.to_xml.sub(/<\?[^>]+>/, "")
|
113
|
-
end
|
114
|
-
|
115
|
-
def init_bib_caches(node)
|
116
|
-
return if @no_isobib
|
117
|
-
|
118
|
-
global = !@no_isobib_cache && !node.attr("local-cache-only")
|
119
|
-
local = node.attr("local-cache") || node.attr("local-cache-only")
|
120
|
-
local = nil if @no_isobib_cache
|
121
|
-
@bibdb = Relaton::DbCache.init_bib_caches(
|
122
|
-
local_cache: local,
|
123
|
-
flush_caches: node.attr("flush-caches"),
|
124
|
-
global_cache: global,
|
125
|
-
)
|
126
|
-
end
|
127
|
-
|
128
|
-
def init_iev_caches(node)
|
129
|
-
unless @no_isobib_cache || @no_isobib
|
130
|
-
node.attr("local-cache-only") or
|
131
|
-
@iev_globalname = global_ievcache_name
|
132
|
-
@iev_localname = local_ievcache_name(node.attr("local-cache") ||
|
133
|
-
node.attr("local-cache-only"))
|
134
|
-
if node.attr("flush-caches")
|
135
|
-
FileUtils.rm_f @iev_globalname unless @iev_globalname.nil?
|
136
|
-
FileUtils.rm_f @iev_localname unless @iev_localname.nil?
|
137
|
-
end
|
138
|
-
end
|
139
|
-
# @iev = Iev::Db.new(globalname, localname) unless @no_isobib
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/ref_sect"
|
@@ -1,90 +1,3 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "mime/types"
|
4
|
-
require "base64"
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/reqt"
|
5
3
|
|
6
|
-
module Asciidoctor
|
7
|
-
module Standoc
|
8
|
-
module Blocks
|
9
|
-
def reqt_subpart(name)
|
10
|
-
%w(specification measurement-target verification import label title
|
11
|
-
description component subject inherit classification).include? name
|
12
|
-
end
|
13
|
-
|
14
|
-
def reqt_subpart_attrs(node, name)
|
15
|
-
klass = node.attr("class") || "component"
|
16
|
-
attr_code(keep_attrs(node)
|
17
|
-
.merge(exclude: node.option?("exclude"),
|
18
|
-
type: node.attr("type"),
|
19
|
-
class: name == "component" ? klass : nil))
|
20
|
-
end
|
21
|
-
|
22
|
-
def requirement_subpart(node)
|
23
|
-
name = node.role || node.attr("style")
|
24
|
-
noko do |xml|
|
25
|
-
xml.send name, **reqt_subpart_attrs(node, name) do |o|
|
26
|
-
o << node.content
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def req_classif_parse(classif)
|
32
|
-
ret = []
|
33
|
-
HTMLEntities.new.decode(classif).split(/;\s*/).each do |c|
|
34
|
-
c1 = c.split(/:\s*/)
|
35
|
-
next unless c1.size == 2
|
36
|
-
|
37
|
-
c1[1].split(/,\s*/).each { |v| ret << [c1[0], v] }
|
38
|
-
end
|
39
|
-
ret
|
40
|
-
end
|
41
|
-
|
42
|
-
def requirement_classification(classif, out)
|
43
|
-
req_classif_parse(classif).each do |r|
|
44
|
-
out.classification do |c|
|
45
|
-
c.tag { |t| t << r[0] }
|
46
|
-
c.value { |v| v << r[1] }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def reqt_attrs(node)
|
52
|
-
attr_code(keep_attrs(node).merge(id_unnum_attrs(node)).merge(
|
53
|
-
id: Metanorma::Utils::anchor_or_uuid(node),
|
54
|
-
unnumbered: node.option?("unnumbered") ? "true" : nil,
|
55
|
-
number: node.attr("number"),
|
56
|
-
subsequence: node.attr("subsequence"),
|
57
|
-
obligation: node.attr("obligation"),
|
58
|
-
filename: node.attr("filename"),
|
59
|
-
type: node.attr("type"),
|
60
|
-
model: node.attr("model"),
|
61
|
-
))
|
62
|
-
end
|
63
|
-
|
64
|
-
def requirement_elems(node, out)
|
65
|
-
node.title and out.title { |t| t << node.title }
|
66
|
-
a = node.attr("label") and out.label do |l|
|
67
|
-
l << a
|
68
|
-
end
|
69
|
-
a = node.attr("subject") and csv_split(a)&.each do |subj|
|
70
|
-
out.subject { |s| s << subj }
|
71
|
-
end
|
72
|
-
a = HTMLEntities.new.decode(node.attr("inherit")) and
|
73
|
-
csv_split(a)&.each do |i|
|
74
|
-
out.inherit { |inh| inh << i }
|
75
|
-
end
|
76
|
-
classif = node.attr("classification") and
|
77
|
-
requirement_classification(classif, out)
|
78
|
-
end
|
79
|
-
|
80
|
-
def requirement(node, obligation)
|
81
|
-
noko do |xml|
|
82
|
-
xml.send obligation, **reqt_attrs(node) do |ex|
|
83
|
-
requirement_elems(node, ex)
|
84
|
-
wrap_in_para(node, ex)
|
85
|
-
end
|
86
|
-
end.join("\n")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|