metanorma-ietf 2.2.1 → 2.2.6

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.
@@ -0,0 +1,191 @@
1
+ require "jing"
2
+ require "fileutils"
3
+
4
+ module IsoDoc::Ietf
5
+ class RfcConvert < ::IsoDoc::Convert
6
+ def schema_validate(filename)
7
+ begin
8
+ errors = Jing.new(File.join(File.dirname(__FILE__), "v3.rng")).
9
+ validate(filename)
10
+ errors.each do |error|
11
+ warn "RFC XML: Line #{"%06d" % error[:line]}:#{error[:column]} "\
12
+ "#{error[:message]}"
13
+ end
14
+ rescue Jing::Error => e
15
+ abort "Jing failed with error: #{e}"
16
+ end
17
+ end
18
+
19
+ def content_validate(xml, filename)
20
+ err = []
21
+ err += numbered_sections_check(xml)
22
+ err += toc_sections_check(xml)
23
+ err += references_check(xml)
24
+ err += xref_check(xml)
25
+ err += metadata_check(xml)
26
+ return if err.empty?
27
+ FileUtils.mv(filename, "#{filename}.err")
28
+ err.each { |e| warn "RFC XML: #{e}" }
29
+ warn "Cannot continue processing"
30
+ end
31
+
32
+ def label(sect)
33
+ ret = sect&.at("./name")&.text ||
34
+ sect["name"] || sect["anchor"]
35
+ end
36
+
37
+ # 2.46.2. "numbered" Attribute
38
+ def numbered_sections_check(xml)
39
+ ret = []
40
+ xml.xpath("//section[@numbered = 'false']").each do |s1|
41
+ s1.xpath("./section[not(@numbered) or @numbered = 'true']").
42
+ each do |s2|
43
+ ret << "Numbered section #{label(s2)} under unnumbered section "\
44
+ "#{label(s1)}"
45
+ end
46
+ s1.xpath("./following-sibling::*[name() = 'section']"\
47
+ "[not(@numbered) or @numbered = 'true']").each do |s2|
48
+ ret << "Numbered section #{label(s2)} following unnumbered section "\
49
+ "#{label(s1)}"
50
+ end
51
+ end
52
+ ret
53
+ end
54
+
55
+ # 5.2.7. Section "toc" attribute
56
+ def toc_sections_check(xml)
57
+ ret = []
58
+ xml.xpath("//section[@toc = 'exclude']").each do |s1|
59
+ s1.xpath(".//section[@toc = 'include']").each do |s2|
60
+ ret << "Section #{label(s2)} with toc=include is included in "\
61
+ "section #{label(s1)} with toc=exclude"
62
+ end
63
+ end
64
+ ret
65
+ end
66
+
67
+ # 5.4.3 <reference> "target" Insertion
68
+ # 5.4.2.4 "Table of Contents" Insertion
69
+ def references_check(xml)
70
+ ret = []
71
+ xml.xpath("//reference[not(@target)]").each do |s|
72
+ s.xpath(".//seriesInfo[@name = 'RFC' or @name = 'Internet-Draft' "\
73
+ "or @name = 'DOI'][not(@value)]").each do |s1|
74
+ ret << "for reference #{s['anchor']}, the seriesInfo with "\
75
+ "name=#{s1['name']} has been given no value"
76
+ end
77
+ end
78
+ xml.xpath("//references | //section").each do |s|
79
+ s.at("./name") or ret << "Cannot generate table of contents entry "\
80
+ "for #{label(s)}, as it has no title"
81
+ end
82
+ ret
83
+ end
84
+
85
+ # 5.4.8.2. "derivedContent" Insertion (without Content)
86
+ def xref_check(xml)
87
+ ret = []
88
+ xml.xpath("//xref | //relref").each do |x|
89
+ t = xml.at(".//*[@anchor = '#{x['target']}']") ||
90
+ xml.at(".//*[@pn = '#{x['target']}']") or
91
+ ret << "#{x.name} target #{x['target']} does not exist in the document"
92
+ next unless t
93
+ x.delete("relative") if x["relative"]&.empty?
94
+ x.delete("section") if x["section"]&.empty?
95
+ if x["format"] == "title" && t.name == "reference"
96
+ t.at("./front/title") or
97
+ ret << "reference #{t['anchor']} has been referenced by #{x.name} "\
98
+ "with format=title, but the reference has no title"
99
+ end
100
+ if x["format"] == "counter" && !%w(section table figure li
101
+ reference references t dt).include?(t.name)
102
+ ret << "#{x.to_xml} with format=counter is only allowed for "\
103
+ "clauses, tables, figures, list entries, definition terms, "\
104
+ "paragraphs, bibliographies, and bibliographic entries"
105
+ end
106
+ if x["format"] == "counter" && t.name == "reference" && !x["section"]
107
+ ret << "reference #{t['anchor']} has been referenced by xref "\
108
+ "#{x.to_xml} with format=counter, which requires a "\
109
+ "section attribute"
110
+ end
111
+ if x["format"] == "counter" && t.name == "li" && t.parent.name != "ol"
112
+ ret << "#{x.to_xml} with format=counter refers to an unnumbered "\
113
+ "list entry"
114
+ end
115
+ if x["format"] == "title" && %w(u author contact).include?(t.name)
116
+ ret << "#{x.to_xml} with format=title cannot reference a "\
117
+ "<#{t.name}> element"
118
+ end
119
+ if x["relative"] && !x["section"]
120
+ ret << "#{x.to_xml} with relative attribute requires a section "\
121
+ "attribute"
122
+ end
123
+ if (x["section"]) && t.name != "reference"
124
+ ret << "#{x.to_xml} has a section attribute, but #{x['target']} "\
125
+ "points to a #{t.name}"
126
+ end
127
+ if (x["relative"]) && t.name != "reference"
128
+ ret << "#{x.to_xml} has a relative attribute, but #{x['target']} "\
129
+ "points to a #{t.name}"
130
+ end
131
+ if !x["relative"] && x["section"]
132
+ unless t.at(".//seriesInfo[@name = 'RFC' or @name = "\
133
+ "'Internet-Draft']")
134
+ ret << "#{x.to_xml} must use a relative attribute, "\
135
+ "since it does not point to a RFC or Internet-Draft reference"
136
+ end
137
+ end
138
+ if x["relative"]
139
+ unless t.at(".//seriesInfo[@name = 'RFC' or @name = "\
140
+ "'Internet-Draft']") || t["target"]
141
+ ret << "need an explicit target= URL attribute in the reference "\
142
+ "pointed to by #{x.to_xml}"
143
+ end
144
+ end
145
+ end
146
+ ret
147
+ end
148
+
149
+ def metadata_check(xml)
150
+ ret = []
151
+ ret += link_check(xml)
152
+ ret += seriesInfo_check(xml)
153
+ ret += ipr_check(xml)
154
+ ret
155
+ end
156
+
157
+ # 5.6.3. <link> Processing
158
+ def link_check(xml)
159
+ l = xml&.at("//link[@rel = 'convertedFrom']")&.text
160
+ !l || %r{^https://datatracker\.ietf\.org/doc/draft-}.match(l) or
161
+ return ["<link rel='convertedFrom'> (:derived-from: document "\
162
+ "attribute) must start with "\
163
+ "https://datatracker.ietf.org/doc/draft-"]
164
+ []
165
+ end
166
+
167
+ # 5.2.2. "seriesInfo" Insertion
168
+ def seriesInfo_check(xml)
169
+ ret = []
170
+ xml.root["ipr"] == "none" and return []
171
+ rfcinfo = xml.at("//seriesInfo[@name = 'RFC']")
172
+ rfcnumber = xml.root["number"]
173
+ rfcinfo && rfcnumber && rfcnumber != rfcinfo["value"] and
174
+ ret << "Mismatch between <rfc number='#{rfcnumber}'> (:docnumber: NUMBER) "\
175
+ "and <seriesInfo name='RFC' value='#{rfcinfo['value']}'> "\
176
+ "(:intended-series: TYPE NUMBER)"
177
+ rfcinfo && !/^\d+$/.match(rfcnumber) and
178
+ ret << "RFC identifier <rfc number='#{rfcnumber}'> (:docnumber: NUMBER) "\
179
+ "must be a number"
180
+ ret
181
+ end
182
+
183
+ # 5.4.2.3. "Copyright Notice" Insertion
184
+ def ipr_check(xml)
185
+ xml.root["ipr"] or return ["Missing ipr attribute on <rfc> element (:ipr:)"]
186
+ /trust200902$/.match(xml.root["ipr"]) or
187
+ return ["Unknown ipr attribute on <rfc> element (:ipr:): #{xml.root['ipr']}"]
188
+ []
189
+ end
190
+ end
191
+ end
@@ -58,42 +58,31 @@ module Metanorma
58
58
  IsoDoc::Ietf::RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
59
59
  @done_rfc = true
60
60
 
61
- when :txt
61
+ when :txt, :pdf, :html
62
62
  unless xml2rfc_present?
63
63
  warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
64
64
  return
65
65
  end
66
66
 
67
67
  rfcname = inname.sub(/\.xml$/, ".rfc.xml")
68
- output(isodoc_node, inname, rfcname, :rfc, options) unless @done_rfc
69
-
70
- outname ||= inname.sub(/\.xml$/, ".txt")
71
- system("xml2rfc --text #{rfcname} -o #{outname}")
72
-
73
- when :pdf
74
- unless xml2rfc_present?
75
- warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
76
- return
68
+ unless @done_rfc && File.exist?(rfcname)
69
+ output(isodoc_node, inname, rfcname, :rfc, options)
77
70
  end
78
71
 
79
- rfcname = inname.sub(/\.xml$/, ".rfc.xml")
80
- output(isodoc_node, inname, rfcname, :rfc, options) unless @done_rfc
81
-
82
- outname ||= inname.sub(/\.xml$/, ".pdf")
83
- system("xml2rfc --pdf #{rfcname} -o #{outname}")
84
-
85
- when :html
86
- unless xml2rfc_present?
87
- warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
88
- return
72
+ outext = case format
73
+ when :txt then ".txt"
74
+ when :pdf then ".pdf"
75
+ when :html then ".html"
89
76
  end
90
77
 
91
- rfcname = inname.sub(/\.xml$/, ".rfc.xml")
92
- output(isodoc_node, inname, rfcname, :rfc, options) unless @done_rfc
93
-
94
- outname ||= inname.sub(/\.xml$/, ".html")
95
- system("xml2rfc --html #{rfcname} -o #{outname}")
78
+ outflag = case format
79
+ when :txt then "--text"
80
+ when :pdf then "--pdf"
81
+ when :html then "--html"
82
+ end
96
83
 
84
+ outname ||= inname.sub(/\.xml$/, outext)
85
+ system("xml2rfc #{outflag} #{rfcname} -o #{outname}")
97
86
  else
98
87
  super
99
88
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ietf
3
- VERSION = "2.2.1".freeze
3
+ VERSION = "2.2.6".freeze
4
4
  end
5
5
  end
@@ -35,8 +35,8 @@ Gem::Specification.new do |spec|
35
35
  spec.require_paths = ["lib"]
36
36
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
37
37
 
38
- spec.add_dependency "metanorma-standoc", "~> 1.5.0"
39
- spec.add_dependency "isodoc", "~> 1.2.0"
38
+ spec.add_dependency "metanorma-standoc", "~> 1.7.0"
39
+ spec.add_dependency "isodoc", "~> 1.4.0"
40
40
  spec.add_dependency "mathml2asciimath"
41
41
 
42
42
  spec.add_development_dependency "byebug"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-standoc
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.0
19
+ version: 1.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.0
26
+ version: 1.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: isodoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.0
33
+ version: 1.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.0
40
+ version: 1.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mathml2asciimath
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -223,9 +223,7 @@ executables: []
223
223
  extensions: []
224
224
  extra_rdoc_files: []
225
225
  files:
226
- - ".github/workflows/macos.yml"
227
- - ".github/workflows/ubuntu.yml"
228
- - ".github/workflows/windows.yml"
226
+ - ".github/workflows/rake.yml"
229
227
  - ".gitignore"
230
228
  - ".hound.yml"
231
229
  - ".oss-guides.rubocop.yml"
@@ -257,10 +255,14 @@ files:
257
255
  - lib/asciidoctor/ietf/isodoc.rng
258
256
  - lib/asciidoctor/ietf/reqt.rng
259
257
  - lib/asciidoctor/ietf/validate.rb
258
+ - lib/isodoc/ietf/SVG-1.2-RFC.rng
260
259
  - lib/isodoc/ietf/blocks.rb
261
260
  - lib/isodoc/ietf/cleanup.rb
262
261
  - lib/isodoc/ietf/footnotes.rb
263
262
  - lib/isodoc/ietf/front.rb
263
+ - lib/isodoc/ietf/i18n-en.yaml
264
+ - lib/isodoc/ietf/i18n.rb
265
+ - lib/isodoc/ietf/init.rb
264
266
  - lib/isodoc/ietf/inline.rb
265
267
  - lib/isodoc/ietf/metadata.rb
266
268
  - lib/isodoc/ietf/references.rb
@@ -269,6 +271,8 @@ files:
269
271
  - lib/isodoc/ietf/section.rb
270
272
  - lib/isodoc/ietf/table.rb
271
273
  - lib/isodoc/ietf/terms.rb
274
+ - lib/isodoc/ietf/v3.rng
275
+ - lib/isodoc/ietf/validation.rb
272
276
  - lib/isodoc/ietf/xref.rb
273
277
  - lib/metanorma-ietf.rb
274
278
  - lib/metanorma/ietf.rb
@@ -1,54 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: macos
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- paths-ignore:
10
- - .github/workflows/ubuntu.yml
11
- - .github/workflows/windows.yml
12
-
13
- jobs:
14
- test-macos:
15
- name: Test on Ruby ${{ matrix.ruby }} macOS
16
- runs-on: macos-latest
17
- continue-on-error: ${{ matrix.experimental }}
18
- strategy:
19
- fail-fast: false
20
- matrix:
21
- ruby: [ '2.6', '2.5', '2.4' ]
22
- experimental: [false]
23
- include:
24
- - ruby: '2.7'
25
- experimental: true
26
- steps:
27
- - uses: actions/checkout@master
28
- - name: Cache xml2rfc
29
- id: cache-xml2rfc
30
- uses: actions/cache@v1
31
- with:
32
- path: ~/.cache/xml2rfc
33
- key: xml2rfc
34
- restore-key: xml2rfc
35
- - name: Use Ruby
36
- uses: actions/setup-ruby@v1
37
- with:
38
- ruby-version: ${{ matrix.ruby }}
39
- - name: Update gems
40
- run: |
41
- sudo gem install bundler --force
42
- bundle install --jobs 4 --retry 3
43
- - name: Use Python
44
- uses: actions/setup-python@v1
45
- with:
46
- python-version: '3.6'
47
- architecture: 'x64'
48
- - name: Install xml2rfc
49
- run: |
50
- pip install xml2rfc
51
- - name: Run specs
52
- run: |
53
- bundle exec rake
54
-
@@ -1,52 +0,0 @@
1
- # Auto-generated by Cimas: Do not edit it manually!
2
- # See https://github.com/metanorma/cimas
3
- name: ubuntu
4
-
5
- on:
6
- push:
7
- branches: [ master ]
8
- pull_request:
9
- paths-ignore:
10
- - .github/workflows/macos.yml
11
- - .github/workflows/windows.yml
12
- jobs:
13
- test-linux:
14
- name: Test on Ruby ${{ matrix.ruby }} Ubuntu
15
- runs-on: ubuntu-latest
16
- continue-on-error: ${{ matrix.experimental }}
17
- strategy:
18
- fail-fast: false
19
- matrix:
20
- ruby: [ '2.6', '2.5', '2.4' ]
21
- experimental: [false]
22
- include:
23
- - ruby: '2.7'
24
- experimental: true
25
- steps:
26
- - uses: actions/checkout@master
27
- - name: Cache xml2rfc
28
- id: cache-xml2rfc
29
- uses: actions/cache@v1
30
- with:
31
- path: ~/.cache/xml2rfc
32
- key: xml2rfc
33
- restore-key: xml2rfc
34
- - name: Use Ruby
35
- uses: actions/setup-ruby@v1
36
- with:
37
- ruby-version: ${{ matrix.ruby }}
38
- - name: Update gems
39
- run: |
40
- gem install bundler
41
- bundle install --jobs 4 --retry 3
42
- - name: Use Python
43
- uses: actions/setup-python@v1
44
- with:
45
- python-version: '3.6'
46
- architecture: 'x64'
47
- - name: Install xml2rfc
48
- run: |
49
- pip install xml2rfc
50
- - name: Run specs
51
- run: |
52
- bundle exec rake