metanorma-ietf 1.0.10 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +3 -2
  3. data/.github/workflows/ubuntu.yml +3 -2
  4. data/.github/workflows/windows.yml +4 -3
  5. data/README.adoc +9 -0
  6. data/lib/asciidoctor/ietf/basicdoc.rng +1045 -0
  7. data/lib/asciidoctor/ietf/biblio.rng +1142 -0
  8. data/lib/asciidoctor/ietf/blocks.rb +76 -0
  9. data/lib/asciidoctor/ietf/converter.rb +211 -0
  10. data/lib/asciidoctor/ietf/front.rb +143 -0
  11. data/lib/asciidoctor/ietf/ietf.rng +882 -0
  12. data/lib/asciidoctor/ietf/isodoc.rng +514 -0
  13. data/lib/asciidoctor/ietf/isostandard.rng +860 -0
  14. data/lib/asciidoctor/ietf/reqt.rng +171 -0
  15. data/lib/asciidoctor/ietf/validate.rb +84 -0
  16. data/lib/isodoc/ietf/blocks.rb +215 -0
  17. data/lib/isodoc/ietf/cleanup.rb +220 -0
  18. data/lib/isodoc/ietf/footnotes.rb +70 -0
  19. data/lib/isodoc/ietf/front.rb +232 -0
  20. data/lib/isodoc/ietf/inline.rb +136 -0
  21. data/lib/isodoc/ietf/metadata.rb +62 -0
  22. data/lib/isodoc/ietf/references.rb +129 -0
  23. data/lib/isodoc/ietf/reqt.rb +74 -0
  24. data/lib/isodoc/ietf/rfc_convert.rb +60 -0
  25. data/lib/isodoc/ietf/section.rb +162 -0
  26. data/lib/isodoc/ietf/table.rb +43 -0
  27. data/lib/isodoc/ietf/terms.rb +65 -0
  28. data/lib/metanorma-ietf.rb +2 -1
  29. data/lib/metanorma/ietf/processor.rb +16 -37
  30. data/lib/metanorma/ietf/version.rb +1 -1
  31. data/metanorma-ietf.gemspec +3 -3
  32. metadata +36 -36
  33. data/Gemfile.lock +0 -327
  34. data/lib/asciidoctor/rfc.rb +0 -8
  35. data/lib/asciidoctor/rfc/common/base.rb +0 -544
  36. data/lib/asciidoctor/rfc/common/front.rb +0 -120
  37. data/lib/asciidoctor/rfc/common/validate.rb +0 -31
  38. data/lib/asciidoctor/rfc/v2/base.rb +0 -380
  39. data/lib/asciidoctor/rfc/v2/blocks.rb +0 -299
  40. data/lib/asciidoctor/rfc/v2/converter.rb +0 -60
  41. data/lib/asciidoctor/rfc/v2/front.rb +0 -69
  42. data/lib/asciidoctor/rfc/v2/inline_anchor.rb +0 -111
  43. data/lib/asciidoctor/rfc/v2/lists.rb +0 -135
  44. data/lib/asciidoctor/rfc/v2/table.rb +0 -116
  45. data/lib/asciidoctor/rfc/v2/validate.rng +0 -716
  46. data/lib/asciidoctor/rfc/v3/base.rb +0 -330
  47. data/lib/asciidoctor/rfc/v3/blocks.rb +0 -246
  48. data/lib/asciidoctor/rfc/v3/converter.rb +0 -62
  49. data/lib/asciidoctor/rfc/v3/front.rb +0 -122
  50. data/lib/asciidoctor/rfc/v3/inline_anchor.rb +0 -89
  51. data/lib/asciidoctor/rfc/v3/lists.rb +0 -176
  52. data/lib/asciidoctor/rfc/v3/svg.rng +0 -9081
  53. data/lib/asciidoctor/rfc/v3/table.rb +0 -65
  54. data/lib/asciidoctor/rfc/v3/validate.rng +0 -2143
@@ -1,330 +0,0 @@
1
- # coding: utf-8
2
-
3
- require_relative "../common/validate"
4
-
5
- module Asciidoctor
6
- module Rfc::V3
7
- module Base
8
- # Syntax:
9
- # =Title
10
- # Author
11
- # :ipr
12
- # :obsoletes
13
- # :updates
14
- # :submissionType
15
- # :indexInclude
16
- # :iprExtract
17
- # :sortRefs
18
- # :symRefs
19
- # :tocInclude
20
- # :tocDepth
21
- #
22
- # ABSTRACT
23
- #
24
- # NOTEs
25
- #
26
- # ==first title
27
- # CONTENT
28
- #
29
- # [bibliography] # start of back matter
30
- # == Bibliography
31
- #
32
- # [appendix] # start of back matter if not already started
33
- # == Appendix
34
- def document(node)
35
- $seen_back_matter = false
36
- # If this is present, then BCP14 keywords in boldface are not assumed to be <bcp14> tags. By default they are.
37
- $bcp_bold = !(node.attr? "no-rfc-bold-bcp14")
38
- $smart_quotes = (node.attr("smart-quotes") != "false")
39
- $xreftext = {}
40
- result = []
41
- result << '<?xml version="1.0" encoding="UTF-8"?>'
42
-
43
- t = Time.now.getutc
44
- preptime = sprintf(
45
- "%04d-%02d-%02dT%02d:%02d:%02dZ",
46
- t.year, t.month, t.day, t.hour, t.min, t.sec
47
- )
48
-
49
- rfc_attributes = {
50
- ipr: node.attr("ipr"),
51
- obsoletes: node.attr("obsoletes"),
52
- updates: node.attr("updates"),
53
- indexInclude: node.attr("index-include"),
54
- iprExtract: node.attr("ipr-extract"),
55
- sortRefs: node.attr("sort-refs"),
56
- symRefs: node.attr("sym-refs"),
57
- tocInclude: node.attr("toc-include"),
58
- tocDepth: node.attr("toc-depth"),
59
- submissionType: node.attr("submission-type") || "IETF",
60
- 'xml:lang': node.attr("xml-lang"),
61
- prepTime: preptime,
62
- version: "3",
63
- 'xmlns:xi': "http://www.w3.org/2001/XInclude",
64
- }
65
-
66
- rfc_open = noko { |xml| xml.rfc **attr_code(rfc_attributes) }.join.gsub(/\/>$/, ">")
67
- result << rfc_open
68
-
69
- result << (link node)
70
-
71
- result << noko { |xml| front node, xml }
72
- result.last.last.gsub! /<\/front>$/, "" # FIXME: this is a hack!
73
- result << "</front><middle1>"
74
-
75
- result << node.content if node.blocks?
76
- result << ($seen_back_matter ? "</back>" : "</middle>")
77
- result << "</rfc>"
78
-
79
- # <middle> needs to move after preamble
80
- result = result.flatten
81
- result = if result.any? { |e| e =~ /<\/front><middle>/ } && result.any? { |e| e =~ /<\/front><middle1>/ }
82
- result.reject { |e| e =~ /<\/front><middle1>/ }
83
- else
84
- result.map { |e| e =~ /<\/front><middle1>/ ? "</front><middle>" : e }
85
- end
86
- ret = result * "\n"
87
- ret = cleanup(ret)
88
- ret1 = Nokogiri::XML(ret)
89
- ret1 = set_pis(node, ret1)
90
- ret1 = insert_biblio(node, ret1) unless node.attr("biblio-dir").nil? || node.attr("biblio-dir").empty?
91
- Asciidoctor::Rfc::Common::Validate::validate(ret1, File.join(File.dirname(__FILE__), "validate.rng"))
92
- ret1 = resolve_references(node, ret1)
93
- ret1.to_xml
94
- end
95
-
96
- def resolve_references(node, doc)
97
- extract_entities(node, doc).each do |entity|
98
- # TODO actual XML
99
- entity[:node].replace("<xi:include href='#{entity[:url]}' parse='text'/>")
100
- end
101
- doc
102
- end
103
-
104
- # Syntax:
105
- # = Title
106
- # Author
107
- # :link href,href rel
108
- def link(node)
109
- result = []
110
- result << noko do |xml|
111
- links = (node.attr("link") || "").split(/,\s*/)
112
- links.each do |link|
113
- matched = /^(?<href>\S+)\s+(?<rel>\S+)$/.match link
114
- link_attributes = {
115
- href: matched.nil? ? link : matched[:href],
116
- rel: matched.nil? ? nil : matched[:rel],
117
- }
118
- xml.link **attr_code(link_attributes)
119
- end
120
- end
121
- result
122
- end
123
-
124
- def inline_break(node)
125
- # <br> is only defined within tables
126
- noko do |xml|
127
- xml << node.text
128
- xml.br if node.parent.context == :table_cell
129
- end.join
130
- end
131
-
132
- BCP_KEYWORDS = [
133
- "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
134
- "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", "OPTIONAL"
135
- ].freeze
136
-
137
- def inline_quoted(node)
138
- noko do |xml|
139
- case node.type
140
- when :emphasis then xml.em node.text
141
- when :strong
142
- if $bcp_bold && BCP_KEYWORDS.include?(node.text)
143
- xml.bcp14 node.text
144
- else
145
- xml.strong node.text
146
- end
147
- when :monospaced then xml.tt node.text
148
- when :double
149
- xml << ($smart_quotes ? "“#{node.text}”" : "\"#{node.text}\"")
150
- when :single
151
- xml << ($smart_quotes ? "‘#{node.text}’" : "'#{node.text}'")
152
- when :superscript then xml.sup node.text
153
- when :subscript then xml.sub node.text
154
- else
155
- # [bcp14]#MUST NOT#
156
- if node.role == "bcp14"
157
- xml.bcp14 node.text.upcase
158
- elsif node.role == "comment"
159
- xml.comment " " + node.text + " "
160
- else
161
- xml << node.text
162
- end
163
- end
164
- end.join
165
- end
166
-
167
- # Syntax:
168
- # [[id]]
169
- # [keepWithNext=true,keepWithPrevious=true] (optional)
170
- # Text
171
- def paragraph(node)
172
- if node.role == "comment"
173
- return noko do |xml|
174
- xml.comment " " + [flatten_rawtext(node)].flatten.join("\n") + " "
175
- end.join("\n")
176
- end
177
-
178
- t_attributes = {
179
- anchor: node.id,
180
- keepWithNext: node.attr("keep-with-next"),
181
- keepWithPrevious: node.attr("keep-with-previous"),
182
- }
183
- return noko do |xml|
184
- xml.t **attr_code(t_attributes) do |xml_t|
185
- xml_t << node.content
186
- end
187
- end.join("\n")
188
- end
189
-
190
- def ref_section(node)
191
- result = []
192
- $processing_reflist = true
193
- references_attributes = {
194
- anchor: node.id,
195
- }
196
-
197
- if node.blocks.empty?
198
- result << noko do |xml|
199
- xml.references **references_attributes do |xml_references|
200
- xml_references.name node.title unless node.title.nil?
201
- end
202
- end
203
- end
204
- node.blocks.each do |block|
205
- if block.context == :section
206
- result << section(block)
207
- elsif block.context == :pass
208
- # we are assuming a single contiguous :pass block of XML
209
- result << noko do |xml|
210
- xml.references **references_attributes do |xml_references|
211
- xml_references.name node.title unless node.title.nil?
212
- # xml_references << reflist(block).join("\n")
213
- # NOTE: we're allowing the user to do more or less whathever
214
- # in the passthrough since the xpath below just fishes out ALL
215
- # <reference>s in an unrooted fragment, regardless of structure.
216
- Nokogiri::XML::DocumentFragment.
217
- parse(block.content).xpath(".//reference").
218
- each { |reference| xml_references << reference.to_xml }
219
- end
220
- end
221
- elsif block.context == :ulist
222
- block.items.each(&:text)
223
- # we only process the item for its displayreferences
224
- end
225
- end
226
-
227
- unless $xreftext.empty? || $seen_back_matter
228
- result = result.unshift($xreftext.keys.map { |k| %(<displayreference target="#{k}" to="#{$xreftext[k]}"/>) })
229
- end
230
- result = result.unshift("</middle><back>") unless $seen_back_matter
231
- $processing_reflist = false
232
- $seen_back_matter = true
233
- result
234
- end
235
-
236
- # Syntax:
237
- # :sectnums: (toggle)
238
- # :sectnums!: (toggle)
239
- # [[id]]
240
- # [removeInRFC=true,toc=include|exclude|default] (optional)
241
- # == title
242
- # Content
243
- #
244
- # [[id]]
245
- # [bibliography]
246
- # == Normative|Informative References
247
- # * [[[ref1]]] Ref [must provide references as list]
248
- # * [[[ref2]]] Ref
249
- def section(node)
250
- if node.attr("style") == "bibliography" ||
251
- node.parent.context == :section && node.parent.attr("style") == "bibliography"
252
- result = ref_section(node)
253
- else
254
- result = []
255
- if node.attr("style") == "appendix"
256
- result << "</middle><back>" unless $seen_back_matter
257
- $seen_back_matter = true
258
- end
259
-
260
- section_attributes = {
261
- anchor: node.id,
262
- removeInRFC: node.attr("remove-in-rfc"),
263
- toc: node.attr("toc"),
264
- numbered: node.numbered
265
- }
266
-
267
- result << noko do |xml|
268
- xml.section **attr_code(section_attributes) do |section_xml|
269
- section_xml.name { |name| name << node.title } unless node.title.nil?
270
- section_xml << node.content
271
- end
272
- end
273
- end
274
- result
275
- end
276
-
277
- # Syntax:
278
- # [[id]]
279
- # .Name
280
- # [link=xxx,align=left|center|right,alt=alt_text,type]
281
- # image::filename[alt,width,height]
282
- # @note ignoring width, height attributes
283
- def image(node)
284
- uri = node.image_uri node.attr("target")
285
- artwork_attributes = {
286
- align: node.attr("align"),
287
- alt: node.alt,
288
- anchor: node.id,
289
- height: node.attr("height"),
290
- name: node.title,
291
- src: uri,
292
- type: (uri =~ /\.svg$/ ? "svg" : "binary-art"),
293
- width: node.attr("width"),
294
- }
295
-
296
- noko do |xml|
297
- if node.parent.context != :example
298
- xml.figure do |xml_figure|
299
- xml_figure.artwork **attr_code(artwork_attributes)
300
- end
301
- else
302
- xml.artwork **attr_code(artwork_attributes)
303
- end
304
- end
305
- end
306
-
307
- # clean up XML
308
- def cleanup(doc)
309
- xmldoc = Nokogiri::XML(doc)
310
- crefs = xmldoc.xpath("//cref")
311
- # any crefs that are direct children of section should become children of the preceding
312
- # paragraph, if it exists; otherwise, they need to be wrapped in a paragraph
313
- crefs.each do |cref|
314
- if cref.parent.name == "section"
315
- prev = cref.previous_element
316
- if !prev.nil? && prev.name == "t"
317
- cref.parent = prev
318
- else
319
- t = Nokogiri::XML::Element.new("t", xmldoc)
320
- cref.before(t)
321
- cref.parent = t
322
- end
323
- end
324
- end
325
- xmldoc = smart_quote_cleanup(xmldoc) unless $smart_quotes
326
- xmldoc.to_xml(encoding: "US-ASCII")
327
- end
328
- end
329
- end
330
- end
@@ -1,246 +0,0 @@
1
- require "htmlentities"
2
- require "uri"
3
-
4
- module Asciidoctor
5
- module Rfc::V3
6
- module Blocks
7
- # Syntax:
8
- # [discrete]
9
- # == Section
10
- def floating_title(node)
11
- noko do |xml|
12
- xml.t { |xml_t| xml_t.strong node.title }
13
- end
14
- end
15
-
16
- # Syntax:
17
- # [[id]]
18
- # .name
19
- # [align=left|center|right,alt=alt_text] (optional)
20
- # ....
21
- # literal
22
- # ....
23
- def literal(node)
24
- artwork_attributes = {
25
- anchor: node.id,
26
- align: node.attr("align"),
27
- type: "ascii-art",
28
- name: node.title,
29
- alt: node.attr("alt"),
30
- }
31
-
32
- # NOTE: html escaping is performed by Nokogiri
33
- artwork_content = "\n" + node.lines.join("\n") + "\n"
34
-
35
- noko do |xml|
36
- if node.parent.context != :example
37
- xml.figure do |xml_figure|
38
- # xml_figure.artwork artwork_content, **attr_code(artwork_attributes)
39
- xml_figure.artwork **attr_code(artwork_attributes) do |a|
40
- a.cdata artwork_content
41
- end
42
- end
43
- else
44
- # xml.artwork artwork_content, **attr_code(artwork_attributes)
45
- xml.artwork **attr_code(artwork_attributes) do |a|
46
- a.cdata artwork_content
47
- end
48
- end
49
- end
50
- end
51
-
52
- # stem is treated as literal, but with center alignment
53
- def stem(node)
54
- artwork_attributes = {
55
- anchor: node.id,
56
- align: node.attr("align") || "center",
57
- type: "ascii-art",
58
- name: node.title,
59
- alt: node.attr("alt"),
60
- }
61
-
62
- # NOTE: html escaping is performed by Nokogiri
63
- artwork_content = "\n" + node.lines.join("\n") + "\n"
64
-
65
- noko do |xml|
66
- if node.parent.context != :example
67
- xml.figure do |xml_figure|
68
- # xml_figure.artwork artwork_content, **attr_code(artwork_attributes)
69
- xml_figure.artwork **attr_code(artwork_attributes) do |a|
70
- a.cdata artwork_content
71
- end
72
- end
73
- else
74
- # xml.artwork artwork_content, **attr_code(artwork_attributes)
75
- xml.artwork **attr_code(artwork_attributes) do |a|
76
- a.cdata artwork_content
77
- end
78
- end
79
- end
80
- end
81
-
82
- # Syntax:
83
- # [[id]]
84
- # [quote, attribution, citation info] # citation info limited to URL
85
- # Text
86
- def quote(node)
87
- cite_value = node.attr("citetitle")
88
- cite_value = nil unless cite_value.to_s =~ URI::DEFAULT_PARSER.make_regexp
89
-
90
- blockquote_attributes = {
91
- anchor: node.id,
92
- quotedFrom: node.attr("attribution"),
93
- cite: cite_value,
94
- }
95
-
96
- noko do |xml|
97
- xml.blockquote **attr_code(blockquote_attributes) do |xml_blockquote|
98
- xml_blockquote << node.content
99
- end
100
- end
101
- end
102
-
103
- # realise as quote() ; <br/> in v3 does not have the applicability of <vspace/>,
104
- # it is restricted to tables
105
- def verse(node)
106
- quote(node)
107
- end
108
-
109
- # Syntax:
110
- # = Title
111
- # Author
112
- # :HEADER
113
- #
114
- # ABSTRACT
115
- #
116
- # NOTE: note
117
- #
118
- # [NOTE]
119
- # .Title (in preamble)
120
- # ====
121
- # Content
122
- # ====
123
- #
124
- # [NOTE,removeInRFC=true] (in preamble)
125
- # [NOTE,display=true|false,source=name] (in body)
126
- # .Title
127
- # ====
128
- # Content
129
- # ====
130
- # @note admonitions within preamble are notes. Elsewhere, they are comments.
131
- def admonition(node)
132
- result = []
133
- if node.parent.context == :preamble
134
- note_attributes = {
135
- removeInRFC: node.attr("remove-in-rfc"),
136
- }
137
-
138
- result << noko do |xml|
139
- xml.note **attr_code(note_attributes) do |xml_note|
140
- xml_note.name node.title unless node.title.nil?
141
- xml_note << HTMLEntities.new.decode([paragraph1(node)].flatten.join("\n"))
142
- end
143
- end
144
- else
145
- cref_attributes = {
146
- anchor: node.id,
147
- display: node.attr("display"),
148
- source: node.attr("source"),
149
- }
150
-
151
- cref_contents = node.blocks? ? flatten(node) : node.content
152
- cref_contents = [cref_contents].flatten.join("\n")
153
- warn <<~WARNING_MESSAGE if node.blocks?
154
- asciidoctor: WARNING (#{current_location(node)}): comment can not contain blocks of text in XML RFC:\n #{node.content}
155
- WARNING_MESSAGE
156
-
157
- result << noko do |xml|
158
- xml.cref **attr_code(cref_attributes) do |xml_cref|
159
- xml_cref << cref_contents
160
- end
161
- end
162
- end
163
- result
164
- end
165
-
166
- # Syntax:
167
- # [[id]]
168
- # ****
169
- # Sidebar
170
- # ****
171
- def sidebar(node)
172
- aside_attributes = {
173
- anchor: node.id,
174
- }
175
- noko do |xml|
176
- xml.aside **attr_code(aside_attributes) do |xml_aside|
177
- xml_aside << node.content
178
- end
179
- end
180
- end
181
-
182
- # Syntax:
183
- # .Title
184
- # ====
185
- # Example
186
- # ====
187
- def example(node)
188
- node.blocks.each do |b|
189
- unless %i{listing image literal stem}.include? b.context
190
- warn "asciidoctor: WARNING (#{current_location(b)}): examples (figures) should only contain listings (sourcecode), images (artwork), or literal (artwork):\n#{b.lines}"
191
- end
192
- end
193
-
194
- figure_attributes = {
195
- anchor: node.id,
196
- }
197
-
198
- noko do |xml|
199
- xml.figure **attr_code(figure_attributes) do |xml_figure|
200
- xml_figure.name node.title if node.title?
201
- # TODO iref
202
- xml_figure << node.content
203
- end
204
- end
205
- end
206
-
207
- # Syntax:
208
- # .name
209
- # [source,type,src=uri] (src is mutually exclusive with listing content) (v3)
210
- # [source,type,src=uri,align,alt] (src is mutually exclusive with listing content) (v2)
211
- # ----
212
- # code
213
- # ----
214
- def listing(node)
215
- sourcecode_attributes = {
216
- anchor: node.id,
217
- align: nil,
218
- alt: nil,
219
- name: node.title,
220
- type: node.attr("language"),
221
- src: node.attr("src"),
222
- }
223
-
224
- # NOTE: html escaping is performed by Nokogiri
225
- sourcecode_content =
226
- sourcecode_attributes[:src].nil? ? "\n" + node.lines.join("\n") + "\n" : ""
227
-
228
- noko do |xml|
229
- if node.parent.context != :example
230
- xml.figure do |xml_figure|
231
- # xml_figure.sourcecode sourcecode_content, **attr_code(sourcecode_attributes)
232
- xml_figure.sourcecode **attr_code(sourcecode_attributes) do |a|
233
- a.cdata sourcecode_content
234
- end
235
- end
236
- else
237
- # xml.sourcecode sourcecode_content, **attr_code(sourcecode_attributes)
238
- xml.sourcecode **attr_code(sourcecode_attributes) do |a|
239
- a.cdata sourcecode_content
240
- end
241
- end
242
- end
243
- end
244
- end
245
- end
246
- end