kramdown-rfc2629 1.3.30 → 1.3.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 +4 -4
- data/kramdown-rfc2629.gemspec +1 -1
- data/lib/kramdown-rfc2629.rb +94 -19
- 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: 5c7cb1da81c5398c23b2118c7faf5ee1e620d65e4f3c6078fd27758403e9fa79
|
4
|
+
data.tar.gz: ba71f18945de2bb908e503ef7dd049de8477e57d3ddd5420161d2a9ad37b5589
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8238ed916370bf73c5d21d8d03dbc465528d5865039affb4aeff21d9c1b3e79b5984e76d3df070c33abcb57e739c7312686f8a0754123e34ce2df6ce11287e50
|
7
|
+
data.tar.gz: 9d5ab035fdf87fc4dff43072adb17e24f4933629352787cc3aea7647d0e5fd8a38012ba3bbc52a78926477c6dbd8160a3342dc3a32ad335f25f8769adf362975
|
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.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.}
|
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) || artwork_attr["align"]
|
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}"
|
@@ -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,
|
@@ -769,6 +819,8 @@ COLORS
|
|
769
819
|
|
770
820
|
KRAMDOWN_REFCACHETTL = (e = ENV["KRAMDOWN_REFCACHETTL"]) ? e.to_i : 3600
|
771
821
|
|
822
|
+
KRAMDOWN_NO_TARGETS = ENV['KRAMDOWN_NO_TARGETS']
|
823
|
+
|
772
824
|
def convert_img(el, indent, opts) # misuse the tag!
|
773
825
|
if a = el.attr
|
774
826
|
alt = a.delete('alt').strip
|
@@ -788,7 +840,7 @@ COLORS
|
|
788
840
|
to_insert = ""
|
789
841
|
src.scan(/(W3C|3GPP|[A-Z-]+)[.]?([A-Za-z_0-9.\/\+-]+)/) do |t, n|
|
790
842
|
fn = "reference.#{t}.#{n}.xml"
|
791
|
-
sub, ttl,
|
843
|
+
sub, ttl, _can_anchor, altproc = XML_RESOURCE_ORG_MAP[t]
|
792
844
|
ttl ||= KRAMDOWN_REFCACHETTL # everything but RFCs might change a lot
|
793
845
|
puts "*** Huh: #{fn}" unless sub
|
794
846
|
if altproc && !KRAMDOWN_USE_TOOLS_SERVER
|
@@ -802,8 +854,32 @@ COLORS
|
|
802
854
|
# end
|
803
855
|
to_insert = get_and_cache_resource(url, fn.gsub('/', '_'), ttl)
|
804
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
|
805
881
|
# this may be a bit controversial: Don't break the build if reference is broken
|
806
|
-
if KRAMDOWN_OFFLINE
|
882
|
+
if KRAMDOWN_OFFLINE || broken
|
807
883
|
unless to_insert
|
808
884
|
to_insert = "<reference anchor='#{anchor}'> <front> <title>*** BROKEN REFERENCE ***</title> <author> <organization/> </author> <date/> </front> </reference>"
|
809
885
|
warn "*** KRAMDOWN_OFFLINE: Inserting broken reference for #{fn}"
|
@@ -812,8 +888,7 @@ COLORS
|
|
812
888
|
exit 66 unless to_insert # EX_NOINPUT
|
813
889
|
end
|
814
890
|
end
|
815
|
-
to_insert
|
816
|
-
.sub(/\banchor=(?:"[^"]+"|'[^']+')/, "anchor=\"#{anchor}\"")
|
891
|
+
to_insert
|
817
892
|
else
|
818
893
|
"<xref#{el_html_attributes(el)}>#{alt}</xref>"
|
819
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.35
|
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
|