kramdown-rfc2629 1.7.21 → 1.7.23

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b359e547f2f8f265b1ee961d2956c32073d4a846a4fa813bd9ff8f898d385f08
4
- data.tar.gz: 72ecb5162fc2910ceb62d3ee7df6e6902f1fe15540d2761b1e94ee73c60cffb7
3
+ metadata.gz: 269381d3a05b02772eb68975943dcf119cd9010d9fdcfb4eb5df92886bfa59bb
4
+ data.tar.gz: 2f8c3f406037faaa02bd01f0eda40438a601ddaea49ff4c95ff8bcf168e0572a
5
5
  SHA512:
6
- metadata.gz: a65c817ecab99a017c3335f1e8040ffb37f1e1915e32abea9253cabd7f12014d4176ca2ab8fdd3659ea3d546b9e3ead4c3fd4c7f33ca62f8dd6b3b79bb87606c
7
- data.tar.gz: 226b74d1c1a011bbe8631598d91d01c6defaf228c38735405bd86a36456aba3edc74a3cfc27a1e3e91a3f5aa9a7d8075dd34fa35b1b2082ccddea9b339b5a543
6
+ metadata.gz: 831fa5d0ea40f6f3e7c111160684eb818a6e4837159c2816c9d258c67258249226e5f895bfdb5b512f09af1c593a4176c378e99e395b180fd891409b06635206
7
+ data.tar.gz: f335e96c5bda06e7de555115ed3ae4057964287c24713082d23105ed9b93ddd0a63df6459887a9ae49fca3510fda4fc8fdcf880f588d1703ec2b422f9dc77cb9
@@ -68,10 +68,13 @@ lists.each do |k, v|
68
68
  puts
69
69
  puts "# #{title}"
70
70
  puts "{:unnumbered}"
71
+ puts
72
+ puts "{:compact}"
71
73
  else
72
74
  fail
73
75
  end
74
76
  v.each_with_index do |(ref, ti), n|
77
+ ti.sub!(/,?[\p{Zl}\p{Zp}\p{Cc}].*/, "") # first line of caption only
75
78
  ti = "[#{ti}](##{ref})" if ref
76
79
  puts "#{n+1}. #{ti}"
77
80
  end
@@ -40,6 +40,7 @@ end
40
40
 
41
41
  target = nil
42
42
  dir = nil
43
+ out_type = out_name = nil
43
44
  unfold = true
44
45
  targets = [:list, :files, :zip, :yaml]
45
46
  require 'optparse'
@@ -52,6 +53,10 @@ begin
52
53
  opts.on("-dDIR", "--dir=DIR", "Target directory (default: sourcecode)") do |v|
53
54
  dir = v
54
55
  end
56
+ opts.on("-xTYPE/NAME", "--extract=TYPE/NAME", "Extract single item to stdout") do |v|
57
+ target = :stdout
58
+ out_type, out_name = v.split("/", 2)
59
+ end
55
60
  opts.on("-f", "--[no-]unfold", "RFC8792-unfold (default: yes)") do |v|
56
61
  unfold = v
57
62
  end
@@ -74,8 +79,26 @@ target ||= :list
74
79
  gensym = "unnamed-000"
75
80
  taken = Hash.new { |h, k| h[k] = Hash.new }
76
81
  warned = Hash.new { |h, k| h[k] = Hash.new }
77
- d = REXML::Document.new(ARGF)
78
- REXML::XPath.each(d.root, "//sourcecode|//artwork") do |x|
82
+ filenames = ARGV.inspect
83
+ begin
84
+ d = REXML::Document.new(ARGF)
85
+ dr = d.root
86
+ unless dr
87
+ warn "*** Can't parse: #{filenames}"
88
+ exit(1)
89
+ end
90
+ rescue Errno::ENOENT
91
+ warn "*** Not found: #{filenames}"
92
+ exit(1)
93
+ rescue => e
94
+ begin
95
+ warn "*** Can't parse: #{filenames} (#{e.to_s[0..120]})"
96
+ rescue => e
97
+ warn "*** Can't parse: #{filenames} (#{e.to_s[0..120]})"
98
+ end
99
+ exit(1)
100
+ end
101
+ REXML::XPath.each(dr, "//sourcecode|//artwork") do |x|
79
102
  if ty = x[:type]
80
103
  is_svg = false
81
104
  REXML::XPath.each(x, "svg") do is_svg = true end
@@ -161,6 +184,27 @@ def make_directory_from(dir, taken)
161
184
  end
162
185
 
163
186
  case target
187
+ when :stdout
188
+ if dataset = taken[out_type]
189
+ unless out_name
190
+ case dataset.size
191
+ when 0
192
+ warn "No sourcecodes under #{out_type}"
193
+ exit(1)
194
+ when 1
195
+ out_name ||= dataset.keys.first
196
+ else
197
+ warn "Multiple sourcecodes under #{out_type}: #{dataset.keys}"
198
+ exit(1)
199
+ end
200
+ end
201
+ if data = dataset[out_name]
202
+ puts data
203
+ exit
204
+ end
205
+ end
206
+ warn "*** Cannot find sourcecode #{out_type}/#{out_name}"
207
+ exit(1)
164
208
  when :yaml
165
209
  puts taken.to_yaml
166
210
  when :list
@@ -52,6 +52,12 @@
52
52
  <% end -%>
53
53
 
54
54
  <rfc <%=rfcattrs%>>
55
+ <% ps.arr("v3xml2rfc", false) do |pi, val|
56
+ Array(val).each do |el|
57
+ -%>
58
+ <?v3xml2rfc <%=pi%>="<%=ps.escattr(el)%>"?>
59
+ <% end
60
+ end -%>
55
61
  <front>
56
62
  <%= ps.ele("title", ps.attr("abbrev=titleabbrev")) %>
57
63
 
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.7.21'
3
+ s.version = '1.7.23'
4
4
  s.summary = "Kramdown extension for generating RFCXML (RFC 799x)."
5
5
  s.description = %{An RFCXML (RFC 799x) generating backend for Thomas Leitner's
6
6
  "kramdown" markdown parser. Mostly useful for RFC writers.}
@@ -289,6 +289,12 @@ def xml_from_sections(input)
289
289
  # the first section is a YAML with front matter parameters (don't put a label here)
290
290
  # We put back the "---" plus gratuitous blank lines to hack the line number in errors
291
291
  yaml_in = input[/---\s*/] << sections.shift[2]
292
+ begin
293
+ require 'kramdown-rfc/yamlcheck'
294
+ KramdownRFC::YAMLcheck.check_dup_keys(yaml_in)
295
+ rescue => e
296
+ warn "** Cannot check for duplicate keys in YAML header (#{e})"
297
+ end
292
298
  ps = KramdownRFC::ParameterSet.new(yaml_load(yaml_in, [Date], [], true))
293
299
 
294
300
  if v = ps[:v]
@@ -18,6 +18,7 @@ class KDRFC
18
18
  # )))
19
19
 
20
20
  KDRFC_PREPEND = [ENV["KDRFC_PREPEND"]].compact
21
+ KDRFC_XML2RFC_FLAGS = Array(ENV["KDRFC_XML2RFC_FLAGS"]&.split(","))
21
22
 
22
23
  def v3_flag?
23
24
  [*(@options.v3 ? ["--v3"] : []),
@@ -37,6 +38,15 @@ def process_mkd(input, output)
37
38
  end
38
39
  end
39
40
 
41
+ def filename_ct(fn, ext)
42
+ bn = File.basename(fn, ".*")
43
+ if r = ENV["KRAMDOWN_RFC_DOCREV"]
44
+ bn << "-#{r}"
45
+ end
46
+ {filename: "#{bn}.#{ext}",
47
+ content_type: "text/plain"}
48
+ end
49
+
40
50
  def run_idnits(*args)
41
51
  if @options.remote
42
52
  run_idnits_remotely(*args)
@@ -62,8 +72,7 @@ def run_idnits_remotely(txt_fn)
62
72
  url = URI(IDNITS_WEBSERVICE)
63
73
  req = Net::HTTP::Post.new(url)
64
74
  form = [["file", File.open(txt_fn),
65
- {filename: "input.txt",
66
- content_type: "text/plain"}],
75
+ filename_ct(txt_fn, "txt")],
67
76
  ["hidetext", "true"]]
68
77
  diag = ["url/form: ", url, form].inspect
69
78
  req.set_form(form, 'multipart/form-data')
@@ -105,7 +114,7 @@ end
105
114
  def process_xml_locally(input, output, *flags)
106
115
  warn "* converting locally from xml #{input} to txt #{output}" if @options.verbose
107
116
  begin
108
- o, s = Open3.capture2(*KDRFC_PREPEND, "xml2rfc", *v3_flag?, *flags, input)
117
+ o, s = Open3.capture2(*KDRFC_PREPEND, "xml2rfc", *v3_flag?, *flags, *KDRFC_XML2RFC_FLAGS, input)
109
118
  puts o
110
119
  if s.success?
111
120
  warn "* #{output} written" if @options.verbose
@@ -152,8 +161,7 @@ def process_xml_remotely(input, output, *flags)
152
161
  url = URI(XML2RFC_WEBSERVICE + maf)
153
162
  req = Net::HTTP::Post.new(url)
154
163
  form = [["file", File.open(input),
155
- {filename: "input.xml",
156
- content_type: "text/plain"}]]
164
+ filename_ct(input, "xml")]]
157
165
  diag = ["url/form: ", url, form].inspect
158
166
  req.set_form(form, 'multipart/form-data')
159
167
  warn "* requesting at #{url}" if @options.verbose
@@ -0,0 +1,44 @@
1
+ require 'yaml'
2
+
3
+ module KramdownRFC
4
+ module YAMLcheck
5
+
6
+ def self.short_name(node)
7
+ if node.scalar?
8
+ node.value
9
+ else
10
+ node.children&.map {short_name(_1)}&.join("_")
11
+ end
12
+ end
13
+
14
+ # Does not follow aliases.
15
+ def self.check_dup_keys1(node, path)
16
+ if YAML::Nodes::Mapping === node
17
+ children = node.children.each_slice(2)
18
+ duplicates = children.map { |key_node, _value_node|
19
+ key_node }.group_by{short_name(_1)}.select { |_value, nodes| nodes.size > 1 }
20
+
21
+ duplicates.each do |key, nodes|
22
+ name = (path + [key]).join("/")
23
+ lines = nodes.map { |occurrence| occurrence.start_line + 1 }.join(", ")
24
+ warn "** duplicate map key >#{name}< in YAML, lines #{lines}"
25
+ end
26
+
27
+ children.each do |key_node, value_node|
28
+ newname = short_name(key_node)
29
+ check_dup_keys1(value_node, path + Array(newname))
30
+ end
31
+ else
32
+ node.children.to_a.each { |child| check_dup_keys1(child, path) }
33
+ end
34
+ end
35
+
36
+ def self.check_dup_keys(data)
37
+ ast = YAML.parse_stream(data)
38
+ check_dup_keys1(ast, [])
39
+ end
40
+
41
+ # check_dup_keys(DATA)
42
+
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-rfc2629
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.21
4
+ version: 1.7.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-11 00:00:00.000000000 Z
10
+ date: 2025-01-31 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: kramdown
@@ -204,12 +203,12 @@ files:
204
203
  - lib/kramdown-rfc/rexml-formatters-conservative.rb
205
204
  - lib/kramdown-rfc/rfc8792.rb
206
205
  - lib/kramdown-rfc/svg-id-cleanup.rb
206
+ - lib/kramdown-rfc/yamlcheck.rb
207
207
  - lib/kramdown-rfc2629.rb
208
208
  homepage: http://github.com/cabo/kramdown-rfc
209
209
  licenses:
210
210
  - MIT
211
211
  metadata: {}
212
- post_install_message:
213
212
  rdoc_options: []
214
213
  require_paths:
215
214
  - lib
@@ -224,8 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
223
  - !ruby/object:Gem::Version
225
224
  version: '0'
226
225
  requirements: []
227
- rubygems_version: 3.5.14
228
- signing_key:
226
+ rubygems_version: 3.6.2
229
227
  specification_version: 4
230
228
  summary: Kramdown extension for generating RFCXML (RFC 799x).
231
229
  test_files: []