kramdown-rfc2629 1.5.25 → 1.5.26

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: 4e19def630ee2ad018b297cd5c196e3ee70f052fea88004014a1e8dcc298c050
4
- data.tar.gz: eb677f68752221d001095424394b4d276453614bb2286fe77e83d2d3a41d1cfa
3
+ metadata.gz: 47ff7c7c6f4593d4d4c036c5986e7ff84ddec57ecb7a55959942d86ee6f0c9c8
4
+ data.tar.gz: 363ddf3a404d78bc9c4daa71ae33850ec8a0f214fc9488e0c5d9230784f40056
5
5
  SHA512:
6
- metadata.gz: f54b8a10cb72d16313a4a5c644e52e223539f38b4245d6ca3e54abb28b1704bdbd447d15b0065ad00334df6bbae3a0508f08cd59f0eaf37bfaa717eb52b394ff
7
- data.tar.gz: b54e739cba1b21727189cfdf576fc0d8f0bcac1be224bf7affb017c1ddcfd0e2358344a1f162763183b297da2256ca9710e64946b62f79e2e1aa65ec45bdab04
6
+ metadata.gz: b06841b1a0188f1f343eff51e2846b981d42592bbadbec8cbcdf38010ef66b23f560aab3effa183042d3207b9c0356346ab01dfa89ac551d3146e843cd6e35b1
7
+ data.tar.gz: e80bb4fe75e33268c804907f332138fe68440355ef026a853d749e0d82c56d807acf19864b49cbf49f670d4c6c6fd6d1ef58719d534495866fa656ecb11cb562
@@ -95,7 +95,10 @@
95
95
  <% if mail || homepage -%>
96
96
  <t>
97
97
  <% end -%>
98
- <% if mail && (mail_local, mail_host = mail.split("@", 2)) && mail_host -%>
98
+ <% if mail
99
+ mail_local, mail_host = mail.split("@", 2)
100
+ end
101
+ if mail_host -%>
99
102
  <% mail_subdomain, mail_domain = mail_host.split(".", 2) -%>
100
103
  <% group = venue[:group] || mail_local # XXX -%>
101
104
  <% arch = venue[:arch] || "https://mailarchive.ietf.org/arch/browse/#{mail_local}/" -%>
@@ -203,6 +206,7 @@
203
206
  <<CONTRIBUTION
204
207
  {:/nomarkdown}
205
208
  #{contrib}
209
+
206
210
  {::nomarkdown}
207
211
  CONTRIBUTION
208
212
  end -%>
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.5.25'
3
+ s.version = '1.5.26'
4
4
  s.summary = "Kramdown extension for generating RFC 7749 XML."
5
5
  s.description = %{An RFC7749 (XML2RFC) generating backend for Thomas Leitner's
6
6
  "kramdown" markdown parser. Mostly useful for RFC writers.}
@@ -38,7 +38,19 @@ module KramdownRFC
38
38
  def ele(pn, attr=nil, defcontent=nil, markdown=false)
39
39
  val, an = van(pn)
40
40
  val ||= defcontent
41
+ val = [val] if Hash === val
41
42
  Array(val).map do |val1|
43
+ a = Array(attr).dup
44
+ if Hash === val1
45
+ val1.each do |k, v|
46
+ if k == ":"
47
+ val1 = v
48
+ else
49
+ k = Kramdown::Element.attrmangle(k) || k
50
+ a.unshift(%{#{k}="#{escattr(v)}"})
51
+ end
52
+ end
53
+ end
42
54
  v = val1.to_s.strip
43
55
  contents =
44
56
  if markdown
@@ -46,7 +58,7 @@ module KramdownRFC
46
58
  else
47
59
  escape_html(v)
48
60
  end
49
- %{<#{[an, *Array(attr).map(&:to_s)].join(" ").strip}>#{contents}</#{an}>}
61
+ %{<#{[an, *a.map(&:to_s)].join(" ").strip}>#{contents}</#{an}>}
50
62
  end.join(" ")
51
63
  end
52
64
  def arr(an, converthash=true, must_have_one=false, &block)
@@ -8,6 +8,12 @@ module KramdownRFC
8
8
  escape_html(str.to_s, :attribute)
9
9
  end
10
10
 
11
+ AUTHOR_ATTRIBUTES = %w{
12
+ initials surname fullname
13
+ asciiInitials asciiSurname asciiFullname
14
+ role
15
+ }
16
+
11
17
  def self.ref_to_xml(k, v)
12
18
  vps = KramdownRFC::ParameterSet.new(v)
13
19
  erb = ERB.trim_new <<-REFERB, '-'
@@ -18,7 +24,7 @@ module KramdownRFC
18
24
  <% vps.arr("author", true, true) do |au|
19
25
  aups = authorps_from_hash(au)
20
26
  -%>
21
- <author <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
27
+ <author <%=aups.attrs(*AUTHOR_ATTRIBUTES)%>>
22
28
  <%= aups.ele("organization=org", aups.attr("abbrev=orgabbrev"), "") %>
23
29
  </author>
24
30
  <% aups.warn_if_leftovers -%>
@@ -40,19 +46,110 @@ module KramdownRFC
40
46
  ret
41
47
  end
42
48
 
49
+ def self.treat_multi_attribute_member(ps, an)
50
+ value = ps.rest[an]
51
+ if Hash === value
52
+ value.each do |k, v|
53
+ ps.rest[if k == ':'
54
+ an
55
+ else
56
+ Kramdown::Element.attrmangle(k + an) ||
57
+ Kramdown::Element.attrmangle(k) ||
58
+ k
59
+ end] = v
60
+ end
61
+ end
62
+ end
63
+
64
+ def self.initializify(s) # XXX Jean-Pierre
65
+ w = '\p{Lu}\p{Lo}'
66
+ if s =~ /\A[-.#{w}]+[.]/u
67
+ $&
68
+ elsif s =~ /\A([#{w}])[^-]*/u
69
+ ret = "#$1."
70
+ while (s = $') && s =~ /\A(-[\p{L}])[^-]*/u
71
+ ret << "#$1."
72
+ end
73
+ ret
74
+ else
75
+ warn "*** Can't initializify #{s}"
76
+ s
77
+ end
78
+ end
79
+
80
+ def self.looks_like_initial(s)
81
+ s =~ /\A[\p{Lu}\p{Lo}]([-.][\p{Lu}\p{Lo}]?)*\z/u
82
+ end
83
+
84
+ def self.initials_from_parts_and_surname(aups, parts, s)
85
+ ssz = s.size
86
+ nonsurname = parts[0...-ssz]
87
+ if (ns = parts[-ssz..-1]) != s
88
+ warn "*** inconsistent surnames #{ns} and #{s}"
89
+ end
90
+ nonsurname.map{|x| initializify(x)}.join(" ")
91
+ end
92
+
93
+ def self.handle_ins(aups, ins_k, initials_k, surname_k)
94
+ if ins = aups[ins_k]
95
+ parts = ins.split('.').map(&:strip) # split on dots first
96
+ # Coalesce H.-P.
97
+ i = 1; while i < parts.size
98
+ if parts[i][0] == "-"
99
+ parts[i-1..i] = [parts[i-1] + "." + parts[i]]
100
+ else
101
+ i += 1
102
+ end
103
+ end
104
+ # Multiple surnames in ins?
105
+ parts[-1..-1] = parts[-1].split
106
+ s = if surname = aups.rest[surname_k]
107
+ surname.split
108
+ else parts.reverse.take_while{|x| !looks_like_initial(x)}.reverse
109
+ end
110
+ aups.rest[initials_k] = initials_from_parts_and_surname(aups, parts, s)
111
+ aups.rest[surname_k] = s.join(" ")
112
+ end
113
+ end
114
+
115
+ def self.handle_name(aups, fn_k, initials_k, surname_k)
116
+ if name = aups.rest[fn_k]
117
+ names = name.split(/ *\| */, 2) # boundary for given/last name
118
+ if names[1]
119
+ aups.rest[fn_k] = name = names.join(" ") # remove boundary
120
+ if surname = aups.rest[surname_k]
121
+ if surname != names[1]
122
+ warn "*** inconsistent embedded surname #{names[1]} and surname #{surname}"
123
+ end
124
+ end
125
+ aups.rest[surname_k] = names[1]
126
+ end
127
+ parts = name.split
128
+ surname = aups.rest[surname_k] || parts[-1]
129
+ s = surname.split
130
+ aups.rest[initials_k] ||= initials_from_parts_and_surname(aups, parts, s)
131
+ aups.rest[surname_k] = s.join(" ")
132
+ end
133
+ end
134
+
43
135
  def self.authorps_from_hash(au)
44
136
  aups = KramdownRFC::ParameterSet.new(au)
45
- if ins = aups[:ins]
46
- parts = ins.split('.').map(&:strip)
47
- aups.rest["initials"] = parts[0..-2].join('.') << '.'
48
- aups.rest["surname"] = parts[-1]
137
+ if n = aups[:name]
138
+ warn "** both name #{n} and fullname #{fn} are set on one author" if fn = aups.rest["fullname"]
139
+ aups.rest["fullname"] = n
140
+ usename = true
141
+ end
142
+ ["fullname", "ins", "initials", "surname"].each do |an|
143
+ treat_multi_attribute_member(aups, an)
49
144
  end
145
+ handle_ins(aups, :ins, "initials", "surname")
146
+ handle_ins(aups, :asciiIns, "asciiInitials", "asciiSurname")
50
147
  # hack ("heuristic for") initials and surname from name
51
148
  # -- only works for people with exactly one last name and uncomplicated first names
52
- if n = aups.rest["name"]
53
- n = n.split
54
- aups.rest["initials"] ||= n[0..-2].map(&:chr).join('.') << '.'
55
- aups.rest["surname"] ||= n[-1]
149
+ # -- add surname for people with more than one last name
150
+ if usename
151
+ handle_name(aups, "fullname", "initials", "surname")
152
+ handle_name(aups, "asciiFullname", "asciiInitials", "asciiSurname")
56
153
  end
57
154
  aups
58
155
  end
@@ -69,7 +166,7 @@ module KramdownRFC
69
166
  # country: Germany
70
167
 
71
168
  PERSON_ERB = <<~ERB
72
- <<%= element_name%> <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
169
+ <<%= element_name%> <%=aups.attrs(*AUTHOR_ATTRIBUTES)%>>
73
170
  <%= aups.ele("organization=org", aups.attrs("abbrev=orgabbrev",
74
171
  *[$options.v3 && "ascii=orgascii"]), "") %>
75
172
  <address>
@@ -242,6 +242,14 @@ module Kramdown
242
242
  TRUTHY["false"] = false
243
243
  TRUTHY["no"] = false
244
244
 
245
+ # explicit or automatic studlification
246
+ # note that explicit (including trailing "_") opts out of automatic
247
+ def self.attrmangle(k)
248
+ if (d = k.gsub(/_(.|$)/) { $1.upcase }) != k or d = STUDLY_ATTR_MAP[k]
249
+ d
250
+ end
251
+ end
252
+
245
253
  def rfc2629_fix(opts)
246
254
  if a = attr
247
255
  if anchor = a.delete('id')
@@ -254,7 +262,7 @@ module Kramdown
254
262
  opts = opts.merge(noabbrev: TRUTHY[av]) # updated copy
255
263
  end
256
264
  attr.keys.each do |k|
257
- if (d = k.gsub(/_(.|$)/) { $1.upcase }) != k or d = STUDLY_ATTR_MAP[k]
265
+ if d = self.class.attrmangle(k)
258
266
  a[d] = a.delete(k)
259
267
  end
260
268
  end
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.5.25
4
+ version: 1.5.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-25 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.2.32
123
+ rubygems_version: 3.3.3
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Kramdown extension for generating RFC 7749 XML.