metanorma-ietf 2.2.8 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ module IsoDoc::Ietf
43
43
  end
44
44
 
45
45
  def ol_attrs(node)
46
- { anchor: node["id"],
46
+ { anchor: node["id"],
47
47
  spacing: node["spacing"],
48
48
  type: ol_style(node["type"]),
49
49
  group: node["group"],
@@ -73,7 +73,9 @@ module IsoDoc::Ietf
73
73
 
74
74
  def note_label(node)
75
75
  n = @xrefs.get[node["id"]]
76
- return l10n("#{@i18n.note}: ") if n.nil? || n[:label].nil? || n[:label].empty?
76
+ return l10n("#{@i18n.note}: ") if n.nil? || n[:label].nil? ||
77
+ n[:label].empty?
78
+
77
79
  l10n("#{@i18n.note} #{n[:label]}: ")
78
80
  end
79
81
 
@@ -98,7 +100,7 @@ module IsoDoc::Ietf
98
100
  def example_label(node, div, name)
99
101
  n = @xrefs.get[node["id"]]
100
102
  div.t **attr_code(anchor: node["id"], keepWithNext: "true") do |p|
101
- lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example :
103
+ lbl = n.nil? || n[:label].nil? || n[:label].empty? ? @i18n.example :
102
104
  l10n("#{@i18n.example} #{n[:label]}")
103
105
  p << lbl
104
106
  name and !lbl.nil? and p << ": "
@@ -107,15 +109,11 @@ module IsoDoc::Ietf
107
109
  end
108
110
 
109
111
  def sourcecode_parse(node, out)
110
- out.figure **attr_code(anchor: node["id"]) do |div|
111
- name = node&.at(ns("./name"))&.remove and div.name do |n|
112
- name.children.each { |nn| parse(nn, n) }
113
- end
114
- div.sourcecode **attr_code(type: node["lang"], name: node["filename"],
115
- markers: node["markers"],
116
- src: node["src"]) do |s|
117
- node.children.each { |x| parse(x, s) unless x.name == "name" }
118
- end
112
+ out.sourcecode **attr_code(
113
+ anchor: node["id"], type: node["lang"], name: node["filename"],
114
+ markers: node["markers"], src: node["src"]
115
+ ) do |s|
116
+ node.children.each { |x| parse(x, s) unless x.name == "name" }
119
117
  end
120
118
  end
121
119
 
@@ -139,6 +137,7 @@ module IsoDoc::Ietf
139
137
 
140
138
  def formula_where(dl, out)
141
139
  return unless dl
140
+
142
141
  out.t { |p| p << @i18n.where }
143
142
  parse(dl, out)
144
143
  end
@@ -146,7 +145,7 @@ module IsoDoc::Ietf
146
145
  def formula_parse1(node, out)
147
146
  out.t **attr_code(anchor: node["id"]) do |p|
148
147
  parse(node.at(ns("./stem")), p)
149
- lbl = @xrefs.anchor(node['id'], :label, false)
148
+ lbl = @xrefs.anchor(node["id"], :label, false)
150
149
  lbl.nil? or
151
150
  p << " (#{lbl})"
152
151
  end
@@ -157,6 +156,7 @@ module IsoDoc::Ietf
157
156
  formula_where(node.at(ns("./dl")), out)
158
157
  node.children.each do |n|
159
158
  next if %w(stem dl).include? n.name
159
+
160
160
  parse(n, out)
161
161
  end
162
162
  end
@@ -176,7 +176,7 @@ module IsoDoc::Ietf
176
176
  end
177
177
 
178
178
  def admonition_name_parse(_node, div, name)
179
- div.t **{keepWithNext: "true" } do |p|
179
+ div.t **{ keepWithNext: "true" } do |p|
180
180
  name.children.each { |n| parse(n, p) }
181
181
  end
182
182
  end
@@ -200,8 +200,9 @@ module IsoDoc::Ietf
200
200
  end
201
201
  end
202
202
 
203
- def figure_name_parse(node, div, name)
203
+ def figure_name_parse(_node, div, name)
204
204
  return if name.nil?
205
+
205
206
  div.name do |n|
206
207
  name.children.each { |n| parse(n, div) }
207
208
  end
@@ -214,6 +215,7 @@ module IsoDoc::Ietf
214
215
  def figure_parse(node, out)
215
216
  return pseudocode_parse(node, out) if node["class"] == "pseudocode" ||
216
217
  node["type"] == "pseudocode"
218
+
217
219
  @in_figure = true
218
220
  out.figure **attr_code(anchor: node["id"]) do |div|
219
221
  figure_name_parse(node, div, node.at(ns("./name")))
@@ -15,14 +15,14 @@ module IsoDoc::Ietf
15
15
  end
16
16
 
17
17
  # TODO: insert <u>
18
-
18
+
19
19
  def front_cleanup(xmldoc)
20
- xmldoc.xpath("//title").each { |s| s.children = s.text }
21
- xmldoc.xpath("//reference/front[not(author)]").each do |f|
22
- insert = f.at("./seriesInfo[last()]") || f.at("./title")
23
- insert.next = "<author surname='Unknown'/>"
24
- end
20
+ xmldoc.xpath("//title").each { |s| s.children = s.text }
21
+ xmldoc.xpath("//reference/front[not(author)]").each do |f|
22
+ insert = f.at("./seriesInfo[last()]") || f.at("./title")
23
+ insert.next = "<author surname='Unknown'/>"
25
24
  end
25
+ end
26
26
 
27
27
  def table_footnote_cleanup(docxml)
28
28
  docxml.xpath("//table[descendant::fn]").each do |t|
@@ -46,25 +46,19 @@ module IsoDoc::Ietf
46
46
 
47
47
  def figure_cleanup(docxml)
48
48
  figure_postamble(docxml)
49
- figure_wrap_artwork(docxml)
50
49
  figure_unnest(docxml)
51
50
  figure_footnote_cleanup(docxml)
52
51
  end
53
52
 
54
- def figure_wrap_artwork(docxml)
55
- docxml.xpath("//artwork[not(parent::figure)] | "\
56
- "//sourcecode[not(parent::figure)]").each do |a|
57
- a.wrap("<figure></figure>")
58
- end
59
- end
60
-
61
53
  def figure_unnest(docxml)
62
54
  docxml.xpath("//figure[descendant::figure]").each do |f|
63
55
  insert = f
64
56
  f.xpath(".//figure").each do |a|
57
+ title = f.at("./name") and a.children.first.previous = title.remove
65
58
  insert.next = a.remove
66
59
  insert = insert.next_element
67
60
  end
61
+ f.remove
68
62
  end
69
63
  end
70
64
 
@@ -134,8 +128,10 @@ module IsoDoc::Ietf
134
128
 
135
129
  def make_endnotes(docxml)
136
130
  return unless docxml.at("//fn")
137
- endnotes = docxml.at("//back") or
138
- docxml << "<back/>" and endnotes = docxml.at("//back")
131
+
132
+ unless endnotes = docxml.at("//back")
133
+ docxml << "<back/>" and endnotes = docxml.at("//back")
134
+ end
139
135
  endnotes << "<section><name>Endnotes</name></section>"
140
136
  endnotes = docxml.at("//back/section[last()]")
141
137
  end
@@ -146,7 +142,7 @@ module IsoDoc::Ietf
146
142
  t.xpath(".//artwork").each_with_index do |a, i|
147
143
  insert.next = a.dup
148
144
  insert = insert.next
149
- a.replace("[IMAGE #{i+1}]")
145
+ a.replace("[IMAGE #{i + 1}]")
150
146
  end
151
147
  end
152
148
  end
@@ -154,8 +150,8 @@ module IsoDoc::Ietf
154
150
  # for markup in pseudocode
155
151
  def sourcecode_cleanup(docxml)
156
152
  docxml.xpath("//sourcecode").each do |s|
157
- s.children = s.children.to_xml.gsub(%r{<br/>\n}, "\n").
158
- gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
153
+ s.children = s.children.to_xml.gsub(%r{<br/>\n}, "\n")
154
+ .gsub(%r{\s+(<t[ >])}, "\\1").gsub(%r{</t>\s+}, "</t>")
159
155
  sourcecode_remove_markup(s)
160
156
  text = HTMLEntities.new.decode(s.children.to_xml.sub(/\A\n+/, ""))
161
157
  s.children = "<![CDATA[#{text}]]>"
@@ -166,8 +162,10 @@ module IsoDoc::Ietf
166
162
  s.traverse do |n|
167
163
  next if n.text?
168
164
  next if %w(name callout annotation note sourcecode).include? n.name
169
- if n.name == "br" then n.replace("\n")
170
- elsif n.name == "t" then n.replace("\n\n#{n.children}")
165
+
166
+ case n.name
167
+ when "br" then n.replace("\n")
168
+ when "t" then n.replace("\n\n#{n.children}")
171
169
  else
172
170
  n.replace(n.children)
173
171
  end
@@ -177,6 +175,7 @@ module IsoDoc::Ietf
177
175
  def annotation_cleanup(docxml)
178
176
  docxml.xpath("//reference").each do |r|
179
177
  next unless r&.next_element&.name == "aside"
178
+
180
179
  aside = r.next_element
181
180
  aside.name = "annotation"
182
181
  aside.traverse do |n|
@@ -184,7 +183,7 @@ module IsoDoc::Ietf
184
183
  end
185
184
  r << aside
186
185
  end
187
- docxml.xpath("//references/aside").each { |r| r.remove }
186
+ docxml.xpath("//references/aside").each(&:remove)
188
187
  end
189
188
 
190
189
  def deflist_cleanup(docxml)
@@ -211,9 +210,7 @@ module IsoDoc::Ietf
211
210
  end
212
211
 
213
212
  def bookmark_cleanup(docxml)
214
- docxml.xpath("//bookmark").each do |b|
215
- b.remove
216
- end
213
+ docxml.xpath("//bookmark").each(&:remove)
217
214
  end
218
215
 
219
216
  def aside_cleanup(docxml)
@@ -137,6 +137,7 @@ module IsoDoc::Ietf
137
137
  def postal(addr, out)
138
138
  out.postal do |p|
139
139
  if line = addr.at(ns("./formattedAddress"))
140
+ line.xpath(ns(".//br")).each { |br| br.replace("\n") }
140
141
  line.text.split(/\n/).each do |l|
141
142
  p.postalLine l, **attr_code(ascii: l.transliterate)
142
143
  end
@@ -156,7 +156,7 @@ module IsoDoc::Ietf
156
156
  end
157
157
 
158
158
  def index_parse(node, out)
159
- out.iref nil, **attr_code(item: node.at(ns("./primary")).text,
159
+ out.iref nil, **attr_code(item: node.at(ns("./primary")).text, primary: node["primary"],
160
160
  subitem: node&.at(ns("./secondary"))&.text)
161
161
  end
162
162
 
@@ -26,7 +26,7 @@ module IsoDoc::Ietf
26
26
  make_back(html, docxml)
27
27
  end
28
28
  end.join("\n").sub(/<!DOCTYPE[^>]+>\n/, "")
29
- set_pis(docxml, Nokogiri::XML(xml))
29
+ set_pis(docxml, Nokogiri::XML(xml))
30
30
  end
31
31
 
32
32
  def metadata_init(lang, script, i18n)
@@ -34,8 +34,8 @@ module IsoDoc::Ietf
34
34
  end
35
35
 
36
36
  def xref_init(lang, script, klass, i18n, options)
37
- @xrefs = Xref.new(lang, script, klass, i18n, options)
38
- end
37
+ @xrefs = Xref.new(lang, script, klass, i18n, options)
38
+ end
39
39
 
40
40
  def extract_delims(text)
41
41
  @openmathdelim = "$$"
@@ -57,9 +57,14 @@ module IsoDoc::Ietf
57
57
  end
58
58
  end
59
59
 
60
- def textcleanup(docxml)
60
+ def omit_docid_prefix(prefix)
61
+ return true if prefix == "IETF"
62
+ super
63
+ end
64
+
65
+ def textcleanup(docxml)
61
66
  passthrough_cleanup(docxml)
62
- end
67
+ end
63
68
 
64
69
  def postprocess(result, filename, _dir)
65
70
  result = from_xhtml(cleanup(to_xhtml(textcleanup(result)))).
@@ -1,11 +1,14 @@
1
1
  require "metanorma/processor"
2
2
  require "tempfile"
3
3
 
4
+ require "isodoc/ietf/rfc_convert"
5
+
4
6
  module Metanorma
5
7
  module Ietf
6
- class Processor < Metanorma::Processor
8
+ RfcConvert = ::IsoDoc::Ietf::RfcConvert
7
9
 
8
- def initialize
10
+ class Processor < Metanorma::Processor
11
+ def initialize # rubocop:disable Lint/MissingSuper
9
12
  @short = :ietf
10
13
  @input_format = :asciidoc
11
14
  @asciidoctor_backend = :ietf
@@ -18,7 +21,7 @@ module Metanorma
18
21
  rfc: "rfc.xml",
19
22
  html: "html",
20
23
  txt: "txt",
21
- pdf: "pdf"
24
+ pdf: "pdf",
22
25
  }
23
26
  end
24
27
 
@@ -26,15 +29,15 @@ module Metanorma
26
29
  "Metanorma::Ietf #{::Metanorma::Ietf::VERSION}"
27
30
  end
28
31
 
29
- def extract_options(isodocxml)
32
+ def extract_options(_isodocxml)
30
33
  {}
31
34
  end
32
35
 
33
36
  # From mislav: https://stackoverflow.com/questions/2108727
34
37
  # /which-in-ruby-checking-if-program-exists-in-path-from-ruby
35
38
  def which(cmd)
36
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
37
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
39
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
40
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
38
41
  exts.each do |ext|
39
42
  exe = File.join(path, "#{cmd}#{ext}")
40
43
  return exe if File.executable?(exe) && !File.directory?(exe)
@@ -43,49 +46,43 @@ module Metanorma
43
46
  nil
44
47
  end
45
48
 
46
- def use_presentation_xml(ext)
49
+ def use_presentation_xml(_ext)
47
50
  false
48
51
  end
49
52
 
50
- def xml2rfc_present?
51
- !which("xml2rfc").nil?
53
+ def check_xml2rfc_present?(format)
54
+ if which("xml2rfc").nil?
55
+ raise "[metanorma-ietf] Fatal: unable to generate #{format}," \
56
+ " the command `xml2rfc` is not found in path."
57
+ end
52
58
  end
53
59
 
54
- def output(isodoc_node, inname, outname, format, options={})
60
+ def output(isodoc_node, inname, outname, format, options = {})
55
61
  case format
56
62
  when :rfc
57
63
  outname ||= inname.sub(/\.xml$/, ".rfc.xml")
58
- IsoDoc::Ietf::RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
64
+ RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
59
65
  @done_rfc = true
60
-
61
66
  when :txt, :pdf, :html
62
- unless xml2rfc_present?
63
- warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
64
- return
65
- end
67
+ xml2rfc(isodoc_node, inname, outname, format, options)
68
+ else
69
+ super
70
+ end
71
+ end
66
72
 
67
- rfcname = inname.sub(/\.xml$/, ".rfc.xml")
68
- unless @done_rfc && File.exist?(rfcname)
69
- output(isodoc_node, inname, rfcname, :rfc, options)
70
- end
73
+ def xml2rfc(isodoc_node, inname, outname, format, options)
74
+ check_xml2rfc_present?(format)
71
75
 
72
- outext = case format
73
- when :txt then ".txt"
74
- when :pdf then ".pdf"
75
- when :html then ".html"
76
- end
76
+ rfcname = inname.sub(/\.xml$/, ".rfc.xml")
77
+ unless @done_rfc && File.exist?(rfcname)
78
+ output(isodoc_node, inname, rfcname, :rfc, options)
79
+ end
77
80
 
78
- outflag = case format
79
- when :txt then "--text"
80
- when :pdf then "--pdf"
81
- when :html then "--html"
82
- end
81
+ outext = { txt: ".txt", pdf: ".pdf", html: ".html" }[format]
82
+ outflag = { txt: "--text", pdf: "--pdf", html: "--html" }[format]
83
83
 
84
- outname ||= inname.sub(/\.xml$/, outext)
85
- system("xml2rfc #{outflag} #{rfcname} -o #{outname}")
86
- else
87
- super
88
- end
84
+ outname ||= inname.sub(/\.xml$/, outext)
85
+ system("xml2rfc #{outflag} #{rfcname} -o #{outname}")
89
86
  end
90
87
  end
91
88
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ietf
3
- VERSION = "2.2.8".freeze
3
+ VERSION = "2.3.2".freeze
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
 
3
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "metanorma/ietf/version"
6
6
 
@@ -35,17 +35,18 @@ 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.8.0"
39
- spec.add_dependency "isodoc", "~> 1.5.0"
38
+ spec.add_dependency "isodoc", "~> 1.6.0"
40
39
  spec.add_dependency "mathml2asciimath"
40
+ spec.add_dependency "metanorma-standoc", "~> 1.9.0"
41
+ spec.add_dependency "nokogiri", "~> 1.10.4"
41
42
 
42
43
  spec.add_development_dependency "byebug"
43
44
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
44
45
  spec.add_development_dependency "guard", "~> 2.14"
45
46
  spec.add_development_dependency "guard-rspec", "~> 4.7"
46
- spec.add_development_dependency "rake", "~> 12.0"
47
+ spec.add_development_dependency "rake", "~> 13.0"
47
48
  spec.add_development_dependency "rspec", "~> 3.6"
48
- spec.add_development_dependency "rubocop", "~> 0.50"
49
+ spec.add_development_dependency "rubocop", "~> 1.5.2"
49
50
  spec.add_development_dependency "simplecov", "~> 0.15"
50
51
  spec.add_development_dependency "timecop", "~> 0.9"
51
52
  spec.add_development_dependency "vcr", "~> 5.0.0"
metadata CHANGED
@@ -1,57 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.8
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-25 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: metanorma-standoc
14
+ name: isodoc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.0
19
+ version: 1.6.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.8.0
26
+ version: 1.6.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: isodoc
28
+ name: mathml2asciimath
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: metanorma-standoc
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 1.5.0
47
+ version: 1.9.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 1.5.0
54
+ version: 1.9.0
41
55
  - !ruby/object:Gem::Dependency
42
- name: mathml2asciimath
56
+ name: nokogiri
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 1.10.4
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 1.10.4
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: byebug
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +128,14 @@ dependencies:
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '12.0'
131
+ version: '13.0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '12.0'
138
+ version: '13.0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rspec
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +156,14 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0.50'
159
+ version: 1.5.2
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0.50'
166
+ version: 1.5.2
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: simplecov
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -228,8 +242,6 @@ files:
228
242
  - ".hound.yml"
229
243
  - ".oss-guides.rubocop.yml"
230
244
  - ".rspec"
231
- - ".rubocop.ribose.yml"
232
- - ".rubocop.tb.yml"
233
245
  - ".rubocop.yml"
234
246
  - CODE_OF_CONDUCT.md
235
247
  - Gemfile
@@ -301,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
313
  - !ruby/object:Gem::Version
302
314
  version: '0'
303
315
  requirements: []
304
- rubygems_version: 3.0.3
316
+ rubygems_version: 3.1.4
305
317
  signing_key:
306
318
  specification_version: 4
307
319
  summary: metanorma-ietf lets you write IETF documents, such as Internet-Drafts and