metanorma-ietf 2.0.10 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,9 +30,22 @@
30
30
  <data type="boolean"/>
31
31
  </attribute>
32
32
  </optional>
33
+ <optional>
34
+ <attribute name="number"/>
35
+ </optional>
33
36
  <optional>
34
37
  <attribute name="subsequence"/>
35
38
  </optional>
39
+ <optional>
40
+ <attribute name="keep-with-next">
41
+ <data type="boolean"/>
42
+ </attribute>
43
+ </optional>
44
+ <optional>
45
+ <attribute name="keep-lines-together">
46
+ <data type="boolean"/>
47
+ </attribute>
48
+ </optional>
36
49
  <attribute name="id">
37
50
  <data type="ID"/>
38
51
  </attribute>
@@ -141,6 +154,16 @@
141
154
  <data type="boolean"/>
142
155
  </attribute>
143
156
  </optional>
157
+ <optional>
158
+ <attribute name="keep-with-next">
159
+ <data type="boolean"/>
160
+ </attribute>
161
+ </optional>
162
+ <optional>
163
+ <attribute name="keep-lines-together">
164
+ <data type="boolean"/>
165
+ </attribute>
166
+ </optional>
144
167
  <oneOrMore>
145
168
  <ref name="BasicBlock"/>
146
169
  </oneOrMore>
@@ -1,8 +1,8 @@
1
1
  module IsoDoc::Ietf
2
2
  class RfcConvert < ::IsoDoc::Convert
3
3
  def para_attrs(node)
4
- { keepWithNext: node["keepWithNext"],
5
- keepWithPrevious: node["keepWithPrevious"],
4
+ { keepWithNext: node["keep-with-next"],
5
+ keepWithPrevious: node["keep-with-previous"],
6
6
  anchor: node["id"] }
7
7
  end
8
8
 
@@ -56,23 +56,25 @@ module IsoDoc::Ietf
56
56
  end
57
57
  end
58
58
 
59
- def dl_attr(node)
59
+ def dl_attrs(node)
60
60
  attr_code(anchor: node["id"],
61
61
  newline: node["newline"],
62
62
  indent: node["indent"],
63
63
  spacing: node["spacing"])
64
64
  end
65
65
 
66
- def dt_parse(dt, term)
66
+ def dt_parse(dt, term)
67
67
  if dt.elements.empty?
68
- term << dt.text
68
+ term << dt.text
69
69
  else
70
70
  dt.children.each { |n| parse(n, term) }
71
71
  end
72
72
  end
73
73
 
74
74
  def note_label(node)
75
- l10n("#{super}: ")
75
+ n = @xrefs.get[node["id"]]
76
+ return l10n("#{@note_lbl}: ") if n.nil? || n[:label].nil? || n[:label].empty?
77
+ l10n("#{@note_lbl} #{n[:label]}: ")
76
78
  end
77
79
 
78
80
  def note_parse(node, out)
@@ -94,7 +96,7 @@ module IsoDoc::Ietf
94
96
  end
95
97
 
96
98
  def example_label(node, div, name)
97
- n = get_anchors[node["id"]]
99
+ n = @xrefs.get[node["id"]]
98
100
  div.t **attr_code(anchor: node["id"], keepWithNext: "true") do |p|
99
101
  lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl :
100
102
  l10n("#{@example_lbl} #{n[:label]}")
@@ -112,8 +114,8 @@ module IsoDoc::Ietf
112
114
  div.sourcecode **attr_code(type: node["lang"], name: node["filename"],
113
115
  markers: node["markers"],
114
116
  src: node["src"]) do |s|
115
- node.children.each { |x| parse(x, s) unless x.name == "name" }
116
- end
117
+ node.children.each { |x| parse(x, s) unless x.name == "name" }
118
+ end
117
119
  end
118
120
  end
119
121
 
@@ -144,12 +146,21 @@ module IsoDoc::Ietf
144
146
  def formula_parse1(node, out)
145
147
  out.t **attr_code(anchor: node["id"]) do |p|
146
148
  parse(node.at(ns("./stem")), p)
147
- lbl = anchor(node['id'], :label, false)
149
+ lbl = @xrefs.anchor(node['id'], :label, false)
148
150
  lbl.nil? or
149
151
  p << " (#{lbl})"
150
152
  end
151
153
  end
152
154
 
155
+ def formula_parse(node, out)
156
+ formula_parse1(node, out)
157
+ formula_where(node.at(ns("./dl")), out)
158
+ node.children.each do |n|
159
+ next if %w(stem dl).include? n.name
160
+ parse(n, out)
161
+ end
162
+ end
163
+
153
164
  def quote_attribution(node)
154
165
  author = node&.at(ns("./author"))&.text
155
166
  source = node&.at(ns("./source/@uri"))&.text
@@ -19,16 +19,20 @@ module IsoDoc::Ietf
19
19
  end
20
20
 
21
21
  def info(isoxml, out)
22
- @meta.keywords isoxml, out
23
22
  @meta.areas isoxml, out
24
23
  super
25
24
  end
26
25
 
26
+ def output_if_translit(text)
27
+ return nil if text.nil?
28
+ text.transliterate != text ? text.transliterate : nil
29
+ end
30
+
27
31
  def title(isoxml, front)
28
32
  title = @meta.get[:doctitle] or return
29
33
  front.title title, **attr_code(abbrev: @meta.get[:docabbrev],
30
- ascii: @meta.get[:docascii] ||
31
- title.transliterate)
34
+ ascii: (@meta.get[:docascii] ||
35
+ output_if_translit(title)))
32
36
  end
33
37
 
34
38
  def seriesinfo(isoxml, front)
@@ -38,7 +42,7 @@ module IsoDoc::Ietf
38
42
 
39
43
  def seriesinfo_attr(isoxml)
40
44
  attr_code(value: @meta.get[:docnumber] || "",
41
- asciiValue: @meta.get[:docnumber]&.transliterate,
45
+ asciiValue: output_if_translit(@meta.get[:docnumber]),
42
46
  status: @meta.get[:stage],
43
47
  stream: isoxml&.at(ns("//bibdata/series[@type = 'stream']/"\
44
48
  "title"))&.text)
@@ -83,9 +87,9 @@ module IsoDoc::Ietf
83
87
 
84
88
  def pers_author_attrs1(ret, full, init, c)
85
89
  full and ret.merge!(attr_code(
86
- asciiFullname: full&.transliterate,
87
- asciiInitials: init&.transliterate,
88
- asciiSurname: c&.at(ns("./surname"))&.text&.transliterate))
90
+ asciiFullname: output_if_translit(full),
91
+ asciiInitials: output_if_translit(init),
92
+ asciiSurname: output_if_translit(c&.at(ns("./surname")))))
89
93
  ret
90
94
  end
91
95
 
@@ -114,8 +118,8 @@ module IsoDoc::Ietf
114
118
  def organization(org, out, show)
115
119
  name = org.at(ns("./name"))&.text
116
120
  out.organization name, **attr_code(
117
- showOnFrontPage: show&.text, ascii: name&.transliterate,
118
- asciiAbbrev: org&.at(ns("./abbreviation"))&.transliterate,
121
+ showOnFrontPage: show&.text, ascii: output_if_translit(name),
122
+ asciiAbbrev: output_if_translit(org.at(ns("./abbreviation"))),
119
123
  abbrev: org.at(ns("./abbreviation")))
120
124
  end
121
125
 
@@ -120,11 +120,15 @@ module IsoDoc::Ietf
120
120
 
121
121
  def eref_parse(node, out)
122
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 || ""
123
125
  section = eref_clause(node.xpath(ns("./locality | ./localityStack")), nil) || ""
126
+ section = "" if relative.empty?
124
127
  out.relref **attr_code(target: node["bibitemid"], section: section,
128
+ relative: relative,
125
129
  displayFormat: node["displayFormat"]) do |l|
126
- linkend.each { |n| parse(n, l) }
127
- end
130
+ linkend.each { |n| parse(n, l) }
131
+ end
128
132
  end
129
133
 
130
134
  def eref_clause(refs, target)
@@ -19,14 +19,6 @@ module IsoDoc
19
19
  # = item describedby convertedfrom alternate
20
20
  end
21
21
 
22
- def keywords(isoxml, _out)
23
- ret = []
24
- isoxml.xpath(ns("//bibdata/keyword")).each do |kw|
25
- ret << kw.text
26
- end
27
- set(:keywords, ret)
28
- end
29
-
30
22
  def areas(isoxml, _out)
31
23
  ret = []
32
24
  isoxml.xpath(ns("//bibdata/ext/area")).each do |kw|
@@ -45,18 +37,18 @@ module IsoDoc
45
37
  wg(xml)
46
38
  end
47
39
 
48
- def wg(xml)
49
- workgroups = []
50
- xml.xpath(ns("//bibdata/ext/editorialgroup/workgroup")).each do |wg|
51
- workgroups << wg.text
40
+ def wg(xml)
41
+ workgroups = []
42
+ xml.xpath(ns("//bibdata/ext/editorialgroup/workgroup")).each do |wg|
43
+ workgroups << wg.text
52
44
  end
53
- set(:wg, workgroups)
45
+ set(:wg, workgroups)
54
46
  end
55
47
 
56
- def doctype(isoxml, _out)
57
- super
58
- set(:doctype, "Rfc") if get[:doctype].nil?
59
- end
48
+ def doctype(isoxml, _out)
49
+ super
50
+ set(:doctype, "Rfc") if get[:doctype].nil?
51
+ end
60
52
  end
61
53
  end
62
54
  end
@@ -50,8 +50,9 @@ module IsoDoc::Ietf
50
50
  r.format nil, **attr_code(target: u.text, type: u["type"])
51
51
  end
52
52
  docidentifiers = b.xpath(ns("./docidentifier"))
53
- id = bibitem_ref_code(b) and id.text != "(NO ID)" and
54
- r.refcontent render_identifier(id)
53
+ id = render_identifier(bibitem_ref_code(b))
54
+ !id[1].nil? and id[1] != "(NO ID)" and
55
+ r.refcontent id[1]
55
56
  docidentifiers&.each do |u|
56
57
  if %w(DOI IETF).include? u["type"]
57
58
  r.seriesInfo nil, **attr_code(value: u.text, name: u["type"])
@@ -67,15 +68,6 @@ module IsoDoc::Ietf
67
68
  end
68
69
  end
69
70
 
70
- def bibitem_ref_code(b)
71
- id = b.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' "\
72
- "or @type = 'ISSN' or @type = 'ISBN' or @type = 'IETF')]"))
73
- return id if id
74
- id = Nokogiri::XML::Node.new("docidentifier", b.document)
75
- id << "(NO ID)"
76
- id
77
- end
78
-
79
71
  def relaton_to_author(b, f)
80
72
  auths = b.xpath(ns("./contributor[xmlns:role/@type = 'author' or "\
81
73
  "xmlns:role/@type = 'editor']"))
@@ -1,5 +1,10 @@
1
1
  module IsoDoc::Ietf
2
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
+
3
8
  def recommendation_name(node, out, type)
4
9
  label, title, lbl = recommendation_labels(node)
5
10
  out.t **{ keepWithNext: "true" } do |b|
@@ -9,11 +9,12 @@ require_relative "./cleanup"
9
9
  require_relative "./footnotes"
10
10
  require_relative "./references"
11
11
  require_relative "./section"
12
+ require_relative "./xref"
12
13
 
13
14
  module IsoDoc::Ietf
14
15
  class RfcConvert < ::IsoDoc::Convert
15
16
  def convert1(docxml, filename, dir)
16
- anchor_names docxml
17
+ @xrefs.parse docxml
17
18
  info docxml, nil
18
19
  xml = noko do |xml|
19
20
  xml.rfc **attr_code(rfc_attributes(docxml)) do |html|
@@ -30,6 +31,10 @@ module IsoDoc::Ietf
30
31
  @meta = Metadata.new(lang, script, labels)
31
32
  end
32
33
 
34
+ def xref_init(lang, script, klass, labels, options)
35
+ @xrefs = Xref.new(lang, script, klass, labels, options)
36
+ end
37
+
33
38
  def extract_delims(text)
34
39
  @openmathdelim = "$$"
35
40
  @closemathdelim = "$$"
@@ -50,10 +55,15 @@ module IsoDoc::Ietf
50
55
  end
51
56
  end
52
57
 
58
+ def textcleanup(docxml)
59
+ passthrough_cleanup(docxml)
60
+ end
61
+
53
62
  def postprocess(result, filename, dir)
54
- result = from_xhtml(cleanup(to_xhtml(result))).sub(/<!DOCTYPE[^>]+>\n/, "").
63
+ result = from_xhtml(cleanup(to_xhtml(textcleanup(result)))).
64
+ sub(/<!DOCTYPE[^>]+>\n/, "").
55
65
  sub(/(<rfc[^<]+? )lang="[^"]+"/, "\\1")
56
- File.open("#{filename}.rfc.xml", "w:UTF-8") { |f| f.write(result) }
66
+ File.open(filename, "w:UTF-8") { |f| f.write(result) }
57
67
  @files_to_delete.each { |f| FileUtils.rm_rf f }
58
68
  end
59
69
 
@@ -66,6 +76,7 @@ module IsoDoc::Ietf
66
76
  super
67
77
  @xinclude = options[:use_xinclude] == "true"
68
78
  @format = :rfc
79
+ @suffix = "rfc.xml"
69
80
  end
70
81
  end
71
82
  end
@@ -60,7 +60,8 @@ module IsoDoc::Ietf
60
60
  {
61
61
  docName: @meta.get[:doctype] == "Internet Draft" ? @meta.get[:docnumber] : nil,
62
62
  number: @meta.get[:doctype].casecmp?("rfc") ? @meta.get[:docnumber] : nil,
63
- category: docxml&.at(ns("//bibdata/series[@type = 'intended']/title"))&.text || "std",
63
+ category: series2category(
64
+ docxml&.at(ns("//bibdata/series[@type = 'intended']/title"))&.text),
64
65
  ipr: docxml&.at(ns("//bibdata/ext/ipr"))&.text,
65
66
  obsoletes: obs,
66
67
  updates: upd,
@@ -78,6 +79,20 @@ module IsoDoc::Ietf
78
79
  }
79
80
  end
80
81
 
82
+ def series2category(series)
83
+ case series&.downcase
84
+ when "standard", "std" then "std"
85
+ when "informational", "info" then "info"
86
+ when "experimental", "exp" then "exp"
87
+ when "bcp" then "bcp"
88
+ when "fyi", "info" then "info"
89
+ when "full-standard" then "std"
90
+ when "historic" then "historic"
91
+ else
92
+ "std"
93
+ end
94
+ end
95
+
81
96
  def xpath_comma(xpath)
82
97
  return nil if xpath.empty?
83
98
  xpath.map { |x| x.text }.join(", ")
@@ -1,12 +1,12 @@
1
1
  module IsoDoc::Ietf
2
2
  class RfcConvert < ::IsoDoc::Convert
3
- def make_table_attr(node)
3
+ def table_attrs(node)
4
4
  attr_code(anchor: node["id"], align: node["align"])
5
5
  end
6
6
 
7
7
  def table_parse(node, out)
8
8
  @in_table = true
9
- out.table **make_table_attr(node) do |t|
9
+ out.table **table_attrs(node) do |t|
10
10
  table_title_parse(node, out)
11
11
  thead_parse(node, t)
12
12
  tbody_parse(node, t)
@@ -48,18 +48,5 @@ module IsoDoc::Ietf
48
48
 
49
49
  def termdocsource_parse(_node, _out)
50
50
  end
51
-
52
- def termnote_anchor_names(docxml)
53
- docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
54
- c = Counter.new
55
- notes = t.xpath(ns(".//termnote"))
56
- notes.each do |n|
57
- next if n["id"].nil? || n["id"].empty?
58
- idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
59
- @anchors[n["id"]] =
60
- anchor_struct(idx, n, @note_xref_lbl, "note", false)
61
- end
62
- end
63
- end
64
51
  end
65
52
  end
@@ -0,0 +1,20 @@
1
+ require "isodoc"
2
+
3
+ module IsoDoc
4
+ module Ietf
5
+ class Xref < IsoDoc::Xref
6
+ def termnote_anchor_names(docxml)
7
+ docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
8
+ c = IsoDoc::XrefGen::Counter.new
9
+ notes = t.xpath(ns(".//termnote"))
10
+ notes.each do |n|
11
+ next if n["id"].nil? || n["id"].empty?
12
+ idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
13
+ @anchors[n["id"]] =
14
+ anchor_struct(idx, n, @labels["note_xref"], "note", false)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -48,14 +48,19 @@ module Metanorma
48
48
  nil
49
49
  end
50
50
 
51
+ def use_presentation_xml(ext)
52
+ false
53
+ end
54
+
51
55
  def xml2rfc_present?
52
56
  !which("xml2rfc").nil?
53
57
  end
54
58
 
55
- def output(isodoc_node, outname, format, options={})
59
+ def output(isodoc_node, inname, outname, format, options={})
56
60
  case format
57
61
  when :rfc
58
- IsoDoc::Ietf::RfcConvert.new(options).convert(outname, isodoc_node)
62
+ outname ||= inname.sub(/\.xml$/, ".rfc.xml")
63
+ IsoDoc::Ietf::RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
59
64
  @done_rfc = true
60
65
 
61
66
  when :txt
@@ -64,9 +69,10 @@ module Metanorma
64
69
  return
65
70
  end
66
71
 
67
- rfcname = outname.sub(/\.txt$/, ".rfc.xml")
68
- output(isodoc_node, outname, :rfc, options) unless @done_rfc
72
+ rfcname = inname.sub(/\.xml$/, ".rfc.xml")
73
+ output(isodoc_node, inname, rfcname, :rfc, options) unless @done_rfc
69
74
 
75
+ outname ||= inname.sub(/\.xml$/, ".txt")
70
76
  system("xml2rfc --text #{rfcname} -o #{outname}")
71
77
 
72
78
  when :pdf
@@ -75,9 +81,10 @@ module Metanorma
75
81
  return
76
82
  end
77
83
 
78
- rfcname = outname.sub(/\.pdf$/, ".rfc.xml")
79
- output(isodoc_node, outname, :rfc, options) unless @done_rfc
84
+ rfcname = inname.sub(/\.xml$/, ".rfc.xml")
85
+ output(isodoc_node, inname, rfcname, :rfc, options) unless @done_rfc
80
86
 
87
+ outname ||= inname.sub(/\.xml$/, ".pdf")
81
88
  system("xml2rfc --pdf #{rfcname} -o #{outname}")
82
89
 
83
90
  when :html
@@ -86,9 +93,10 @@ module Metanorma
86
93
  return
87
94
  end
88
95
 
89
- rfcname = outname.sub(/\.html$/, ".rfc.xml")
90
- output(isodoc_node, outname, :rfc, options) unless @done_rfc
96
+ rfcname = inname.sub(/\.xml$/, ".rfc.xml")
97
+ output(isodoc_node, inname, rfcname, :rfc, options) unless @done_rfc
91
98
 
99
+ outname ||= inname.sub(/\.xml$/, ".html")
92
100
  system("xml2rfc --html #{rfcname} -o #{outname}")
93
101
 
94
102
  else