kramdown-rfc2629 1.0.34 → 1.0.35

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
  SHA1:
3
- metadata.gz: 8833ab278c338ba6955a4d6708b046923431e657
4
- data.tar.gz: a64817b926813db7906b35867f2726dd14e580a4
3
+ metadata.gz: 2a1f1ed2a734a6ccf34f300ee6b1a5e46abdc7a5
4
+ data.tar.gz: 621309318d88a83810dfb337d90d1c5c39011e29
5
5
  SHA512:
6
- metadata.gz: 8aebe69506ae8d318678a7ac3d40dc54a1699cd2651b0ce42891c376907ca82728b8ed4249d809e30e67cc2a8ba334122e01cbaf7250b993f9c0d420e2aeb58c
7
- data.tar.gz: 3dafcdc46dabc1d28822e476fe932f768ba7ea9b9226c7da0898ca4e315a30c33633184c9d812e92962a08826707f91af9c15103b5923281fc2a2f3c2f2f3469
6
+ metadata.gz: 1b19dd534cb507d9b0dbcfc1d0d1008a9f8be0a962beb067ae68d7f475890e1516ec531b6a6f41f4309da92b7d2f8a81f5bf6d532e84520b6005a3e7d6775ef9
7
+ data.tar.gz: bb8ae29927a434c69ff02cbc81be85930dde4e9d2c60e46ddaf5e2963ab0abe8ae3cefee0a7a07c83bd38fc635e840cb3c6d3eb30669144be40fccc515f830e0
data/README.md CHANGED
@@ -231,9 +231,21 @@ Most of the [kramdown syntax][kdsyntax] is supported and does
231
231
  something useful; with the exception of the math syntax (math has no
232
232
  special support in XML2RFC), and HTML syntax of course.
233
233
 
234
- A number of more esoteric features have recently been added.
234
+ A number of more esoteric features have recently been added.
235
235
  (The minimum required version for each full feature is indicated.)
236
236
 
237
+ (1.0.35:)
238
+ An experimental command `doilit` has been added. It can be used to
239
+ convert DOIs given on the command line into references entries for
240
+ kramdown-rfc YAML, saving a lot of typing. Note that the DOI database
241
+ is not of very consistent quality, so you likely have to hand-edit the
242
+ result before including it into the document (use `-v` to see raw JSON
243
+ data from the DOI database, made somewhat readable by converting it
244
+ into YAML). Use `-c` to enable caching (requires `open-uri-cached`
245
+ gem). Use `-h=handle` in front of a DOI to set a handle different
246
+ from the default `a`, `b`, etc. Similarly, use `-x=handle` to
247
+ generate XML2RFCv2 XML instead of kramdown-rfc YAML.
248
+
237
249
  (1.0.31:)
238
250
  The kramdown `smart_quotes` feature can be controlled better.
239
251
  By default, it is on (with default kramdown settings), unless `coding:
data/bin/doilit CHANGED
@@ -2,15 +2,42 @@
2
2
  require 'open-uri'
3
3
  require 'yaml'
4
4
  require 'json'
5
+ require 'kramdown-rfc2629'
6
+ require 'kramdown-rfc/parameterset'
7
+ require 'kramdown-rfc/refxml'
8
+
9
+ # doilit -c 10.6028/NIST.SP.800-183 10.1016/j.adhoc.2015.04.007 10.1109/MIC.2012.29 10.1145/2507924.2507954
10
+
5
11
 
6
12
  ACCEPT_CITE_JSON = {"Accept" => "application/citeproc+json"}
7
13
 
8
14
  $verbose = false
15
+ $handle = "a"
16
+ $xml = false
9
17
 
18
+ litent = {}
10
19
  ARGV.each do |doi|
11
- if doi == "-v"
20
+ case doi
21
+ when "-c"
22
+ begin
23
+ require 'open-uri/cached'
24
+ rescue LoadError
25
+ warn '*** please "gem install open-uri-cached" to enable caching'
26
+ end
27
+ next
28
+ when "-v"
12
29
  $verbose = true
13
30
  next
31
+ when /\A-h=(.*)/
32
+ $handle = $1
33
+ next
34
+ when /\A-x=(.*)/
35
+ $handle = $1
36
+ $xml = true
37
+ next
38
+ when /\A-/
39
+ warn "*** Usage: doilit [-c] [-v] [-h=handle|-x=xmlhandle] doi..."
40
+ exit 1
14
41
  end
15
42
  cite = JSON.parse(open("http://dx.doi.org/#{doi}", ACCEPT_CITE_JSON).read)
16
43
  puts cite.to_yaml if $verbose
@@ -27,9 +54,9 @@ ARGV.each do |doi|
27
54
  lau
28
55
  end
29
56
  end
30
- if i = cite["issued"]
31
- if dp = i["date-parts"]
32
- if Integer === (dp = dp[0])
57
+ if iss = cite["issued"]
58
+ if dp = iss["date-parts"]
59
+ if Integer === (dp = dp[0])[0]
33
60
  lit["date"] = ["%04d" % dp[0], *dp[1..-1].map {|p| "%02d" % p}].join("-")
34
61
  end
35
62
  end
@@ -51,5 +78,15 @@ ARGV.each do |doi|
51
78
  ser[pub] = info.join(", ")
52
79
  end
53
80
  lit["seriesinfo"]["DOI"] = cite["DOI"]
54
- puts lit.to_yaml.gsub(/^/, " ")
81
+ while litent[$handle]
82
+ $handle.succ!
83
+ end
84
+ litent[$handle] = lit
85
+ end
86
+ if $xml
87
+ litent.each do |k, v|
88
+ puts KramdownRFC::ref_to_xml(k, v)
89
+ end
90
+ else
91
+ puts litent.to_yaml.gsub(/^/, " ").lines[1..-1]
55
92
  end
data/bin/kramdown-rfc2629 CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby2.1
2
2
  # -*- coding: utf-8 -*-
3
3
  require 'kramdown-rfc2629'
4
+ require 'kramdown-rfc/parameterset'
5
+ require 'kramdown-rfc/refxml'
4
6
  require 'yaml'
5
7
  require 'erb'
6
8
  require 'date'
@@ -21,7 +23,7 @@ def xml_from_sections(input)
21
23
  # the first section is a YAML with front matter parameters (don't put a label here)
22
24
  # We put back the "---" plus gratuitous blank lines to hack the line number in errors
23
25
  yaml_in = input[/---\s*/] << sections.shift[2]
24
- ps = ParameterSet.new(YAML.load(yaml_in))
26
+ ps = KramdownRFC::ParameterSet.new(YAML.load(yaml_in))
25
27
  coding_override = ps.has(:coding)
26
28
  smart_quotes = ps[:smart_quotes]
27
29
 
@@ -131,33 +133,7 @@ def xml_from_sections(input)
131
133
  warn "*** don't know how to expand ref #{k}"
132
134
  next
133
135
  end
134
- vps = ParameterSet.new(v)
135
- erb = ERB.new <<-REFERB, nil, '-'
136
- <reference anchor="<%= k %>" <%= vps.attr("target") %>>
137
- <front>
138
- <%= vps.ele("title") -%>
139
-
140
- <% vps.arr("author", true, true) do |au|
141
- aups = authorps_from_hash(au)
142
- -%>
143
- <author <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
144
- <%= aups.ele("organization=org", aups.attr("abbrev=orgabbrev"), "") %>
145
- </author>
146
- <% aups.warn_if_leftovers -%>
147
- <% end -%>
148
- <date <%= dateattrs(vps[:date]) %>/>
149
- </front>
150
- <% vps.arr("seriesinfo", false) do |k, v| -%>
151
- <seriesInfo name="<%=k%>" value="<%=v%>"/>
152
- <% end -%>
153
- <% vps.arr("format", false) do |k, v| -%>
154
- <format type="<%=k%>" target="<%=v%>"/>
155
- <% end -%>
156
- <%= vps.ele("annotation=ann") -%>
157
- </reference>
158
- REFERB
159
- sechash[sn.to_s] << erb.result(binding)
160
- vps.warn_if_leftovers
136
+ sechash[sn.to_s] << KramdownRFC::ref_to_xml(k, v)
161
137
  end
162
138
  end
163
139
  end
@@ -177,55 +153,6 @@ def xml_from_sections(input)
177
153
  [input, coding_override, link_defs, smart_quotes]
178
154
  end
179
155
 
180
- class ParameterSet
181
- include Kramdown::Utils::Html
182
-
183
- attr_reader :f
184
- def initialize(y)
185
- raise "*** invalid parameter set #{y.inspect}" unless Hash === y
186
- @f = y
187
- end
188
- def [](pn)
189
- @f.delete(pn.to_s)
190
- end
191
- def has(pn)
192
- @f[pn.to_s]
193
- end
194
- def van(pn) # pn is a parameter name, possibly with an =alias
195
- an, pn = pn.to_s.split("=")
196
- pn ||= an
197
- [self[pn] || self[an], an]
198
- end
199
- def attr(pn)
200
- val, an = van(pn)
201
- %{#{an}="#{val}"} if val
202
- end
203
- def attrs(*pns)
204
- pns.map{ |pn| attr(pn) }.compact.join(" ")
205
- end
206
- def ele(pn, attr=nil, defcontent=nil)
207
- val, an = van(pn)
208
- val ||= defcontent
209
- Array(val).map do |val1|
210
- %{<#{[an, *Array(attr).map(&:to_s)].join(" ").strip}>#{escape_html(val1.to_s.strip)}</#{an}>}
211
- end.join(" ")
212
- end
213
- def arr(an, converthash=true, must_have_one=false, &block)
214
- arr = self[an] || []
215
- arr = [arr] if Hash === arr && converthash
216
- arr << { } if must_have_one && arr.empty?
217
- Array(arr).each(&block)
218
- end
219
- def rest
220
- @f
221
- end
222
- def warn_if_leftovers
223
- if !@f.empty?
224
- warn "*** attributes left #{@f.inspect}!"
225
- end
226
- end
227
- end
228
-
229
156
  XML_RESOURCE_ORG_PREFIX = Kramdown::Converter::Rfc2629::XML_RESOURCE_ORG_PREFIX
230
157
 
231
158
  def bibtagsys(bib)
@@ -241,43 +168,6 @@ def bibtagsys(bib)
241
168
  end
242
169
  end
243
170
 
244
- def authorps_from_hash(au)
245
- aups = ParameterSet.new(au)
246
- if ins = aups[:ins]
247
- parts = ins.split('.').map(&:strip)
248
- aups.rest["initials"] = parts[0..-2].join('.') << '.'
249
- aups.rest["surname"] = parts[-1]
250
- end
251
- # hack ("heuristic for") initials and surname from name
252
- # -- only works for people with exactly one last name and uncomplicated first names
253
- if n = aups.rest["name"]
254
- n = n.split
255
- aups.rest["initials"] ||= n[0..-2].map(&:chr).join('.') << '.'
256
- aups.rest["surname"] ||= n[-1]
257
- end
258
- aups
259
- end
260
-
261
- def dateattrs(date)
262
- begin
263
- case date
264
- when Integer
265
- %{year="#{"%04d" % date}"}
266
- when String
267
- Date.parse("#{date}-01").strftime(%{year="%Y" month="%B"})
268
- when Date
269
- date.strftime(%{year="%Y" month="%B" day="%d"})
270
- when Array # this allows to explicitly give a string
271
- %{year="#{date.join(" ")}"}
272
- when nil
273
- %{year="n.d."}
274
- end
275
-
276
- rescue ArgumentError
277
- warn "*** Invalid date: #{date} -- use 2012, 2012-07, or 2012-07-28"
278
- end
279
- end
280
-
281
171
  def read_encodings
282
172
  encfilename = File.expand_path '../../data/encoding-fallbacks.txt', __FILE__
283
173
  encfile = File.read(encfilename, coding: "UTF-8")
@@ -24,7 +24,7 @@
24
24
  <%= ps.ele("title", ps.attr("abbrev=titleabbrev")) %>
25
25
 
26
26
  <% ps.arr("author") do |au|
27
- aups = authorps_from_hash(au)
27
+ aups = KramdownRFC::authorps_from_hash(au)
28
28
  -%>
29
29
  <author <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
30
30
  <%= aups.ele("organization=org", aups.attr("abbrev=orgabbrev"), "") %>
@@ -45,7 +45,7 @@
45
45
  <% aups.warn_if_leftovers -%>
46
46
  <% end -%>
47
47
 
48
- <date <%= dateattrs(ps[:date]||Date.today) %>/>
48
+ <date <%= KramdownRFC::dateattrs(ps[:date]||Date.today) %>/>
49
49
 
50
50
  <%= ps.ele("area") %>
51
51
  <%= ps.ele("workgroup=wg") %>
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.0.34'
3
+ s.version = '1.0.35'
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.}
@@ -0,0 +1,53 @@
1
+ module KramdownRFC
2
+
3
+ class ParameterSet
4
+ include Kramdown::Utils::Html
5
+
6
+ attr_reader :f
7
+ def initialize(y)
8
+ raise "*** invalid parameter set #{y.inspect}" unless Hash === y
9
+ @f = y
10
+ end
11
+ def [](pn)
12
+ @f.delete(pn.to_s)
13
+ end
14
+ def has(pn)
15
+ @f[pn.to_s]
16
+ end
17
+ def van(pn) # pn is a parameter name, possibly with an =alias
18
+ an, pn = pn.to_s.split("=")
19
+ pn ||= an
20
+ [self[pn] || self[an], an]
21
+ end
22
+ def attr(pn)
23
+ val, an = van(pn)
24
+ %{#{an}="#{val}"} if val
25
+ end
26
+ def attrs(*pns)
27
+ pns.map{ |pn| attr(pn) }.compact.join(" ")
28
+ end
29
+ def ele(pn, attr=nil, defcontent=nil)
30
+ val, an = van(pn)
31
+ val ||= defcontent
32
+ Array(val).map do |val1|
33
+ %{<#{[an, *Array(attr).map(&:to_s)].join(" ").strip}>#{escape_html(val1.to_s.strip)}</#{an}>}
34
+ end.join(" ")
35
+ end
36
+ def arr(an, converthash=true, must_have_one=false, &block)
37
+ arr = self[an] || []
38
+ arr = [arr] if Hash === arr && converthash
39
+ arr << { } if must_have_one && arr.empty?
40
+ Array(arr).each(&block)
41
+ end
42
+ def rest
43
+ @f
44
+ end
45
+ def warn_if_leftovers
46
+ if !@f.empty?
47
+ warn "*** attributes left #{@f.inspect}!"
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ end
@@ -0,0 +1,72 @@
1
+ module KramdownRFC
2
+
3
+ def self.ref_to_xml(k, v)
4
+ vps = KramdownRFC::ParameterSet.new(v)
5
+ erb = ERB.new <<-REFERB, nil, '-'
6
+ <reference anchor="<%= k %>" <%= vps.attr("target") %>>
7
+ <front>
8
+ <%= vps.ele("title") -%>
9
+
10
+ <% vps.arr("author", true, true) do |au|
11
+ aups = authorps_from_hash(au)
12
+ -%>
13
+ <author <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
14
+ <%= aups.ele("organization=org", aups.attr("abbrev=orgabbrev"), "") %>
15
+ </author>
16
+ <% aups.warn_if_leftovers -%>
17
+ <% end -%>
18
+ <date <%= dateattrs(vps[:date]) %>/>
19
+ </front>
20
+ <% vps.arr("seriesinfo", false) do |k, v| -%>
21
+ <seriesInfo name="<%=k%>" value="<%=v%>"/>
22
+ <% end -%>
23
+ <% vps.arr("format", false) do |k, v| -%>
24
+ <format type="<%=k%>" target="<%=v%>"/>
25
+ <% end -%>
26
+ <%= vps.ele("annotation=ann") -%>
27
+ </reference>
28
+ REFERB
29
+ ret = erb.result(binding)
30
+ vps.warn_if_leftovers
31
+ ret
32
+ end
33
+
34
+ def self.authorps_from_hash(au)
35
+ aups = KramdownRFC::ParameterSet.new(au)
36
+ if ins = aups[:ins]
37
+ parts = ins.split('.').map(&:strip)
38
+ aups.rest["initials"] = parts[0..-2].join('.') << '.'
39
+ aups.rest["surname"] = parts[-1]
40
+ end
41
+ # hack ("heuristic for") initials and surname from name
42
+ # -- only works for people with exactly one last name and uncomplicated first names
43
+ if n = aups.rest["name"]
44
+ n = n.split
45
+ aups.rest["initials"] ||= n[0..-2].map(&:chr).join('.') << '.'
46
+ aups.rest["surname"] ||= n[-1]
47
+ end
48
+ aups
49
+ end
50
+
51
+ def self.dateattrs(date)
52
+ begin
53
+ case date
54
+ when /\A\d\d\d\d\z/
55
+ %{year="#{date}"}
56
+ when Integer
57
+ %{year="#{"%04d" % date}"}
58
+ when String
59
+ Date.parse("#{date}-01").strftime(%{year="%Y" month="%B"})
60
+ when Date
61
+ date.strftime(%{year="%Y" month="%B" day="%d"})
62
+ when Array # this allows to explicitly give a string
63
+ %{year="#{date.join(" ")}"}
64
+ when nil
65
+ %{year="n.d."}
66
+ end
67
+
68
+ rescue ArgumentError
69
+ warn "*** Invalid date: #{date} -- use 2012, 2012-07, or 2012-07-28"
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-rfc2629
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.34
4
+ version: 1.0.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
@@ -41,6 +41,8 @@ files:
41
41
  - data/encoding-fallbacks.txt
42
42
  - data/kramdown-rfc2629.erb
43
43
  - kramdown-rfc2629.gemspec
44
+ - lib/kramdown-rfc/parameterset.rb
45
+ - lib/kramdown-rfc/refxml.rb
44
46
  - lib/kramdown-rfc2629.rb
45
47
  homepage: http://github.com/cabo/kramdown-rfc2629
46
48
  licenses: