kramdown-rfc2629 1.5.20 → 1.5.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/kramdown-rfc2629 +46 -30
- data/data/kramdown-rfc2629.erb +14 -4
- data/kramdown-rfc2629.gemspec +1 -1
- data/lib/kramdown-rfc/rfc8792.rb +77 -0
- data/lib/kramdown-rfc2629.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e19def630ee2ad018b297cd5c196e3ee70f052fea88004014a1e8dcc298c050
|
4
|
+
data.tar.gz: eb677f68752221d001095424394b4d276453614bb2286fe77e83d2d3a41d1cfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f54b8a10cb72d16313a4a5c644e52e223539f38b4245d6ca3e54abb28b1704bdbd447d15b0065ad00334df6bbae3a0508f08cd59f0eaf37bfaa717eb52b394ff
|
7
|
+
data.tar.gz: b54e739cba1b21727189cfdf576fc0d8f0bcac1be224bf7affb017c1ddcfd0e2358344a1f162763183b297da2256ca9710e64946b62f79e2e1aa65ec45bdab04
|
data/bin/kramdown-rfc2629
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'kramdown-rfc2629'
|
4
4
|
require 'kramdown-rfc/parameterset'
|
5
5
|
require 'kramdown-rfc/refxml'
|
6
|
+
require 'kramdown-rfc/rfc8792'
|
6
7
|
require 'yaml'
|
7
8
|
require 'kramdown-rfc/erb'
|
8
9
|
require 'date'
|
@@ -24,12 +25,55 @@ def add_quote(s)
|
|
24
25
|
l.map {|li| "> #{li}"}.join
|
25
26
|
end
|
26
27
|
|
27
|
-
def process_chunk(s, dedent, quote)
|
28
|
+
def process_chunk(s, nested, dedent, fold, quote)
|
29
|
+
process_includes(s) if nested
|
28
30
|
s = remove_indentation(s) if dedent
|
31
|
+
s = fold8792_1(s, *fold) if fold
|
29
32
|
s = add_quote(s) if quote
|
30
33
|
s
|
31
34
|
end
|
32
35
|
|
36
|
+
def process_includes(input)
|
37
|
+
input.gsub!(/^\{::include((?:-[a-z0-9]+)*)\s+(.*?)\}/) {
|
38
|
+
include_flags = $1
|
39
|
+
fn = [$2]
|
40
|
+
chunks = false
|
41
|
+
nested = false
|
42
|
+
dedent = false
|
43
|
+
fold = false
|
44
|
+
quote = false
|
45
|
+
include_flags.split("-") do |flag|
|
46
|
+
case flag
|
47
|
+
when ""
|
48
|
+
when "nested"
|
49
|
+
nested = true
|
50
|
+
when "quote"
|
51
|
+
quote = true
|
52
|
+
when "dedent"
|
53
|
+
dedent = true
|
54
|
+
when /\Afold(\d*)(left(\d*))?(dry)?\z/
|
55
|
+
fold = [$1.to_i, # col 0 for ''
|
56
|
+
($3.to_i if $2), # left 0 for '', nil if no "left"
|
57
|
+
$4] # dry
|
58
|
+
when "all", "last"
|
59
|
+
fn = fn.flat_map{|n| Dir[n]}
|
60
|
+
fn = [fn.last] if flag == "last"
|
61
|
+
chunks = fn.map{ |f|
|
62
|
+
ret = process_chunk(File.read(f), nested, dedent, fold, quote)
|
63
|
+
nested = false; dedent = false; fold = false; quote = false
|
64
|
+
ret
|
65
|
+
}
|
66
|
+
else
|
67
|
+
warn "** unknown include flag #{flag}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
chunks = fn.map{|f| File.read(f)} unless chunks # no all/last
|
71
|
+
chunks = chunks.map {|ch| process_chunk(ch, nested, dedent, fold, quote)}
|
72
|
+
chunks.join.chomp
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
|
33
77
|
def boilerplate(key)
|
34
78
|
case key.downcase
|
35
79
|
when /\Abcp14(info)?(\+)?(-tagged)?\z/i
|
@@ -455,35 +499,7 @@ if input[-1] != "\n"
|
|
455
499
|
# warn "*** added missing newline at end"
|
456
500
|
input << "\n" # fix #26
|
457
501
|
end
|
458
|
-
input
|
459
|
-
include_flags = $1
|
460
|
-
fn = [$2]
|
461
|
-
chunks = false
|
462
|
-
dedent = false
|
463
|
-
quote = false
|
464
|
-
include_flags.split("-") do |flag|
|
465
|
-
case flag
|
466
|
-
when ""
|
467
|
-
when "quote"
|
468
|
-
quote = true
|
469
|
-
when "dedent"
|
470
|
-
dedent = true
|
471
|
-
when "all", "last"
|
472
|
-
fn = fn.flat_map{|n| Dir[n]}
|
473
|
-
fn = [fn.last] if flag == "last"
|
474
|
-
chunks = fn.map{ |f|
|
475
|
-
ret = process_chunk(File.read(f), dedent, quote)
|
476
|
-
dedent = false; quote = false
|
477
|
-
ret
|
478
|
-
}
|
479
|
-
else
|
480
|
-
warn "** unknown include flag #{flag}"
|
481
|
-
end
|
482
|
-
end
|
483
|
-
chunks = fn.map{|f| File.read(f)} unless chunks # no all/last
|
484
|
-
chunks = chunks.map {|ch| process_chunk(ch, dedent, quote)}
|
485
|
-
chunks.join.chomp
|
486
|
-
} unless ENV["KRAMDOWN_SAFE"]
|
502
|
+
process_includes(input) unless ENV["KRAMDOWN_SAFE"]
|
487
503
|
input.gsub!(/^\{::boilerplate\s+(.*?)\}/) {
|
488
504
|
boilerplate($1)
|
489
505
|
}
|
data/data/kramdown-rfc2629.erb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
<?xml version="1.0" encoding="<%=ps[:coding]||"UTF-8"%>"?>
|
2
2
|
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
|
3
3
|
<!-- generated by https://github.com/cabo/kramdown-rfc2629 version <%=
|
4
|
-
Gem.loaded_specs["kramdown-rfc2629"].version rescue nil
|
5
|
-
|
4
|
+
Gem.loaded_specs["kramdown-rfc2629"].version rescue nil
|
5
|
+
%> (Ruby <%= RUBY_VERSION %>) -->
|
6
|
+
|
7
|
+
<% if $options.v3 %>
|
8
|
+
<!DOCTYPE rfc <%= ps["doctype-reference"] %> [
|
9
|
+
<!ENTITY nbsp " ">
|
10
|
+
<!ENTITY zwsp "​">
|
11
|
+
<!ENTITY nbhy "‑">
|
12
|
+
<!ENTITY wj "⁠">
|
13
|
+
<% else %>
|
6
14
|
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
|
15
|
+
<% end %>
|
7
16
|
<% ps.arr("bibxml") do |tag, sys| -%>
|
8
17
|
<!ENTITY <%= tag %> SYSTEM "<%= sys %>">
|
9
18
|
<% end -%>
|
@@ -22,7 +31,8 @@
|
|
22
31
|
rfcattrs = ps.attrs("ipr", "docName=docname", "category=cat",
|
23
32
|
"consensus", "submissionType=submissiontype", "xml:lang=lang",
|
24
33
|
"number", "obsoletes", "updates", "seriesNo=seriesno")
|
25
|
-
TRUE_FALSE = {nil => "true", false => "false", true => "true"
|
34
|
+
TRUE_FALSE = {nil => "true", false => "false", true => "true",
|
35
|
+
"yes" => "true", "no" => "false"}
|
26
36
|
YES_NO = {"true" => "yes", "false" => "no"}
|
27
37
|
pis = KramdownRFC::ParameterSet.new({})
|
28
38
|
ps.arr("pi", false) do |pi, val|
|
@@ -36,7 +46,7 @@
|
|
36
46
|
end
|
37
47
|
end
|
38
48
|
pis.rest.each do |pi, val|
|
39
|
-
v = YES_NO[val] ||
|
49
|
+
v = YES_NO[val] || pis.escattr(val)
|
40
50
|
-%>
|
41
51
|
<?rfc <%=pi%>="<%=v%>"?>
|
42
52
|
<% end -%>
|
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.5.
|
3
|
+
s.version = '1.5.25'
|
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.}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
FOLD_MSG = "NOTE: '\\' line wrapping per RFC 8792".freeze
|
2
|
+
MIN_FOLD_COLUMNS = FOLD_MSG.size
|
3
|
+
FOLD_COLUMNS = 69
|
4
|
+
RE_IDENT = /\A[A-Za-z0-9_]\z/
|
5
|
+
|
6
|
+
def fold8792_1(s, columns = FOLD_COLUMNS, left = false, dry = false)
|
7
|
+
if s.index("\t")
|
8
|
+
warn "*** HT (\"TAB\") in text to be folded. Giving up."
|
9
|
+
return s
|
10
|
+
end
|
11
|
+
if columns < MIN_FOLD_COLUMNS
|
12
|
+
columns =
|
13
|
+
if columns == 0
|
14
|
+
FOLD_COLUMNS
|
15
|
+
else
|
16
|
+
warn "*** folding to #{MIN_FOLD_COLUMNS}, not #{columns}"
|
17
|
+
MIN_FOLD_COLUMNS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
lines = s.lines.map(&:chomp)
|
22
|
+
did_fold = false
|
23
|
+
ix = 0
|
24
|
+
while li = lines[ix]
|
25
|
+
col = columns
|
26
|
+
if li[col].nil?
|
27
|
+
if li[-1] == "\\"
|
28
|
+
lines[ix..ix] = [li << "\\", ""]
|
29
|
+
ix += 1
|
30
|
+
end
|
31
|
+
ix += 1
|
32
|
+
else
|
33
|
+
did_fold = true
|
34
|
+
min_indent = left || 0
|
35
|
+
col -= 1 # space for "\\"
|
36
|
+
while li[col] == " " # can't start new line with " "
|
37
|
+
col -= 1
|
38
|
+
end
|
39
|
+
if col <= min_indent
|
40
|
+
warn "*** Cannot RFC8792-fold1 to #{columns} cols #{"with indent #{left}" if left} |#{li.inspect}|"
|
41
|
+
else
|
42
|
+
if RE_IDENT === li[col] # Don't split IDs
|
43
|
+
col2 = col
|
44
|
+
while col2 > min_indent && RE_IDENT === li[col2-1]
|
45
|
+
col2 -= 1
|
46
|
+
end
|
47
|
+
if col2 > min_indent
|
48
|
+
col = col2
|
49
|
+
end
|
50
|
+
end
|
51
|
+
rest = li[col..-1]
|
52
|
+
indent = left || columns - rest.size
|
53
|
+
if !left && li[-1] == "\\"
|
54
|
+
indent -= 1 # leave space for next round
|
55
|
+
end
|
56
|
+
if indent > 0
|
57
|
+
rest = " " * indent + rest
|
58
|
+
end
|
59
|
+
lines[ix..ix] = [li[0...col] << "\\", rest]
|
60
|
+
end
|
61
|
+
ix += 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if did_fold
|
66
|
+
msg = FOLD_MSG.dup
|
67
|
+
if !dry && columns >= msg.size + 4
|
68
|
+
delta = columns - msg.size - 2 # 2 spaces
|
69
|
+
half = delta/2
|
70
|
+
msg = "#{"=" * half} #{msg} #{"=" * (delta - half)}"
|
71
|
+
end
|
72
|
+
lines[0...0] = [msg, ""]
|
73
|
+
lines.map{|x| x << "\n"}.join
|
74
|
+
else
|
75
|
+
s
|
76
|
+
end
|
77
|
+
end
|
data/lib/kramdown-rfc2629.rb
CHANGED
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.5.
|
4
|
+
version: 1.5.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/kramdown-rfc/kdrfc-processor.rb
|
100
100
|
- lib/kramdown-rfc/parameterset.rb
|
101
101
|
- lib/kramdown-rfc/refxml.rb
|
102
|
+
- lib/kramdown-rfc/rfc8792.rb
|
102
103
|
- lib/kramdown-rfc2629.rb
|
103
104
|
homepage: http://github.com/cabo/kramdown-rfc2629
|
104
105
|
licenses:
|
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
120
|
- !ruby/object:Gem::Version
|
120
121
|
version: '0'
|
121
122
|
requirements: []
|
122
|
-
rubygems_version: 3.2.
|
123
|
+
rubygems_version: 3.2.32
|
123
124
|
signing_key:
|
124
125
|
specification_version: 4
|
125
126
|
summary: Kramdown extension for generating RFC 7749 XML.
|