kramdown-rfc2629 1.7.2 → 1.7.4

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: 6fd72c01ed7024958d451c3342f16b8985dc145ef09a6e4d33ba2f3d290d81e4
4
- data.tar.gz: 7ada0cb08e8481cfef450606bcfdaab0303a49b0306fdf5be7041121b57a1143
3
+ metadata.gz: 6c60909608ac8c84853d39c03fdf0da2cdfd179601a63a5b07a52099925a8ce9
4
+ data.tar.gz: ce8fcfe62f77fc23a8a5514e329ade31864ac099f5a45c6bbce976e3a8210a1e
5
5
  SHA512:
6
- metadata.gz: c525300de7bf414755c50476de45b9842ab011965a2dcfa82206d9e614a12b482b958707021dc3fff51a6c66f98b39b55d3dd6556d001ec255b50fde926a82e9
7
- data.tar.gz: 200cb7e1760cc81b628354dc2343eaee5595294d1334b16d17b1e47ed3bc2f83174ee588d9e5d50289aebf0b0f579b4ad635124779cc66e5578bd600f4e17b9f
6
+ metadata.gz: 3b11fe08773c3e5c80aaaaeff16bf6728ab8656ee95ce0186bf786b2da2b99832b65b36fa32e7801e36b3f9c32b4e90830fa4c14f5136d0f7945c2c342ba17d1
7
+ data.tar.gz: 35a372c29219550c56a2335a497b3117621ac7b998792d596272fad84725a6f464a89bb931c9472a0ef4320eee40b69088e3f595ef8e6a028e7ba0a57e58436f
data/README.md CHANGED
@@ -150,7 +150,7 @@ or
150
150
  email: pthubert@cisco.com
151
151
 
152
152
  (the hash keys are the XML GIs from RFC 7749, with a flattened
153
- structure. As RFC 7749 requiresd giving both the full name and
153
+ structure. As RFC 7749 requires giving both the full name and
154
154
  surname/initials, we use `ins` as an abbreviation for
155
155
  "initials/surname". Yes, the toolchain is Unicode-capable, even if
156
156
  the final RFC output is still in ASCII.)
@@ -9,10 +9,35 @@ require_relative '../lib/kramdown-rfc/rexml-all-text.rb'
9
9
  def clean(s)
10
10
  s.gsub!(/\//, ":")
11
11
  s.gsub!(/\A([-.]+)/) {"_" * $1.size }
12
- s.gsub!(/[^-.:\w]/, "_")
12
+ s.gsub!(/[^-.:\w]+/, "-")
13
13
  s
14
14
  end
15
15
 
16
+ $seen_slugs = {}
17
+
18
+ def slugify_like_xml2rfc(s, delta = 0)
19
+ s = s.unicode_normalize(:nfkd).force_encoding(Encoding::ASCII).scrub('').downcase
20
+ s.gsub!(/[^-\w\s\/]/, '')
21
+ s = s.strip
22
+ s.gsub!(/[-\s\/]/, '-')
23
+ n = 32 - delta
24
+ nmax = [s.size, 40 - delta].min
25
+ while $seen_slugs[slugex = s[0...n]] && n < nmax
26
+ n += 1
27
+ end
28
+ if $seen_slugs[slugex]
29
+ m = 2
30
+ while $seen_slugs[slugex = "#{s[0...n]}-#{m}"]
31
+ m += 1
32
+ if m == 1000
33
+ raise ArgumentError, "Can't build distinguishable slug for '#{s}'"
34
+ end
35
+ end
36
+ end
37
+ $seen_slugs[slugex] = s
38
+ slugex
39
+ end
40
+
16
41
  target = nil
17
42
  dir = nil
18
43
  unfold = true
@@ -52,22 +77,67 @@ warned = Hash.new { |h, k| h[k] = Hash.new }
52
77
  d = REXML::Document.new(ARGF)
53
78
  REXML::XPath.each(d.root, "//sourcecode|//artwork") do |x|
54
79
  if ty = x[:type]
80
+ is_svg = false
81
+ REXML::XPath.each(x, "svg") do is_svg = true end
55
82
  ty = clean(ty)
83
+ if is_svg && ty != "svg"
84
+ warn "** replacing SVG type '#{ty}' by type 'svg'"
85
+ ty = "svg"
86
+ end
87
+ ext = ty
88
+ if ty.empty?
89
+ ty = "=txt"
90
+ ext = "txt"
91
+ end
56
92
  name = x[:name]
93
+ name_is_from_slug = false
57
94
  if !name || name.empty?
58
- name = gensym.succ!.dup
59
- name = "#{name}.#{ty}" unless ty.empty?
95
+ REXML::XPath.each(x, "ancestor::*/name[position() = 1]") do |nameel|
96
+ unless sname = nameel['slugifiedName']
97
+ alltext = nameel.all_text
98
+ nameel.add_attribute('slugifiedName',
99
+ sname = clean("name-" << slugify_like_xml2rfc(alltext, 5)))
100
+ end
101
+ name = clean(sname.to_s.sub(/^name-/, ''))
102
+ name_is_from_slug = true
103
+ end
104
+ if !name || name.empty?
105
+ name = gensym.succ!.dup
106
+ end
107
+ name = "#{name}.#{ext}"
60
108
  end
61
109
  name = clean(name)
62
110
  if taken[ty][name]
63
- unless warned[ty][name]
64
- warn "Concatenating to #{ty}/#{name}."
65
- warned[ty][name] = true
111
+ if name_is_from_slug || is_svg
112
+ # rename old entry as well if it was from slug?
113
+ nameparts = name.split(".")
114
+ if is_svg && nameparts[-1] != "svg"
115
+ nameparts << "svg"
116
+ end
117
+ ext1 = nameparts.pop || "txt"
118
+ suffix = "b"
119
+ while taken[ty][name = [*nameparts[0...-1], "#{nameparts[-1]}-#{suffix}", ext1].join(".")]
120
+ suffix.succ!
121
+ end
122
+ taken[ty][name] = ''
123
+ else
124
+ unless warned[ty][name]
125
+ warn "Concatenating to #{ty}/#{name}."
126
+ warned[ty][name] = true
127
+ end
66
128
  end
67
129
  else
68
130
  taken[ty][name] = ''
69
131
  end
70
- taken[ty][name] << handle_artwork_sourcecode(x.all_text, unfold)
132
+ extracted = false
133
+ REXML::XPath.each(x, "svg") do |svg|
134
+ # According to v3.rnc, there should be only one...
135
+ taken[ty][name] << svg.to_s
136
+ extracted = true
137
+ end
138
+ unless extracted
139
+ taken[ty][name] << handle_artwork_sourcecode(x.all_text, unfold)
140
+ end
71
141
  end
72
142
  end
73
143
 
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.7.2'
3
+ s.version = '1.7.4'
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.}
@@ -702,6 +702,10 @@ COLORS
702
702
  checks = el.attr.delete("check")
703
703
  postprocs = el.attr.delete("post")
704
704
  case t
705
+ when "cbor"
706
+ warn "** There is no sourcecode-type “cbor”."
707
+ warn "** Do you mean “cbor-diag” (diagnostic notation)"
708
+ warn "** or “cbor-pretty” (annotated hex-dump)?"
705
709
  when "json"
706
710
  checks ||= "json"
707
711
  when /\A(.*)-from-yaml\z/
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-rfc2629
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-28 00:00:00.000000000 Z
11
+ date: 2023-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown