metanorma-ietf 2.4.1 → 2.5.0

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.
@@ -1,167 +1,170 @@
1
1
  require "mathml2asciimath"
2
2
 
3
- module IsoDoc::Ietf
4
- class RfcConvert < ::IsoDoc::Convert
5
- def em_parse(node, out)
6
- out.em do |e|
7
- node.children.each { |n| parse(n, e) }
3
+ module IsoDoc
4
+ module Ietf
5
+ class RfcConvert < ::IsoDoc::Convert
6
+ def em_parse(node, out)
7
+ out.em do |e|
8
+ node.children.each { |n| parse(n, e) }
9
+ end
8
10
  end
9
- end
10
11
 
11
- def sup_parse(node, out)
12
- out.sup do |e|
13
- node.children.each { |n| parse(n, e) }
12
+ def sup_parse(node, out)
13
+ out.sup do |e|
14
+ node.children.each { |n| parse(n, e) }
15
+ end
14
16
  end
15
- end
16
17
 
17
- def sub_parse(node, out)
18
- out.sub do |e|
19
- node.children.each { |n| parse(n, e) }
18
+ def sub_parse(node, out)
19
+ out.sub do |e|
20
+ node.children.each { |n| parse(n, e) }
21
+ end
20
22
  end
21
- end
22
23
 
23
- def tt_parse(node, out)
24
- out.tt do |e|
25
- node.children.each { |n| parse(n, e) }
24
+ def tt_parse(node, out)
25
+ out.tt do |e|
26
+ node.children.each { |n| parse(n, e) }
27
+ end
26
28
  end
27
- end
28
29
 
29
- def strong_parse(node, out)
30
- out.strong do |e|
31
- node.children.each { |n| parse(n, e) }
30
+ def strong_parse(node, out)
31
+ out.strong do |e|
32
+ node.children.each { |n| parse(n, e) }
33
+ end
32
34
  end
33
- end
34
35
 
35
- def bcp14_parse(node, out)
36
- out.bcp14 do |e|
37
- node.children.each { |n| parse(n, e) }
36
+ def bcp14_parse(node, out)
37
+ out.bcp14 do |e|
38
+ node.children.each { |n| parse(n, e) }
39
+ end
38
40
  end
39
- end
40
41
 
41
- def strike_parse(node, out)
42
- node.children.each { |n| parse(n, out) }
43
- end
42
+ def strike_parse(node, out)
43
+ node.children.each { |n| parse(n, out) }
44
+ end
44
45
 
45
- def smallcap_parse(node, out)
46
- node.children.each { |n| parse(n, out) }
47
- end
46
+ def smallcap_parse(node, out)
47
+ node.children.each { |n| parse(n, out) }
48
+ end
48
49
 
49
- def keyword_parse(node, out)
50
- node.children.each { |n| parse(n, out) }
51
- end
50
+ def keyword_parse(node, out)
51
+ node.children.each { |n| parse(n, out) }
52
+ end
52
53
 
53
- def text_parse(node, out)
54
- return if node.nil? || node.text.nil?
55
- text = node.to_s
56
- out << text
57
- end
54
+ def text_parse(node, out)
55
+ return if node.nil? || node.text.nil?
58
56
 
59
- def stem_parse(node, out)
60
- stem = case node["type"]
61
- when "MathML" then MathML2AsciiMath.m2a(node.children.to_xml)
62
- else
63
- HTMLEntities.new.encode(node.text)
64
- end
65
- out << "#{@openmathdelim} #{stem} #{@closemathdelim}"
66
- end
57
+ text = node.to_s
58
+ out << text
59
+ end
67
60
 
68
- def page_break(_out)
69
- end
61
+ def stem_parse(node, out)
62
+ stem = case node["type"]
63
+ when "MathML" then MathML2AsciiMath.m2a(node.children.to_xml)
64
+ else HTMLEntities.new.encode(node.text)
65
+ end
66
+ out << "#{@openmathdelim} #{stem} #{@closemathdelim}"
67
+ end
70
68
 
71
- def pagebreak_parse(_node, _out)
72
- end
69
+ def page_break(_out); end
73
70
 
74
- def br_parse(node, out)
75
- if @sourcecode
71
+ def pagebreak_parse(_node, _out); end
72
+
73
+ def br_parse(_node, out)
76
74
  out.br
77
75
  end
78
- end
79
76
 
80
- def hr_parse(node, out)
81
- end
77
+ def hr_parse(node, out); end
82
78
 
83
- def link_parse(node, out)
84
- out.eref **attr_code(target: node["target"]) do |l|
85
- node.children.each { |n| parse(n, l) }
79
+ def link_parse(node, out)
80
+ out.eref **attr_code(target: node["target"]) do |l|
81
+ node.children.each { |n| parse(n, l) }
82
+ end
86
83
  end
87
- end
88
84
 
89
- def image_parse(node, out, caption)
90
- attrs = { src: node["src"], title: node["title"],
91
- align: node["align"], name: node["filename"],
92
- anchor: node["id"], type: "svg",
93
- alt: node["alt"] }
94
- out.artwork **attr_code(attrs)
95
- image_title_parse(out, caption)
96
- end
85
+ def image_parse(node, out, caption)
86
+ attrs = { src: node["src"], title: node["title"],
87
+ align: node["align"], name: node["filename"],
88
+ anchor: node["id"], type: "svg",
89
+ alt: node["alt"] }
90
+ out.artwork **attr_code(attrs)
91
+ image_title_parse(out, caption)
92
+ end
97
93
 
98
- def image_title_parse(out, caption)
99
- unless caption.nil?
100
- out.t **{ align: "center", keepWithPrevious: "true" } do |p|
101
- p << caption.to_s
94
+ def image_title_parse(out, caption)
95
+ unless caption.nil?
96
+ out.t **{ align: "center", keepWithPrevious: "true" } do |p|
97
+ p << caption.to_s
98
+ end
102
99
  end
103
100
  end
104
- end
105
101
 
106
- def xref_parse(node, out)
107
- out.xref **attr_code(target: node["target"], format: node["format"],
108
- relative: node["relative"]) do |l|
109
- l << get_linkend(node)
110
- end
111
- end
102
+ def xref_parse(node, out)
103
+ out.xref **attr_code(target: node["target"], format: node["format"],
104
+ relative: node["relative"]) do |l|
105
+ l << get_linkend(node)
106
+ end
107
+ end
112
108
 
113
- def get_linkend(node)
114
- contents = node.children.select { |c| !%w{locality localityStack}.include? c.name }.
115
- select { |c| !c.text? || /\S/.match(c) }
116
- !contents.empty? and
117
- return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
118
- ""
119
- end
109
+ def get_linkend(node)
110
+ contents = node.children.reject do |c|
111
+ %w{locality localityStack}.include? c.name
112
+ end
113
+ .select { |c| !c.text? || /\S/.match(c) }
114
+ !contents.empty? and
115
+ return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
116
+ ""
117
+ end
120
118
 
121
- def eref_parse(node, out)
122
- linkend = node.children.reject { |c| %w{locality localityStack}.include? c.name }
123
- relative = node["relative"] ||
124
- node.at(ns(".//locality[@type = 'anchor']/referenceFrom"))&.text || ""
125
- section = eref_clause(node.xpath(ns("./locality | ./localityStack")), nil) || ""
126
- section = "" if relative.empty?
127
- out.relref **attr_code(target: node["bibitemid"], section: section,
128
- relative: relative,
129
- displayFormat: node["displayFormat"]) do |l|
130
- linkend.each { |n| parse(n, l) }
131
- end
132
- end
119
+ def eref_parse(node, out)
120
+ linkend = node.children.reject do |c|
121
+ %w{locality localityStack}.include? c.name
122
+ end
123
+ relative = node["relative"] ||
124
+ node.at(ns(".//locality[@type = 'anchor']/referenceFrom"))&.text || ""
125
+ section = eref_clause(node.xpath(ns("./locality | ./localityStack")),
126
+ nil) || ""
127
+ #section = "" unless relative.empty?
128
+ out.relref **attr_code(target: node["bibitemid"], section: section,
129
+ relative: relative,
130
+ displayFormat: node["displayFormat"]) do |l|
131
+ linkend.each { |n| parse(n, l) }
132
+ end
133
+ end
133
134
 
134
- def eref_clause(refs, target)
135
- ret = []
136
- ret1 = ""
137
- refs.each do |l|
138
- if l.name == "localityStack"
139
- ret << ret1
140
- ret1 = ""
141
- ret << eref_clause1(l.elements, target)
142
- else
143
- ret1 += eref_clause1([l], target)
135
+ def eref_clause(refs, target)
136
+ ret = []
137
+ ret1 = ""
138
+ refs.each do |l|
139
+ if l.name == "localityStack"
140
+ ret << ret1
141
+ ret1 = ""
142
+ ret << eref_clause1(l.elements, target)
143
+ else ret1 += eref_clause1([l], target)
144
+ end
144
145
  end
146
+ ret << ret1
147
+ ret.reject { |c| c.nil? || c.empty? }.join("; ")
145
148
  end
146
- ret << ret1
147
- ret.reject { |c| c.nil? || c.empty? }.join("; ")
148
- end
149
149
 
150
- def eref_clause1(refs, target)
151
- refs.each do |l|
152
- next unless %w(clause section).include? l["type"]
153
- return l&.at(ns("./referenceFrom"))&.text
150
+ def eref_clause1(refs, _target)
151
+ refs.each do |l|
152
+ next unless %w(clause section).include? l["type"]
153
+
154
+ return l&.at(ns("./referenceFrom"))&.text
155
+ end
156
+ ""
154
157
  end
155
- return ""
156
- end
157
158
 
158
- def index_parse(node, out)
159
- out.iref nil, **attr_code(item: node.at(ns("./primary")).text, primary: node["primary"],
160
- subitem: node&.at(ns("./secondary"))&.text)
161
- end
159
+ def index_parse(node, out)
160
+ out.iref nil, **attr_code(item: node.at(ns("./primary")).text,
161
+ primary: node["primary"],
162
+ subitem: node&.at(ns("./secondary"))&.text)
163
+ end
162
164
 
163
- def bookmark_parse(node, out)
164
- out.bookmark nil, **attr_code(anchor: node["id"])
165
+ def bookmark_parse(node, out)
166
+ out.bookmark nil, **attr_code(anchor: node["id"])
167
+ end
165
168
  end
166
169
  end
167
170
  end
@@ -55,15 +55,29 @@ module IsoDoc
55
55
  uris&.each do |u|
56
56
  r.format nil, **attr_code(target: u.text, type: u["type"])
57
57
  end
58
- docidentifiers = bib.xpath(ns("./docidentifier"))
59
- id = render_identifier(bibitem_ref_code(bib))
60
- !id[1].nil? && id[1] != "(NO ID)" and r.refcontent id[1]
61
- docidentifiers&.each do |u|
62
- if %w(DOI IETF).include? u["type"]
63
- r.seriesInfo nil, **attr_code(value: u.text.sub(/^DOI /, ""),
64
- name: u["type"])
65
- end
66
- end
58
+ docidentifier_render(bib, r)
59
+ end
60
+ end
61
+
62
+ def docidentifier_render(bib, out)
63
+ docidentifiers = bib.xpath(ns("./docidentifier"))
64
+ id = render_identifier(bibitem_ref_code(bib))
65
+ !id[1].nil? && id[1] != "(NO ID)" and out.refcontent id[1]
66
+ docidentifiers&.each do |u|
67
+ u["type"] == "DOI" and
68
+ out.seriesInfo nil, **attr_code(value: u.text.sub(/^DOI /, ""),
69
+ name: "DOI")
70
+ u["type"] == "IETF" and docidentifier_ietf(u, out)
71
+ end
72
+ end
73
+
74
+ def docidentifier_ietf(ident, out)
75
+ if /^RFC /.match?(ident.text)
76
+ out.seriesInfo nil, **attr_code(value: ident.text.sub(/^RFC 0*/, ""),
77
+ name: "RFC")
78
+ elsif /^I-D\./.match?(ident.text)
79
+ out.seriesInfo nil, **attr_code(value: ident.text.sub(/^I-D\./, ""),
80
+ name: "Internet-Draft")
67
81
  end
68
82
  end
69
83
 
@@ -1,79 +1,83 @@
1
- module IsoDoc::Ietf
2
- class RfcConvert < ::IsoDoc::Convert
3
- def recommendation_labels(node)
4
- [node.at(ns("./label")), node.at(ns("./title")),
5
- @xrefs.anchor(node['id'], :label, false)]
6
- end
7
-
8
- def recommendation_name(node, out, type)
9
- label, title, lbl = recommendation_labels(node)
10
- out.t **{ keepWithNext: "true" } do |b|
11
- b << (lbl.nil? ? l10n("#{type}:") : l10n("#{type} #{lbl}:"))
1
+ module IsoDoc
2
+ module Ietf
3
+ class RfcConvert < ::IsoDoc::Convert
4
+ def recommendation_labels(node)
5
+ [node.at(ns("./label")), node.at(ns("./title")),
6
+ @xrefs.anchor(node["id"], :label, false)]
12
7
  end
13
- if label || title
14
- out.t **{ keepWithNext: "true" } do |b|
15
- label and label.children.each { |n| parse(n,b) }
16
- b << "#{clausedelim} " if label && title
17
- title and title.children.each { |n| parse(n,b) }
8
+
9
+ def recommendation_name(node, out, type)
10
+ label, title, lbl = recommendation_labels(node)
11
+ out.t **{ keepWithNext: "true" } do |b|
12
+ b << (lbl.nil? ? l10n("#{type}:") : l10n("#{type} #{lbl}:"))
13
+ end
14
+ if label || title
15
+ out.t **{ keepWithNext: "true" } do |b|
16
+ label and label.children.each { |n| parse(n, b) }
17
+ b << "#{clausedelim} " if label && title
18
+ title and title.children.each { |n| parse(n, b) }
19
+ end
18
20
  end
19
21
  end
20
- end
21
22
 
22
- def recommendation_attributes(node, out)
23
- ret = recommendation_attributes1(node)
24
- return if ret.empty?
25
- out.ul do |p|
26
- ret.each do |l|
27
- p.li do |i|
28
- i.em { |e| i << l }
23
+ def recommendation_attributes(node, out)
24
+ ret = recommendation_attributes1(node)
25
+ return if ret.empty?
26
+
27
+ out.ul do |p|
28
+ ret.each do |l|
29
+ p.li do |i|
30
+ i.em { |_e| i << l }
31
+ end
29
32
  end
30
33
  end
31
34
  end
32
- end
33
35
 
34
- def recommendation_parse(node, out)
35
- recommendation_name(node, out, @i18n.recommendation)
36
- recommendation_attributes(node, out)
37
- node.children.each do |n|
38
- parse(n, out) unless %w(label title).include? n.name
36
+ def recommendation_parse(node, out)
37
+ recommendation_name(node, out, @i18n.recommendation)
38
+ recommendation_attributes(node, out)
39
+ node.children.each do |n|
40
+ parse(n, out) unless %w(label title).include? n.name
41
+ end
39
42
  end
40
- end
41
43
 
42
- def requirement_parse(node, out)
43
- recommendation_name(node, out, @i18n.requirement)
44
- recommendation_attributes(node, out)
45
- node.children.each do |n|
46
- parse(n, out) unless %w(label title).include? n.name
44
+ def requirement_parse(node, out)
45
+ recommendation_name(node, out, @i18n.requirement)
46
+ recommendation_attributes(node, out)
47
+ node.children.each do |n|
48
+ parse(n, out) unless %w(label title).include? n.name
49
+ end
47
50
  end
48
- end
49
51
 
50
- def permission_parse(node, out)
51
- recommendation_name(node, out, @i18n.permission)
52
- recommendation_attributes(node, out)
53
- node.children.each do |n|
54
- parse(n, out) unless %w(label title).include? n.name
52
+ def permission_parse(node, out)
53
+ recommendation_name(node, out, @i18n.permission)
54
+ recommendation_attributes(node, out)
55
+ node.children.each do |n|
56
+ parse(n, out) unless %w(label title).include? n.name
57
+ end
55
58
  end
56
- end
57
59
 
58
- def inline?(node)
59
- return true if node.first_element_child.nil?
60
- %w(em link eref xref strong tt sup sub strike keyword smallcap
61
- br hr bookmark pagebreak stem origin term preferred admitted
62
- deprecates domain termsource modification).include? node.first_element_child.name
63
- end
60
+ def inline?(node)
61
+ return true if node.first_element_child.nil?
64
62
 
65
- def requirement_component_parse(node, out)
66
- return if node["exclude"] == "true"
67
- out1 = out
68
- if inline?(node)
69
- out.t do |p|
70
- p << "INHERIT: " if node.name == "inherit"
71
- node.children.each { |n| parse(n, p) }
63
+ %w(em link eref xref strong tt sup sub strike keyword smallcap
64
+ br hr bookmark pagebreak stem origin term preferred admitted
65
+ deprecates domain termsource modification)
66
+ .include? node.first_element_child.name
67
+ end
68
+
69
+ def requirement_component_parse(node, out)
70
+ return if node["exclude"] == "true"
71
+
72
+ if inline?(node)
73
+ out.t do |p|
74
+ p << "INHERIT: " if node.name == "inherit"
75
+ node.children.each { |n| parse(n, p) }
76
+ end
77
+ else
78
+ node.children.each { |n| parse(n, out) }
72
79
  end
73
- else
74
- node.children.each { |n| parse(n, out) }
75
80
  end
76
81
  end
77
82
  end
78
83
  end
79
-
@@ -52,6 +52,8 @@ module IsoDoc::Ietf
52
52
  case node.name
53
53
  when "bcp14" then bcp14_parse(node, out)
54
54
  when "concept" then concept_parse(node, out)
55
+ when "verbaldefinition", "nonverbalrepresentation"
56
+ node.elements.each { |n| parse(n, out) }
55
57
  else
56
58
  text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
57
59
  out.t { |p| p << text }
@@ -1,63 +1,70 @@
1
- module IsoDoc::Ietf
2
- class RfcConvert < ::IsoDoc::Convert
3
- def definition_parse(node, out)
4
- node.children.each { |n| parse(n, out) }
5
- end
1
+ module IsoDoc
2
+ module Ietf
3
+ class RfcConvert < ::IsoDoc::Convert
4
+ def definition_parse(node, out)
5
+ node.children.each { |n| parse(n, out) }
6
+ end
6
7
 
7
- def modification_parse(node, out)
8
- para = node.at(ns("./p"))
9
- out << " -- "
10
- para.children.each { |n| parse(n, out) }
11
- end
8
+ def modification_parse(node, out)
9
+ para = node.at(ns("./p"))
10
+ out << " -- "
11
+ para.children.each { |n| parse(n, out) }
12
+ end
12
13
 
13
- def deprecated_term_parse(node, out)
14
- out.t do |p|
15
- p << l10n("#{@i18n.deprecated}: ")
16
- node.children.each { |c| parse(c, p) }
14
+ def deprecated_term_parse(node, out)
15
+ name = node.at(ns(".//name"))
16
+ out.t do |p|
17
+ p << l10n("#{@i18n.deprecated}: ")
18
+ name.children.each { |c| parse(c, p) }
19
+ end
17
20
  end
18
- end
19
21
 
20
- def admitted_term_parse(node, out)
21
- out.t do |p|
22
- node.children.each { |c| parse(c, p) }
22
+ def admitted_term_parse(node, out)
23
+ name = node.at(ns(".//name"))
24
+ out.t do |p|
25
+ name.children.each { |c| parse(c, p) }
26
+ end
23
27
  end
24
- end
25
28
 
26
- def term_parse(node, out)
27
- out.name do |p|
28
- node.children.each { |n| parse(n, p) }
29
+ def term_parse(node, out)
30
+ name = node.at(ns(".//name"))
31
+ out.name do |p|
32
+ name.children.each { |n| parse(n, p) }
33
+ end
29
34
  end
30
- end
31
35
 
32
- def termnote_parse(node, out)
33
- note_parse(node, out)
34
- end
36
+ def termnote_parse(node, out)
37
+ note_parse(node, out)
38
+ end
35
39
 
36
- def termref_parse(node, out)
37
- out.t do |p|
38
- p << "SOURCE: "
39
- node.children.each { |n| parse(n, p) }
40
+ def termref_parse(node, out)
41
+ out.t do |p|
42
+ p << "SOURCE: "
43
+ node.children.each { |n| parse(n, p) }
44
+ end
40
45
  end
41
- end
42
46
 
43
- def termdef_parse(node, out)
44
- set_termdomain("")
45
- clause_parse(node, out)
46
- end
47
+ def termdef_parse(node, out)
48
+ set_termdomain("")
49
+ node.xpath(ns("./definition")).size > 1 and
50
+ IsoDoc::PresentationXMLConvert.new({}).multidef(node)
51
+ clause_parse(node, out)
52
+ end
47
53
 
48
- def termdocsource_parse(_node, _out); end
54
+ def termdocsource_parse(_node, _out); end
49
55
 
50
- def concept_parse(node, out)
51
- if d = node.at(ns("./renderterm"))
52
- out.em do |em|
53
- d.children.each { |n| parse(n, em) }
56
+ def concept_parse(node, out)
57
+ if d = node.at(ns("./renderterm"))
58
+ out.em do |em|
59
+ d.children.each { |n| parse(n, em) }
60
+ end
61
+ out << " "
54
62
  end
55
- out << " "
63
+ out << "[term defined in "
64
+ r = node.at(ns("./xref | ./eref | ./termref"))
65
+ parse(r, out)
66
+ out << "]"
56
67
  end
57
- out << "[term defined in "
58
- r = node.at(ns("./xref | ./eref | ./termref"))
59
- parse(r, out)
60
- out << "]"
61
68
  end
62
69
  end
63
70
  end
@@ -165,7 +165,7 @@ module IsoDoc
165
165
  def seriesInfo_check(xml)
166
166
  ret = []
167
167
  xml.root["ipr"] == "none" and return []
168
- rfcinfo = xml.at("//seriesInfo[@name = 'RFC']")
168
+ rfcinfo = xml.at("//front//seriesInfo[@name = 'RFC']")
169
169
  rfcnumber = xml.root["number"]
170
170
  rfcinfo && rfcnumber && rfcnumber != rfcinfo["value"] and
171
171
  ret << "Mismatch between <rfc number='#{rfcnumber}'> "\
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ietf
3
- VERSION = "2.4.1".freeze
3
+ VERSION = "2.5.0".freeze
4
4
  end
5
5
  end
@@ -35,11 +35,9 @@ Gem::Specification.new do |spec|
35
35
  spec.require_paths = ["lib"]
36
36
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
37
37
 
38
- spec.add_dependency "isodoc", "~> 1.7.0"
39
38
  spec.add_dependency "mathml2asciimath"
40
- spec.add_dependency "metanorma-standoc", "~> 1.10.0"
41
39
  spec.add_dependency "metanorma-ietf-data"
42
- spec.add_dependency "nokogiri", "~> 1.11.6"
40
+ spec.add_dependency "metanorma-standoc", "~> 1.11.0"
43
41
  spec.add_dependency "open-uri"
44
42
 
45
43
  spec.add_development_dependency "byebug"