kramdown-rfc2629 1.3.29 → 1.3.34
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 +4 -4
- data/kramdown-rfc2629.gemspec +1 -1
- data/lib/kramdown-rfc2629.rb +107 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea9fb4169327aa3629088261ef7ca4f99b6cdc205326d782a8c43d97818f76b
|
4
|
+
data.tar.gz: 1319c3c4e0435633b9dac413c5ed13384a10b245708b8abf55c8c943178ba9e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79cedc2bf3905da08feafd6a856d67d4f4928cc53d21ed2035b05607e2ce55bf8ec455cb7a94f67afc4296c813b05668d425d5c280a1f0e61b435c611dd66ad8
|
7
|
+
data.tar.gz: e9026c235426738610a9d3d5a4a2a3d803a5afde25714cab72e4012e882cc285e82755d41d3dfe2d89a8456a044c4c7b1fb14e6f53992db93b3b8d1ac1f2ba1d
|
data/kramdown-rfc2629.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'kramdown-rfc2629'
|
3
|
-
s.version = '1.3.
|
3
|
+
s.version = '1.3.34'
|
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.}
|
data/lib/kramdown-rfc2629.rb
CHANGED
@@ -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 }
|
@@ -361,9 +373,12 @@ COLORS
|
|
361
373
|
[result, result1] # text, svg
|
362
374
|
end
|
363
375
|
|
376
|
+
ARTWORK_TYPES = %w(ascii-art binary-art call-flow hex-dump svg)
|
377
|
+
|
364
378
|
def convert_codeblock(el, indent, opts)
|
365
379
|
# el.attr['anchor'] ||= saner_generate_id(el.value) -- no longer in 1.0.6
|
366
380
|
result = el.value
|
381
|
+
gi = el.attr.delete('gi')
|
367
382
|
blockclass = el.attr.delete('class')
|
368
383
|
if blockclass == 'language-tbreak'
|
369
384
|
result = result.lines.map {|line| [line.chomp, 0]}
|
@@ -390,7 +405,7 @@ COLORS
|
|
390
405
|
if md = cl.match(/\Alanguage-(.*)/)
|
391
406
|
t = artwork_attr["type"] = md[1] # XXX overwrite
|
392
407
|
else
|
393
|
-
$stderr.puts "*** Unimplemented
|
408
|
+
$stderr.puts "*** Unimplemented codeblock class: #{cl}"
|
394
409
|
end
|
395
410
|
end
|
396
411
|
end
|
@@ -399,17 +414,27 @@ COLORS
|
|
399
414
|
result[0,0] = "\n" unless result[0,1] == "\n"
|
400
415
|
end
|
401
416
|
el.attr.each do |k, v|
|
402
|
-
if md = k.match(/\
|
417
|
+
if md = k.match(/\A(?:artwork|sourcecode)-(.*)/)
|
403
418
|
el.attr.delete(k)
|
404
419
|
artwork_attr[md[1]] = v
|
405
420
|
end
|
406
421
|
end
|
407
422
|
case t
|
408
423
|
when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt", "mermaid", "math"
|
424
|
+
if gi
|
425
|
+
warn "*** Can't set GI #{gi} for composite SVG artset"
|
426
|
+
end
|
409
427
|
result, result1 = memoize(:svg_tool_process, t, result)
|
410
428
|
"#{' '*indent}<figure#{el_html_attributes(el)}><artset><artwork #{html_attributes(artwork_attr.merge("type"=> "svg"))}>#{result1.sub(/.*?<svg/m, "<svg")}</artwork><artwork #{html_attributes(artwork_attr.merge("type"=> "ascii-art"))}><![CDATA[#{result}#{result =~ /\n\Z/ ? '' : "\n"}]]></artwork></artset></figure>\n"
|
411
429
|
else
|
412
|
-
|
430
|
+
gi ||= (
|
431
|
+
if !$options.v3 || !t || ARTWORK_TYPES.include?(t)
|
432
|
+
"artwork"
|
433
|
+
else
|
434
|
+
"sourcecode"
|
435
|
+
end
|
436
|
+
)
|
437
|
+
"#{' '*indent}<figure#{el_html_attributes(el)}><#{gi}#{html_attributes(artwork_attr)}><![CDATA[#{result}#{result =~ /\n\Z/ ? '' : "\n"}]]></#{gi}></figure>\n"
|
413
438
|
end
|
414
439
|
end
|
415
440
|
end
|
@@ -682,6 +707,34 @@ COLORS
|
|
682
707
|
KRAMDOWN_OFFLINE = ENV["KRAMDOWN_OFFLINE"]
|
683
708
|
KRAMDOWN_REFCACHE_REFETCH = ENV["KRAMDOWN_REFCACHE_REFETCH"]
|
684
709
|
|
710
|
+
def get_and_write_resource(url, fn)
|
711
|
+
options = {}
|
712
|
+
if ENV["KRAMDOWN_DONT_VERIFY_HTTPS"]
|
713
|
+
options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE
|
714
|
+
end # workaround for OpenSSL on Windows...
|
715
|
+
# URI.open(url, **options) do |uf| # not portable to older versions
|
716
|
+
OpenURI.open_uri(url, **options) do |uf|
|
717
|
+
s = uf.read
|
718
|
+
if uf.status[0] != "200"
|
719
|
+
warn "*** Status code #{status} while fetching #{url}"
|
720
|
+
else
|
721
|
+
File.write(fn, s)
|
722
|
+
end
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
def get_and_write_resource_persistently(url, fn)
|
727
|
+
t1 = Time.now
|
728
|
+
response = $http.request(URI(url))
|
729
|
+
if response.code != "200"
|
730
|
+
raise "Status code #{response.code} while fetching #{url}"
|
731
|
+
else
|
732
|
+
File.write(fn, response.body)
|
733
|
+
end
|
734
|
+
t2 = Time.now
|
735
|
+
warn "(#{"%.3f" % (t2 - t1)} s)" if KRAMDOWN_PERSISTENT_VERBOSE
|
736
|
+
end
|
737
|
+
|
685
738
|
# this is now slightly dangerous as multiple urls could map to the same cachefile
|
686
739
|
def get_and_cache_resource(url, cachefile, tvalid = 7200, tn = Time.now)
|
687
740
|
fn = "#{REFCACHEDIR}/#{cachefile}"
|
@@ -695,7 +748,7 @@ COLORS
|
|
695
748
|
message = "fetching"
|
696
749
|
fetch_timeout = 60 # seconds; long timeout needed for Travis
|
697
750
|
end
|
698
|
-
$stderr.puts "#{fn}: #{message}"
|
751
|
+
$stderr.puts "#{fn}: #{message} from #{url}"
|
699
752
|
if ENV["HAVE_WGET"]
|
700
753
|
`cd #{REFCACHEDIR}; wget -t 3 -T #{fetch_timeout} -Nnv "#{url}"` # ignore errors if offline (hack)
|
701
754
|
begin
|
@@ -710,18 +763,15 @@ COLORS
|
|
710
763
|
require 'timeout'
|
711
764
|
begin
|
712
765
|
Timeout::timeout(fetch_timeout) do
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
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)
|
766
|
+
if $http
|
767
|
+
begin # belt and suspenders
|
768
|
+
get_and_write_resource_persistently(url, fn)
|
769
|
+
rescue Exception => e
|
770
|
+
warn "*** Can't get with persistent HTTP: #{e}"
|
771
|
+
get_and_write_resource(url, fn)
|
724
772
|
end
|
773
|
+
else
|
774
|
+
get_and_write_resource(url, fn)
|
725
775
|
end
|
726
776
|
end
|
727
777
|
rescue OpenURI::HTTPError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED,
|
@@ -739,8 +789,12 @@ COLORS
|
|
739
789
|
|
740
790
|
# [subdirectory name, cache ttl in seconds, does it provide for ?anchor=]
|
741
791
|
XML_RESOURCE_ORG_MAP = {
|
742
|
-
"RFC" => ["bibxml", 86400*7
|
743
|
-
|
792
|
+
"RFC" => ["bibxml", 86400*7, false,
|
793
|
+
->(fn, n){ "https://www.rfc-editor.org/refs/bibxml/#{fn}"}
|
794
|
+
],
|
795
|
+
"I-D" => ["bibxml3", false, false,
|
796
|
+
->(fn, n){ "https://datatracker.ietf.org/doc/bibxml3/draft-#{n.sub(/\Adraft-/, '')}/xml" }
|
797
|
+
],
|
744
798
|
"W3C" => "bibxml4",
|
745
799
|
"3GPP" => "bibxml5",
|
746
800
|
"ANSI" => "bibxml2",
|
@@ -761,9 +815,12 @@ COLORS
|
|
761
815
|
XML_RESOURCE_ORG_HOST = ENV["XML_RESOURCE_ORG_HOST"] || "xml2rfc.tools.ietf.org"
|
762
816
|
XML_RESOURCE_ORG_PREFIX = ENV["XML_RESOURCE_ORG_PREFIX"] ||
|
763
817
|
"https://#{XML_RESOURCE_ORG_HOST}/public/rfc"
|
818
|
+
KRAMDOWN_USE_TOOLS_SERVER = ENV["KRAMDOWN_USE_TOOLS_SERVER"]
|
764
819
|
|
765
820
|
KRAMDOWN_REFCACHETTL = (e = ENV["KRAMDOWN_REFCACHETTL"]) ? e.to_i : 3600
|
766
821
|
|
822
|
+
KRAMDOWN_NO_TARGETS = ENV['KRAMDOWN_NO_TARGETS']
|
823
|
+
|
767
824
|
def convert_img(el, indent, opts) # misuse the tag!
|
768
825
|
if a = el.attr
|
769
826
|
alt = a.delete('alt').strip
|
@@ -783,18 +840,46 @@ COLORS
|
|
783
840
|
to_insert = ""
|
784
841
|
src.scan(/(W3C|3GPP|[A-Z-]+)[.]?([A-Za-z_0-9.\/\+-]+)/) do |t, n|
|
785
842
|
fn = "reference.#{t}.#{n}.xml"
|
786
|
-
sub, ttl,
|
843
|
+
sub, ttl, _can_anchor, altproc = XML_RESOURCE_ORG_MAP[t]
|
787
844
|
ttl ||= KRAMDOWN_REFCACHETTL # everything but RFCs might change a lot
|
788
845
|
puts "*** Huh: #{fn}" unless sub
|
789
|
-
|
846
|
+
if altproc && !KRAMDOWN_USE_TOOLS_SERVER
|
847
|
+
url = altproc.call(fn, n)
|
848
|
+
else
|
849
|
+
url = "#{XML_RESOURCE_ORG_PREFIX}/#{sub}/#{fn}"
|
850
|
+
end
|
790
851
|
# if can_anchor # create anchor server-side for stand_alone: false
|
791
852
|
# url << "?anchor=#{anchor}"
|
792
853
|
# fn[/.xml$/] = "--anchor=#{anchor}.xml"
|
793
854
|
# end
|
794
855
|
to_insert = get_and_cache_resource(url, fn.gsub('/', '_'), ttl)
|
795
856
|
to_insert.scrub! rescue nil # only do this for Ruby >= 2.1
|
857
|
+
|
858
|
+
begin
|
859
|
+
d = REXML::Document.new(to_insert)
|
860
|
+
d.xml_decl.nowrite
|
861
|
+
d.root.attributes["anchor"] = anchor
|
862
|
+
if t == "RFC" or t == "I-D"
|
863
|
+
if KRAMDOWN_NO_TARGETS
|
864
|
+
d.root.attributes["target"] = nil
|
865
|
+
REXML::XPath.each(d.root, "/reference/format") { |x|
|
866
|
+
d.root.delete_element(x)
|
867
|
+
}
|
868
|
+
else
|
869
|
+
REXML::XPath.each(d.root, "/reference/format") { |x|
|
870
|
+
x.attributes["target"].sub!(%r{https?://www.ietf.org/internet-drafts/},
|
871
|
+
%{https://www.ietf.org/archive/id/}) if t == "I-D"
|
872
|
+
}
|
873
|
+
end
|
874
|
+
end
|
875
|
+
to_insert = d.to_s
|
876
|
+
rescue Exception => e
|
877
|
+
warn "** Can't manipulate reference XML: #{e}"
|
878
|
+
broken = true
|
879
|
+
to_insert = nil
|
880
|
+
end
|
796
881
|
# this may be a bit controversial: Don't break the build if reference is broken
|
797
|
-
if KRAMDOWN_OFFLINE
|
882
|
+
if KRAMDOWN_OFFLINE || broken
|
798
883
|
unless to_insert
|
799
884
|
to_insert = "<reference anchor='#{anchor}'> <front> <title>*** BROKEN REFERENCE ***</title> <author> <organization/> </author> <date/> </front> </reference>"
|
800
885
|
warn "*** KRAMDOWN_OFFLINE: Inserting broken reference for #{fn}"
|
@@ -803,8 +888,7 @@ COLORS
|
|
803
888
|
exit 66 unless to_insert # EX_NOINPUT
|
804
889
|
end
|
805
890
|
end
|
806
|
-
to_insert
|
807
|
-
.sub(/\banchor=(?:"[^"]+"|'[^']+')/, "anchor=\"#{anchor}\"")
|
891
|
+
to_insert
|
808
892
|
else
|
809
893
|
"<xref#{el_html_attributes(el)}>#{alt}</xref>"
|
810
894
|
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.
|
4
|
+
version: 1.3.34
|
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-
|
11
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|