kramdown-rfc2629 1.7.22 → 1.7.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6829cc1f3803f3a5badbe865394e4bd303c26fb2ec5710ed2347cdbabea1f529
4
- data.tar.gz: 5505e3f40551c0e7a1b4341b2a87ae80aa7e28c5bb773a2b7dc99ad491ab1ded
3
+ metadata.gz: 269381d3a05b02772eb68975943dcf119cd9010d9fdcfb4eb5df92886bfa59bb
4
+ data.tar.gz: 2f8c3f406037faaa02bd01f0eda40438a601ddaea49ff4c95ff8bcf168e0572a
5
5
  SHA512:
6
- metadata.gz: fb74883f8051016119e1cfe1a2ae7270919d599e8416bde8fa7632d64e5080d02bfba81ad7ec37fc6a4817ee18c1dcb53ff23cefa3f1d5c32c0888456ac7cc9e
7
- data.tar.gz: 7f89516975da7b9017642c882c6154173da0116d39db648a298b1c42bb974f9224eec8d6b34f90132008577eba6617b59636b37a40f6dc2851cb1c9f8787b822
6
+ metadata.gz: 831fa5d0ea40f6f3e7c111160684eb818a6e4837159c2816c9d258c67258249226e5f895bfdb5b512f09af1c593a4176c378e99e395b180fd891409b06635206
7
+ data.tar.gz: f335e96c5bda06e7de555115ed3ae4057964287c24713082d23105ed9b93ddd0a63df6459887a9ae49fca3510fda4fc8fdcf880f588d1703ec2b422f9dc77cb9
@@ -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
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.7.22'
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]
@@ -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,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-rfc2629
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.22
4
+ version: 1.7.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-24 00:00:00.000000000 Z
10
+ date: 2025-01-31 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: kramdown
@@ -203,6 +203,7 @@ files:
203
203
  - lib/kramdown-rfc/rexml-formatters-conservative.rb
204
204
  - lib/kramdown-rfc/rfc8792.rb
205
205
  - lib/kramdown-rfc/svg-id-cleanup.rb
206
+ - lib/kramdown-rfc/yamlcheck.rb
206
207
  - lib/kramdown-rfc2629.rb
207
208
  homepage: http://github.com/cabo/kramdown-rfc
208
209
  licenses: