kramdown-rfc2629 1.4.6 → 1.4.7

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: 4b0564f81e1af0b8fd748342c07d417a7d24a5eee8ec5a6cd64f79234ebc192a
4
- data.tar.gz: 2f9e7421b5355b608bc5a41174317bccd4b55e95f1c2089228517003572f19e5
3
+ metadata.gz: 92b7379a1d7172926d1d84ccdc5c816821a0c62c838b597dbc4e92cac91cff0d
4
+ data.tar.gz: b501c48e3ff1bddaca7abec20125dc360de97f67076341d2b9812a3913cbf314
5
5
  SHA512:
6
- metadata.gz: e0aa2949a7d5d28eacdceff68e37fae0338a7f92abab5ed21fcb99414042c528521d844d8e92d14202a0b914eec685149c69dcbdb53d3089a0f72723872d4b63
7
- data.tar.gz: 9424d9efbe85b3ca435ff1691f052097b579ff02247af53a5b463b2eb3cf50bed3761ad4386d87a93df32e6b9a87a4924e1c47eaae0e01b2163473a9e65bf950
6
+ metadata.gz: 3ae6bd5ad655d1300c426b06b00c92a7f56c15636b990d3d0ee02e2cc2a0481a7900d002e6076baa467aa2b3dc309719bedff0fd9e85912f083e85b0a9ef332c
7
+ data.tar.gz: c5cce63d97840efc638bd14240f6652955bb291c46cc038426bb8209c2b65725c14ee3db850954e8ba1bf5f23781f44d388c5d9984be38a4a0f55e63eaef6b1f
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env ruby
2
+ # prerequisite:
3
+ # gem install net-http-persistent
4
+ #
5
+ # generates referencegroup files for BCP and STD series (like bibxml9)
6
+ # unfortunately, needs to re-fetch rfc-index.xml
7
+ # uses pretty slow built-in XML parser, so it will take a while even on regen
8
+ #
9
+ # uses ENV["KRAMDOWN_REFCACHEDIR"] for where you want to have your bibxml9 data
10
+ #
11
+
12
+ require 'rexml/document'
13
+ require 'fileutils'
14
+
15
+ begin
16
+ require 'net/http/persistent'
17
+ rescue
18
+ warn "*** please install net-http-persistent:"
19
+ warn " gem install net-http-persistent"
20
+ warn "(prefix by sudo only if required)."
21
+ exit 72 # EX_OSFILE
22
+ end
23
+
24
+
25
+ TARGET_DIR = ENV["KRAMDOWN_REFCACHEDIR"] || (
26
+ path = File.expand_path("~/.cache/xml2rfc")
27
+ warn "*** set environment variable KRAMDOWN_REFCACHEDIR to #{path} to actually use the cache"
28
+ path
29
+ )
30
+
31
+ FileUtils.mkdir_p(TARGET_DIR)
32
+ FileUtils.chdir(TARGET_DIR)
33
+
34
+ $http = Net::HTTP::Persistent.new name: 'subseries'
35
+
36
+ KRAMDOWN_PERSISTENT_VERBOSE = true
37
+
38
+ def get_and_write_resource_persistently(url, fn, age_verbose=false)
39
+ t1 = Time.now
40
+ response = $http.request(URI(url))
41
+ if response.code != "200"
42
+ raise "*** Status code #{response.code} while fetching #{url}"
43
+ else
44
+ File.write(fn, response.body)
45
+ end
46
+ t2 = Time.now
47
+ warn "#{url} -> #{fn} (#{"%.3f" % (t2 - t1)} s)" if KRAMDOWN_PERSISTENT_VERBOSE
48
+ if age_verbose
49
+ if age = response.get_fields("age")
50
+ warn "(working from a web cache, index is #{age.first} seconds stale)"
51
+ end
52
+ end
53
+ end
54
+
55
+ CLEAR_RET = "\e[K\r" # XXX all the world is ECMA-48 (ISO 6429), no?
56
+
57
+ def noisy(name)
58
+ print "#{name}...#{CLEAR_RET}"
59
+ end
60
+ def clear_noise
61
+ print CLEAR_RET
62
+ end
63
+
64
+ def normalize_name(n)
65
+ n.sub(/([A-Z])0+/) {$1}
66
+ end
67
+
68
+ def regress_name(n)
69
+ n.sub(/([A-Z])(\d+)/) {"#$1#{"%04d" % $2.to_i}"}
70
+ end
71
+
72
+ def regress_name_dot(n)
73
+ n.sub(/([A-Z])(\d+)/) {"#$1.#{"%04d" % $2.to_i}"}
74
+ end
75
+
76
+ def get_ref(rfcname)
77
+ name = "reference.#{regress_name_dot(rfcname)}.xml"
78
+ begin
79
+ file = File.read(name) # no age check
80
+ rescue Errno::ENOENT
81
+ get_and_write_resource_persistently("https://www.rfc-editor.org/refs/bibxml/" << name, name)
82
+ file = File.read(name)
83
+ end
84
+ d = REXML::Document.new(file)
85
+ d.xml_decl.nowrite
86
+ "<!-- #{name} -->\n" << d.to_s.lstrip
87
+ end
88
+
89
+ def create_bib(series, subname, rfcnames)
90
+ p [series, subname, rfcnames]
91
+ subname_norm = normalize_name(subname)
92
+ refs = %{<?xml version='1.0' encoding='UTF-8'?>\n}
93
+ refs << %{<referencegroup anchor='#{subname_norm}' target='https://www.rfc-editor.org/info/#{subname_norm.downcase}'>\n}
94
+ refs << rfcnames.map {|x| get_ref(x)}.join
95
+ refs << "</referencegroup>\n"
96
+ File.write("reference.#{regress_name_dot(subname)}.xml", refs)
97
+ end
98
+
99
+ def handle_sub(series, entry)
100
+ ids = entry.get_elements("doc-id")
101
+ warn "** ids #{ids} #{entry}" unless ids.size == 1
102
+ subname = ids.first.text
103
+ isalso = entry.get_elements("is-also")
104
+ if isalso.size == 1
105
+ rfcs = isalso.first.get_elements("doc-id")
106
+ if rfcs.size > 0
107
+ rfcnames = rfcs.map {|r| r.text}
108
+ create_bib(series, subname, rfcnames)
109
+ end
110
+ end
111
+ end
112
+
113
+ RFCINDEX_SOURCE = "https://www.rfc-editor.org/rfc/rfc-index.xml"
114
+ RFCINDEX_COPY = File.basename(RFCINDEX_SOURCE)
115
+
116
+ get_and_write_resource_persistently(RFCINDEX_SOURCE, RFCINDEX_COPY, true) unless ENV["KRAMDOWN_DONT_REFRESH_RFCINDEX"]
117
+
118
+ doc = REXML::Document.new(File.read(RFCINDEX_COPY))
119
+ REXML::XPath.each(doc.root, "/rfc-index/bcp-entry") { |e| handle_sub("BCP", e) }
120
+ REXML::XPath.each(doc.root, "/rfc-index/std-entry") { |e| handle_sub("STD", e) }
data/bin/kramdown-rfc2629 CHANGED
@@ -269,6 +269,10 @@ def bibtagsys(bib, anchor=nil, stand_alone=true)
269
269
  rfc4d = "%04d" % $1.to_i
270
270
  [bib.upcase,
271
271
  "#{XML_RESOURCE_ORG_PREFIX}/bibxml/reference.RFC.#{rfc4d}.xml"]
272
+ elsif $options.v3 && bib =~ /\A(bcp|std)(\d+)/i
273
+ n4d = "%04d" % $2.to_i
274
+ [bib.upcase,
275
+ "#{XML_RESOURCE_ORG_PREFIX}/bibxml-rfcsubseries-new/reference.#{$1.upcase}.#{n4d}.xml"]
272
276
  elsif bib =~ /\A([-A-Z0-9]+)\./ &&
273
277
  (xro = Kramdown::Converter::Rfc2629::XML_RESOURCE_ORG_MAP[$1])
274
278
  dir, _ttl, rewrite_anchor = xro
@@ -100,7 +100,7 @@
100
100
  <name>Contributors</name>
101
101
  <% else -%>
102
102
  <section anchor="contributors" numbered="false" title="Contributors">
103
- <% warn "*** Cannot process YAML contributors under V2 rules" if consec -%>
103
+ <% warn "*** To use YAML contributors, use --v3 (kdrfc -3)" if consec -%>
104
104
  <% end -%>
105
105
  <%= sh -%>
106
106
  <% if $options.v3 && consec
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.4.6'
3
+ s.version = '1.4.7'
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.}
@@ -10,7 +10,8 @@ spec = Gem::Specification.new do |s|
10
10
  s.files = Dir['lib/**/*.rb'] + %w(README.md LICENSE kramdown-rfc2629.gemspec bin/kdrfc bin/kramdown-rfc2629 bin/doilit bin/kramdown-rfc-extract-markdown data/kramdown-rfc2629.erb data/encoding-fallbacks.txt data/math.json)
11
11
  s.require_path = 'lib'
12
12
  s.executables = ['kramdown-rfc2629', 'doilit', 'kramdown-rfc-extract-markdown',
13
- 'kdrfc', 'kramdown-rfc-cache-i-d-bibxml']
13
+ 'kdrfc', 'kramdown-rfc-cache-i-d-bibxml',
14
+ 'kramdown-rfc-cache-subseries-bibxml']
14
15
  s.required_ruby_version = '>= 2.3.0'
15
16
  # s.requirements = 'wget'
16
17
  # s.has_rdoc = true
@@ -833,13 +833,27 @@ COLORS
833
833
  end
834
834
  end
835
835
 
836
+ def self.bcp_std_ref(t, n)
837
+ warn "*** #{t} anchors not supported in v2 format" unless $options.v3
838
+ [name = "reference.#{t}.#{"%04d" % n.to_i}.xml",
839
+ "#{XML_RESOURCE_ORG_PREFIX}/bibxml-rfcsubseries-new/#{name}"] # FOR NOW
840
+ end
841
+
836
842
  # [subdirectory name, cache ttl in seconds, does it provide for ?anchor=]
837
843
  XML_RESOURCE_ORG_MAP = {
838
844
  "RFC" => ["bibxml", 86400*7, false,
839
- ->(fn, n){ "https://www.rfc-editor.org/refs/bibxml/#{fn}"}
845
+ ->(fn, n){ [name = "reference.RFC.#{"%04d" % n.to_i}.xml",
846
+ "https://www.rfc-editor.org/refs/bibxml/#{name}"] }
840
847
  ],
841
848
  "I-D" => ["bibxml3", false, false,
842
- ->(fn, n){ "https://datatracker.ietf.org/doc/bibxml3/draft-#{n.sub(/\Adraft-/, '')}/xml" }
849
+ ->(fn, n){ [fn,
850
+ "https://datatracker.ietf.org/doc/bibxml3/draft-#{n.sub(/\Adraft-/, '')}/xml"] }
851
+ ],
852
+ "BCP" => ["bibxml-rfcsubseries", 86400*7, false,
853
+ ->(fn, n){ Rfc2629::bcp_std_ref("BCP", n) }
854
+ ],
855
+ "STD" => ["bibxml-rfcsubseries", 86400*7, false,
856
+ ->(fn, n){ Rfc2629::bcp_std_ref("STD", n) }
843
857
  ],
844
858
  "W3C" => "bibxml4",
845
859
  "3GPP" => "bibxml5",
@@ -890,7 +904,7 @@ COLORS
890
904
  ttl ||= KRAMDOWN_REFCACHETTL # everything but RFCs might change a lot
891
905
  puts "*** Huh: #{fn}" unless sub
892
906
  if altproc && !KRAMDOWN_USE_TOOLS_SERVER
893
- url = altproc.call(fn, n)
907
+ fn, url = altproc.call(fn, n)
894
908
  else
895
909
  url = "#{XML_RESOURCE_ORG_PREFIX}/#{sub}/#{fn}"
896
910
  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.4.6
4
+ version: 1.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-29 00:00:00.000000000 Z
11
+ date: 2021-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -62,6 +62,7 @@ executables:
62
62
  - kramdown-rfc-extract-markdown
63
63
  - kdrfc
64
64
  - kramdown-rfc-cache-i-d-bibxml
65
+ - kramdown-rfc-cache-subseries-bibxml
65
66
  extensions: []
66
67
  extra_rdoc_files: []
67
68
  files:
@@ -70,6 +71,7 @@ files:
70
71
  - bin/doilit
71
72
  - bin/kdrfc
72
73
  - bin/kramdown-rfc-cache-i-d-bibxml
74
+ - bin/kramdown-rfc-cache-subseries-bibxml
73
75
  - bin/kramdown-rfc-extract-markdown
74
76
  - bin/kramdown-rfc2629
75
77
  - data/encoding-fallbacks.txt