kramdown-rfc2629 1.3.28 → 1.3.33

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: c6818d86a47ba8a06c199cdbca16a30644b06c4bb517fc7a5a5a35d93161a0e6
4
- data.tar.gz: cb90602fd0b11b2e010200ffc4fac1727cd0aa446d2e59e5861d4fcd6b1cf579
3
+ metadata.gz: 7b532912e56847cec71ed5c419ea08af4d19d3f6c7a4d91edffbfaa3005dd37f
4
+ data.tar.gz: 6dbf519c9eadbddb50a07f6b1cef88cdcc9d877a5f66614ececf6bf5bc2d3353
5
5
  SHA512:
6
- metadata.gz: b2c6ca51eaf892fb8b52c4bf115a82830deb1df21afcc0fb28c58eabbe273b727872be851d5e858c1018ce97e3ee5b8e7464086d4652a17af2f1144dda5f86a4
7
- data.tar.gz: fb3125ce8ee03845999ad6f7e09cc9047ee4f4f3406da987c6a1458c0a4de65d0c2d590f62d02c516aa1d3de4d71e21660d33313fbf370452d57ee98d0a472ee
6
+ metadata.gz: 0f7f9faf79c570a7bcca633aef94a6f27d997d861eca1ecad0855795eef44728d925cc1d1b7751454b6c122168d12ef4f341b4ed350d8aeb9247b53e13d523ba
7
+ data.tar.gz: 2dcdb7cf588bd99e8e983b71eefbbb0a2aec8785f466abe8e83f6b7ea40061aecea69abe6466d94d2dc69c019dd798a0569e5ed66b65efc42bf76d448ef45778
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.3.28'
3
+ s.version = '1.3.33'
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.}
@@ -20,6 +20,7 @@ Kramdown::Parser::Html::Constants::HTML_SPAN_ELEMENTS.concat my_span_elements
20
20
  require 'rexml/parsers/baseparser'
21
21
  require 'open3' # for math
22
22
  require 'json' # for math
23
+ require 'rexml/document' # for SVG and bibxml acrobatics
23
24
 
24
25
  class Object
25
26
  def deep_clone
@@ -178,6 +179,18 @@ module Kramdown
178
179
 
179
180
  # :stopdoc:
180
181
 
182
+ KRAMDOWN_PERSISTENT = ENV["KRAMDOWN_PERSISTENT"]
183
+ KRAMDOWN_PERSISTENT_VERBOSE = /v/ === KRAMDOWN_PERSISTENT
184
+
185
+ if KRAMDOWN_PERSISTENT
186
+ begin
187
+ require 'net/http/persistent'
188
+ $http = Net::HTTP::Persistent.new name: 'kramdown-rfc'
189
+ rescue Exception => e
190
+ warn "** Can't set up persistent HTTP -- #{e}"
191
+ end
192
+ end
193
+
181
194
  # Defines the amount of indentation used when nesting XML tags.
182
195
  INDENTATION = 2
183
196
 
@@ -281,7 +294,6 @@ COLORS
281
294
  end
282
295
 
283
296
  def svg_clean(s) # expensive, risky
284
- require "rexml/document"
285
297
  d = REXML::Document.new(s)
286
298
  REXML::XPath.each(d.root, "//*[@shape-rendering]") { |x| x.attributes["shape-rendering"] = nil } #; warn x.inspect }
287
299
  REXML::XPath.each(d.root, "//*[@text-rendering]") { |x| x.attributes["text-rendering"] = nil } #; warn x.inspect }
@@ -682,6 +694,34 @@ COLORS
682
694
  KRAMDOWN_OFFLINE = ENV["KRAMDOWN_OFFLINE"]
683
695
  KRAMDOWN_REFCACHE_REFETCH = ENV["KRAMDOWN_REFCACHE_REFETCH"]
684
696
 
697
+ def get_and_write_resource(url, fn)
698
+ options = {}
699
+ if ENV["KRAMDOWN_DONT_VERIFY_HTTPS"]
700
+ options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE
701
+ end # workaround for OpenSSL on Windows...
702
+ # URI.open(url, **options) do |uf| # not portable to older versions
703
+ OpenURI.open_uri(url, **options) do |uf|
704
+ s = uf.read
705
+ if uf.status[0] != "200"
706
+ warn "*** Status code #{status} while fetching #{url}"
707
+ else
708
+ File.write(fn, s)
709
+ end
710
+ end
711
+ end
712
+
713
+ def get_and_write_resource_persistently(url, fn)
714
+ t1 = Time.now
715
+ response = $http.request(URI(url))
716
+ if response.code != "200"
717
+ raise "Status code #{response.code} while fetching #{url}"
718
+ else
719
+ File.write(fn, response.body)
720
+ end
721
+ t2 = Time.now
722
+ warn "(#{"%.3f" % (t2 - t1)} s)" if KRAMDOWN_PERSISTENT_VERBOSE
723
+ end
724
+
685
725
  # this is now slightly dangerous as multiple urls could map to the same cachefile
686
726
  def get_and_cache_resource(url, cachefile, tvalid = 7200, tn = Time.now)
687
727
  fn = "#{REFCACHEDIR}/#{cachefile}"
@@ -695,7 +735,7 @@ COLORS
695
735
  message = "fetching"
696
736
  fetch_timeout = 60 # seconds; long timeout needed for Travis
697
737
  end
698
- $stderr.puts "#{fn}: #{message}"
738
+ $stderr.puts "#{fn}: #{message} from #{url}"
699
739
  if ENV["HAVE_WGET"]
700
740
  `cd #{REFCACHEDIR}; wget -t 3 -T #{fetch_timeout} -Nnv "#{url}"` # ignore errors if offline (hack)
701
741
  begin
@@ -710,18 +750,15 @@ COLORS
710
750
  require 'timeout'
711
751
  begin
712
752
  Timeout::timeout(fetch_timeout) do
713
- options = {}
714
- if ENV["KRAMDOWN_DONT_VERIFY_HTTPS"]
715
- options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE
716
- end # workaround for OpenSSL on Windows...
717
- # URI.open(url, **options) do |uf| # not portable to older versions
718
- OpenURI.open_uri(url, **options) do |uf|
719
- s = uf.read
720
- if uf.status[0] != "200"
721
- warn "*** Status code #{status} while fetching #{url}"
722
- else
723
- File.write(fn, s)
753
+ if $http
754
+ begin # belt and suspenders
755
+ get_and_write_resource_persistently(url, fn)
756
+ rescue Exception => e
757
+ warn "*** Can't get with persistent HTTP: #{e}"
758
+ get_and_write_resource(url, fn)
724
759
  end
760
+ else
761
+ get_and_write_resource(url, fn)
725
762
  end
726
763
  end
727
764
  rescue OpenURI::HTTPError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED,
@@ -739,8 +776,12 @@ COLORS
739
776
 
740
777
  # [subdirectory name, cache ttl in seconds, does it provide for ?anchor=]
741
778
  XML_RESOURCE_ORG_MAP = {
742
- "RFC" => ["bibxml", 86400*7], # these should change rarely
743
- "I-D" => "bibxml3",
779
+ "RFC" => ["bibxml", 86400*7, false,
780
+ ->(fn, n){ "https://www.rfc-editor.org/refs/bibxml/#{fn}"}
781
+ ],
782
+ "I-D" => ["bibxml3", false, false,
783
+ ->(fn, n){ "https://datatracker.ietf.org/doc/bibxml3/draft-#{n.sub(/\Adraft-/, '')}/xml" }
784
+ ],
744
785
  "W3C" => "bibxml4",
745
786
  "3GPP" => "bibxml5",
746
787
  "ANSI" => "bibxml2",
@@ -761,9 +802,12 @@ COLORS
761
802
  XML_RESOURCE_ORG_HOST = ENV["XML_RESOURCE_ORG_HOST"] || "xml2rfc.tools.ietf.org"
762
803
  XML_RESOURCE_ORG_PREFIX = ENV["XML_RESOURCE_ORG_PREFIX"] ||
763
804
  "https://#{XML_RESOURCE_ORG_HOST}/public/rfc"
805
+ KRAMDOWN_USE_TOOLS_SERVER = ENV["KRAMDOWN_USE_TOOLS_SERVER"]
764
806
 
765
807
  KRAMDOWN_REFCACHETTL = (e = ENV["KRAMDOWN_REFCACHETTL"]) ? e.to_i : 3600
766
808
 
809
+ KRAMDOWN_NO_TARGETS = ENV['KRAMDOWN_NO_TARGETS']
810
+
767
811
  def convert_img(el, indent, opts) # misuse the tag!
768
812
  if a = el.attr
769
813
  alt = a.delete('alt').strip
@@ -783,18 +827,46 @@ COLORS
783
827
  to_insert = ""
784
828
  src.scan(/(W3C|3GPP|[A-Z-]+)[.]?([A-Za-z_0-9.\/\+-]+)/) do |t, n|
785
829
  fn = "reference.#{t}.#{n}.xml"
786
- sub, ttl, can_anchor = XML_RESOURCE_ORG_MAP[t]
830
+ sub, ttl, _can_anchor, altproc = XML_RESOURCE_ORG_MAP[t]
787
831
  ttl ||= KRAMDOWN_REFCACHETTL # everything but RFCs might change a lot
788
832
  puts "*** Huh: #{fn}" unless sub
789
- url = "#{XML_RESOURCE_ORG_PREFIX}/#{sub}/#{fn}"
790
- if can_anchor # create anchor server-side for stand_alone: false
791
- url << "?anchor=#{anchor}"
792
- fn[/.xml$/] = "--anchor=#{anchor}.xml"
833
+ if altproc && !KRAMDOWN_USE_TOOLS_SERVER
834
+ url = altproc.call(fn, n)
835
+ else
836
+ url = "#{XML_RESOURCE_ORG_PREFIX}/#{sub}/#{fn}"
793
837
  end
838
+ # if can_anchor # create anchor server-side for stand_alone: false
839
+ # url << "?anchor=#{anchor}"
840
+ # fn[/.xml$/] = "--anchor=#{anchor}.xml"
841
+ # end
794
842
  to_insert = get_and_cache_resource(url, fn.gsub('/', '_'), ttl)
795
843
  to_insert.scrub! rescue nil # only do this for Ruby >= 2.1
844
+
845
+ begin
846
+ d = REXML::Document.new(to_insert)
847
+ d.xml_decl.nowrite
848
+ d.root.attributes["anchor"] = anchor
849
+ if t == "RFC" or t == "I-D"
850
+ if KRAMDOWN_NO_TARGETS
851
+ d.root.attributes["target"] = nil
852
+ REXML::XPath.each(d.root, "/reference/format") { |x|
853
+ d.root.delete_element(x)
854
+ }
855
+ else
856
+ REXML::XPath.each(d.root, "/reference/format") { |x|
857
+ x.attributes["target"].sub!(%r{https?://www.ietf.org/internet-drafts/},
858
+ %{https://www.ietf.org/archive/id/}) if t == "I-D"
859
+ }
860
+ end
861
+ end
862
+ to_insert = d.to_s
863
+ rescue Exception => e
864
+ warn "** Can't manipulate reference XML: #{e}"
865
+ broken = true
866
+ to_insert = nil
867
+ end
796
868
  # this may be a bit controversial: Don't break the build if reference is broken
797
- if KRAMDOWN_OFFLINE
869
+ if KRAMDOWN_OFFLINE || broken
798
870
  unless to_insert
799
871
  to_insert = "<reference anchor='#{anchor}'> <front> <title>*** BROKEN REFERENCE ***</title> <author> <organization/> </author> <date/> </front> </reference>"
800
872
  warn "*** KRAMDOWN_OFFLINE: Inserting broken reference for #{fn}"
@@ -803,8 +875,7 @@ COLORS
803
875
  exit 66 unless to_insert # EX_NOINPUT
804
876
  end
805
877
  end
806
- to_insert.sub(/<\?xml version=["']1.0["'] encoding=["']UTF-8["']\?>/, '')
807
- .sub(/\banchor=(?:"[^"]+"|'[^']+')/, "anchor=\"#{anchor}\"")
878
+ to_insert
808
879
  else
809
880
  "<xref#{el_html_attributes(el)}>#{alt}</xref>"
810
881
  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.3.28
4
+ version: 1.3.33
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-02-05 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown