kramdown-rfc2629 1.6.13 → 1.6.14

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: b52ce81714c14272005b47807396c6cac7764fa7a2931ca93b2661dfb479d4cf
4
- data.tar.gz: a99b8e49ba4145ca88690ca0af1a1c6549c25a995cbfcb008763adea8a0b7b5d
3
+ metadata.gz: 7be618ba93e707717f18f0f853e899b65744c420dbc9ae1da26a10b382521e88
4
+ data.tar.gz: 77e4f3084a37acb49f50672d660ee14a0e02464d00a425dc1119edc2d79e143c
5
5
  SHA512:
6
- metadata.gz: 6204f7e5f2bbfebd84c4b3b068819008a66535948e5bf8f8eefdfe8a010ec69cde2cf910c0cec73ef74b9f75feb6e5d96d57519dd2e30f5a255406de82b10491
7
- data.tar.gz: 3b595453599f3c33b44a2834ec4bea7306d48b2e6a3a0f1af27843e92013428e03341c20fe5d9f8b6398acca6a39c31890678d9afc1fa99f76eb2511eb72a27c
6
+ metadata.gz: 7f22d6a97b03cf1066b4e37f2cccbc249e11b4d70b2d29d79ed6ff532d91a5dc68751e35d98f0979d288e0ae9cfb7f1b2ebaf47e27ac4c3c6cea508f5d685137
7
+ data.tar.gz: 784534de1682353998ef226d4418539588ad56d2eb7a5dfb3ab8bae3f7bee557a49098bc03e1fd3d084083dadc871867c13f3b1a048bdcc9a31cea32d8445fe5
data/bin/doilit CHANGED
@@ -1,16 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
- require 'open-uri'
3
2
  require 'yaml'
4
- require 'json'
5
3
  require 'kramdown-rfc2629'
6
4
  require 'kramdown-rfc/parameterset'
7
5
  require 'kramdown-rfc/refxml'
6
+ require 'kramdown-rfc/doi'
8
7
 
9
8
  # 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
9
 
11
-
12
- ACCEPT_CITE_JSON = {"Accept" => "application/citeproc+json"}
13
-
14
10
  $verbose = false
15
11
  $fuzzy = false
16
12
  $handle = "a"
@@ -43,79 +39,9 @@ ARGV.each do |doi|
43
39
  warn "*** Usage: doilit [-c] [-f] [-v] [-h=handle|-x=xmlhandle] doi..."
44
40
  exit 1
45
41
  end
46
- cite = JSON.parse(URI("https://dx.doi.org/#{doi}").open(ACCEPT_CITE_JSON).read)
47
- puts cite.to_yaml if $verbose
48
- lit = {}
49
- ser = lit["seriesinfo"] = {}
50
- lit["title"] = cite["title"]
51
- if (st = cite["subtitle"]) && Array === st # defensive
52
- st.delete('')
53
- if st != []
54
- lit["title"] << ": " << st.join("; ")
55
- end
56
- end
57
- if authors = cite["author"]
58
- lit["author"] = authors.map do |au|
59
- lau = {}
60
- if (f = au["family"])
61
- if (g = au["given"])
62
- lau["name"] = "#{g} #{f}"
63
- lau["ins"] = "#{g[0]}. #{f}"
64
- else
65
- lau["name"] = "#{f}"
66
- # lau["ins"] = "#{g[0]}. #{f}"
67
- end
68
- end
69
- lau
70
- end
71
- end
72
- if iss = cite["issued"]
73
- if dp = iss["date-parts"]
74
- if Integer === (dp = dp[0])[0]
75
- lit["date"] = ["%04d" % dp[0], *dp[1..-1].map {|p| "%02d" % p}].join("-")
76
- end
77
- end
78
- end
79
- if !lit.key?("date") && $fuzzy && (iss = cite["created"])
80
- if dp = iss["date-parts"]
81
- if Integer === (dp = dp[0])[0]
82
- lit["date"] = ["%04d" % dp[0], *dp[1..-1].map {|p| "%02d" % p}].join("-")
83
- end
84
- end
85
- end
86
- if (ct = cite["container-title"]) && ct != []
87
- info = []
88
- if v = cite["volume"]
89
- vi = "vol. #{v}"
90
- if (v = cite["journal-issue"]) && (issue = v["issue"])
91
- vi << ", no. #{issue}"
92
- end
93
- info << vi
94
- end
95
- if p = cite["page"]
96
- info << "pp. #{p}"
97
- end
98
- rhs = info.join(", ")
99
- if info != []
100
- ser[ct] = rhs
101
- else
102
- spl = ct.split(" ")
103
- ser[spl[0..-2].join(" ")] = spl[-1]
104
- end
105
- elsif pub = cite["publisher"]
106
- info = []
107
- if t = cite["type"]
108
- info << t
109
- end
110
- rhs = info.join(", ")
111
- if info != []
112
- ser[pub] = rhs
113
- else
114
- spl = pub.split(" ")
115
- ser[spl[0..-2].join(" ")] = spl[-1]
116
- end
117
- end
118
- lit["seriesinfo"]["DOI"] = cite["DOI"]
42
+
43
+ lit = doi_fetch_and_convert(doi, fuzzy: $fuzzy, verbose: $verbose)
44
+
119
45
  while litent[$handle]
120
46
  $handle.succ!
121
47
  end
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.6.13'
3
+ s.version = '1.6.14'
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.}
@@ -0,0 +1,92 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+ require 'yaml'
4
+
5
+ ACCEPT_CITE_JSON = {"Accept" => "application/citeproc+json"}
6
+
7
+ def doi_fetch_and_convert(doi, fuzzy: false, verbose: false)
8
+ cite = JSON.parse(URI("https://dx.doi.org/#{doi}").open(ACCEPT_CITE_JSON).read)
9
+ puts cite.to_yaml if verbose
10
+ lit = {}
11
+ ser = lit["seriesinfo"] = {}
12
+ lit["title"] = cite["title"]
13
+ if (st = cite["subtitle"]) && Array === st # defensive
14
+ st.delete('')
15
+ if st != []
16
+ lit["title"] << ": " << st.join("; ")
17
+ end
18
+ end
19
+ if authors = cite["author"]
20
+ lit["author"] = authors.map do |au|
21
+ lau = {}
22
+ if (f = au["family"])
23
+ if (g = au["given"])
24
+ lau["name"] = "#{g} #{f}"
25
+ lau["ins"] = "#{g[0]}. #{f}"
26
+ else
27
+ lau["name"] = "#{f}"
28
+ # lau["ins"] = "#{g[0]}. #{f}"
29
+ end
30
+ end
31
+ if (f = au["affiliation"]) && Array === f
32
+ names = f.map { |affn|
33
+ if Hash === affn && (n = affn["name"]) && String === n
34
+ n
35
+ end
36
+ }.compact
37
+ if names.size > 0
38
+ lau["org"] = names.join("; ")
39
+ end
40
+ end
41
+ lau
42
+ end
43
+ end
44
+ if iss = cite["issued"]
45
+ if dp = iss["date-parts"]
46
+ if Integer === (dp = dp[0])[0]
47
+ lit["date"] = ["%04d" % dp[0], *dp[1..-1].map {|p| "%02d" % p}].join("-")
48
+ end
49
+ end
50
+ end
51
+ if !lit.key?("date") && fuzzy && (iss = cite["created"])
52
+ if dp = iss["date-parts"]
53
+ if Integer === (dp = dp[0])[0]
54
+ lit["date"] = ["%04d" % dp[0], *dp[1..-1].map {|p| "%02d" % p}].join("-")
55
+ end
56
+ end
57
+ end
58
+ if (ct = cite["container-title"]) && ct != []
59
+ info = []
60
+ if v = cite["volume"]
61
+ vi = "vol. #{v}"
62
+ if (v = cite["journal-issue"]) && (issue = v["issue"])
63
+ vi << ", no. #{issue}"
64
+ end
65
+ info << vi
66
+ end
67
+ if p = cite["page"]
68
+ info << "pp. #{p}"
69
+ end
70
+ rhs = info.join(", ")
71
+ if info != []
72
+ ser[ct] = rhs
73
+ else
74
+ spl = ct.split(" ")
75
+ ser[spl[0..-2].join(" ")] = spl[-1]
76
+ end
77
+ elsif pub = cite["publisher"]
78
+ info = []
79
+ if t = cite["type"]
80
+ info << t
81
+ end
82
+ rhs = info.join(", ")
83
+ if info != []
84
+ ser[pub] = rhs
85
+ else
86
+ spl = pub.split(" ")
87
+ ser[spl[0..-2].join(" ")] = spl[-1]
88
+ end
89
+ end
90
+ ser["DOI"] = cite["DOI"]
91
+ lit
92
+ end
@@ -22,6 +22,8 @@ require 'open3' # for math
22
22
  require 'json' # for math
23
23
  require 'rexml/document' # for SVG and bibxml acrobatics
24
24
 
25
+ require 'kramdown-rfc/doi' # for fetching information for a DOI
26
+
25
27
  class Object
26
28
  def deep_clone
27
29
  Marshal.load(Marshal.dump(self))
@@ -1002,6 +1004,12 @@ COLORS
1002
1004
  warn "(#{"%.3f" % (t2 - t1)} s)" if KRAMDOWN_PERSISTENT_VERBOSE
1003
1005
  end
1004
1006
 
1007
+ def get_doi(refname)
1008
+ lit = doi_fetch_and_convert(refname, fuzzy: true)
1009
+ anchor = "DOI_#{refname.gsub("/", "_")}"
1010
+ KramdownRFC::ref_to_xml(anchor, lit)
1011
+ end
1012
+
1005
1013
  # this is now slightly dangerous as multiple urls could map to the same cachefile
1006
1014
  def get_and_cache_resource(url, cachefile, tvalid = 7200, tn = Time.now)
1007
1015
  fn = "#{REFCACHEDIR}/#{cachefile}"
@@ -1016,7 +1024,17 @@ COLORS
1016
1024
  fetch_timeout = 60 # seconds; long timeout needed for Travis
1017
1025
  end
1018
1026
  $stderr.puts "#{fn}: #{message} from #{url}"
1019
- if ENV["HAVE_WGET"]
1027
+ if Array === url
1028
+ begin
1029
+ case url[0]
1030
+ when :DOI
1031
+ ref = get_doi(url[1])
1032
+ File.write(fn, ref)
1033
+ end
1034
+ rescue Exception => e
1035
+ warn "*** Error fetching #{url[0]} #{url[1].inspect}: #{e}"
1036
+ end
1037
+ elsif ENV["HAVE_WGET"]
1020
1038
  `cd #{REFCACHEDIR}; wget -t 3 -T #{fetch_timeout} -Nnv "#{url}"` # ignore errors if offline (hack)
1021
1039
  begin
1022
1040
  File.utime nil, nil, fn
@@ -1089,7 +1107,8 @@ COLORS
1089
1107
  "NIST" => "bibxml2",
1090
1108
  "OASIS" => "bibxml2",
1091
1109
  "PKCS" => "bibxml2",
1092
- "DOI" => ["bibxml7", 86400, true], # 24 h cache at source anyway
1110
+ "DOI" => ["bibxml7", 86400, true, ->(fn, n){ [fn, [:DOI, n] ] }
1111
+ ], # emulate old 24 h cache
1093
1112
  "IANA" => ["bibxml8", 86400, true], # ditto
1094
1113
  }
1095
1114
 
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.6.13
4
+ version: 1.6.14
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-06-29 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -100,6 +100,7 @@ files:
100
100
  - kramdown-rfc2629.gemspec
101
101
  - lib/kramdown-rfc/autolink-iref-cleanup.rb
102
102
  - lib/kramdown-rfc/command.rb
103
+ - lib/kramdown-rfc/doi.rb
103
104
  - lib/kramdown-rfc/erb.rb
104
105
  - lib/kramdown-rfc/gzip-clone.rb
105
106
  - lib/kramdown-rfc/kdrfc-processor.rb