kramdown-rfc2629 1.4.19 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/kdrfc +18 -150
- data/kramdown-rfc2629.gemspec +1 -1
- data/lib/kramdown-rfc/kdrfc-processor.rb +154 -0
- data/lib/kramdown-rfc2629.rb +19 -4
- 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: 296e6b41d770f71cc7266daefdbef48425bd7b050ae3be467badabf1f2f8453d
|
4
|
+
data.tar.gz: 12ca2cd06a9d6911f4f4db728210909ccb23a44563c4ae8ac5beaaf044fb550e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8adf6c1c27f37b30468b6c593f3faa334adfba8953f99160ac842bfcc98bb7dde0ef02e36ea65450b9ea519ac46a200e5631c9a3bd5832296ef78b7aa18fb8a
|
7
|
+
data.tar.gz: ee84d6769775ea513fea5240bdf1d552f7a724213840363d76a0510a53d9cae8ae56dd2de342f6b1540f5e2c5f9fe085b53ad7e4ca9ccd15ee598798f7a2be65
|
data/bin/kdrfc
CHANGED
@@ -1,127 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby -KU
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require 'open3'
|
2
|
+
require 'kramdown-rfc/kdrfc-processor'
|
3
|
+
require 'optparse'
|
5
4
|
|
6
5
|
# try to get this from gemspec.
|
7
6
|
KDRFC_VERSION=Gem.loaded_specs["kramdown-rfc2629"].version rescue "unknown-version"
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
def v3_flag?
|
12
|
-
$options.v3 ? ["--v3"] : []
|
13
|
-
end
|
14
|
-
|
15
|
-
def process_mkd(input, output)
|
16
|
-
warn "* converting locally from markdown #{input} to xml #{output}" if $options.verbose
|
17
|
-
o, s = Open3.capture2(*KDRFC_PREPEND, "kramdown-rfc2629", *v3_flag?, input)
|
18
|
-
if s.success?
|
19
|
-
File.open(output, "w") do |fo|
|
20
|
-
fo.print(o)
|
21
|
-
end
|
22
|
-
warn "* #{output} written" if $options.verbose
|
23
|
-
else
|
24
|
-
warn "*** kramdown-rfc failed, status #{s.exitstatus}"
|
25
|
-
exit 1
|
26
|
-
end
|
27
|
-
end
|
8
|
+
kdrfc = KramdownRFC::KDRFC.new
|
9
|
+
kdrfc.options.txt = true # default
|
28
10
|
|
29
|
-
def run_idnits(txt_fn)
|
30
|
-
unless system("idnits", txt_fn)
|
31
|
-
warn "*** problem #$? running idnits"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def process_xml(*args)
|
36
|
-
if $options.remote
|
37
|
-
process_xml_remotely(*args)
|
38
|
-
else
|
39
|
-
process_xml_locally(*args)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def process_xml_locally(input, output, *flags)
|
44
|
-
warn "* converting locally from xml #{input} to txt #{output}" if $options.verbose
|
45
|
-
begin
|
46
|
-
o, s = Open3.capture2(*KDRFC_PREPEND, "xml2rfc", *v3_flag?, *flags, input)
|
47
|
-
puts o
|
48
|
-
if s.success?
|
49
|
-
warn "* #{output} written" if $options.verbose
|
50
|
-
else
|
51
|
-
warn "*** xml2rfc failed, status #{s.exitstatus} (possibly try with -r)"
|
52
|
-
exit 1
|
53
|
-
end
|
54
|
-
rescue Errno::ENOENT
|
55
|
-
warn "*** falling back to remote processing" if $options.verbose
|
56
|
-
process_xml_remotely(input, output, *flags)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
XML2RFC_WEBSERVICE = ENV["KRAMDOWN_XML2RFC_WEBSERVICE"] ||
|
61
|
-
'http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc-dev.cgi'
|
62
|
-
|
63
|
-
MODE_AS_FORMAT = {
|
64
|
-
nil => { # v2
|
65
|
-
"--text" => "txt/ascii",
|
66
|
-
"--html" => "html/ascii",
|
67
|
-
},
|
68
|
-
true => { # v3
|
69
|
-
"--text" => "txt/v3ascii",
|
70
|
-
"--html" => "html/v3ascii",
|
71
|
-
"--v2v3" => "v3xml/ascii",
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
def process_xml_remotely(input, output, *flags)
|
76
|
-
warn "* converting remotely from xml #{input} to txt #{output}" if $options.verbose
|
77
|
-
format = flags[0] || "--text"
|
78
|
-
# warn [:V3, $options.v3].inspect
|
79
|
-
maf = MODE_AS_FORMAT[$options.v3][format]
|
80
|
-
unless maf
|
81
|
-
warn "*** don't know how to convert remotely from xml #{input} to txt #{output}"
|
82
|
-
exit(1)
|
83
|
-
end
|
84
|
-
url = URI(XML2RFC_WEBSERVICE)
|
85
|
-
req = Net::HTTP::Post.new(url)
|
86
|
-
form = [["modeAsFormat", maf],
|
87
|
-
["type", "binary"],
|
88
|
-
["input", File.open(input),
|
89
|
-
{filename: "input.xml",
|
90
|
-
content_type: "text/plain"}]]
|
91
|
-
diag = ["url/form: ", url, form].inspect
|
92
|
-
req.set_form(form, 'multipart/form-data')
|
93
|
-
res = Net::HTTP::start(url.hostname, url.port,
|
94
|
-
:use_ssl => url.scheme == 'https' ) {|http|
|
95
|
-
http.request(req)
|
96
|
-
}
|
97
|
-
case res
|
98
|
-
when Net::HTTPOK
|
99
|
-
case res.content_type
|
100
|
-
when 'application/octet-stream'
|
101
|
-
if res.body == ''
|
102
|
-
warn "*** HTTP response is empty with status #{res.code}, not written"
|
103
|
-
exit 1
|
104
|
-
end
|
105
|
-
File.open(output, "w") do |fo|
|
106
|
-
fo.print(res.body)
|
107
|
-
end
|
108
|
-
warn "* #{output} written" if $options.verbose
|
109
|
-
else
|
110
|
-
warn "*** HTTP response has unexpected content_type #{res.content_type} with status #{res.code}, #{diag}"
|
111
|
-
warn res.body
|
112
|
-
exit 1
|
113
|
-
end
|
114
|
-
else
|
115
|
-
warn "*** HTTP response: #{res.code}, #{diag}"
|
116
|
-
exit 1
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
require 'optparse'
|
121
|
-
require 'ostruct'
|
122
|
-
|
123
|
-
$options = OpenStruct.new
|
124
|
-
$options.txt = true # default
|
125
11
|
op = OptionParser.new do |opts|
|
126
12
|
opts.banner = <<BANNER
|
127
13
|
Usage: kdrfc [options] file.md|file.mkd|file.xml
|
@@ -136,63 +22,45 @@ BANNER
|
|
136
22
|
exit
|
137
23
|
end
|
138
24
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
139
|
-
|
25
|
+
kdrfc.options.verbose = v
|
140
26
|
end
|
141
27
|
opts.on("-r", "--[no-]remote", "Run xml2rfc remotely even if there is a local one") do |v|
|
142
|
-
|
28
|
+
kdrfc.options.remote = v
|
143
29
|
end
|
144
30
|
opts.on("-x", "--[no-]xml", "Convert to xml only") do |v|
|
145
|
-
|
31
|
+
kdrfc.options.xml_only = v
|
146
32
|
end
|
147
33
|
opts.on("-p", "--[no-]prep", "Convert xml to prepped xml") do |v|
|
148
|
-
|
34
|
+
kdrfc.options.prep = v
|
149
35
|
end
|
150
36
|
opts.on("-P", "-f", "--[no-]pdf", "Convert xml to PDF") do |v|
|
151
|
-
|
37
|
+
kdrfc.options.pdf = v
|
152
38
|
end
|
153
39
|
opts.on("-c", "--[no-]convert", "Convert xml to v3 xml") do |v|
|
154
|
-
|
40
|
+
kdrfc.options.v2v3 = v
|
155
41
|
end
|
156
42
|
opts.on("-i", "--[no-]idnits", "Run idnits on the resulting text") do |v|
|
157
|
-
|
43
|
+
kdrfc.options.idnits = v
|
158
44
|
end
|
159
45
|
opts.on("-h", "--[no-]html", "Convert to html as well") do |v|
|
160
|
-
|
46
|
+
kdrfc.options.html = v
|
161
47
|
end
|
162
48
|
opts.on("-t", "--[no-]txt", "Convert to txt as well") do |v|
|
163
|
-
|
49
|
+
kdrfc.options.txt = v
|
164
50
|
end
|
165
51
|
opts.on("-3", "--[no-]v3", "Use RFCXML v3 processing rules") do |v|
|
166
|
-
|
52
|
+
kdrfc.options.v3 = v
|
167
53
|
end
|
168
54
|
end
|
169
55
|
op.parse!
|
170
56
|
|
171
|
-
def process_the_xml(fn, base)
|
172
|
-
process_xml(fn, "#{base}.prepped.xml", "--preptool") if $options.prep
|
173
|
-
process_xml(fn, "#{base}.v2v3.xml", "--v2v3") if $options.v2v3
|
174
|
-
process_xml(fn, "#{base}.txt") if $options.txt || $options.idnits
|
175
|
-
process_xml(fn, "#{base}.html", "--html") if $options.html
|
176
|
-
process_xml(fn, "#{base}.pdf", "--pdf") if $options.pdf
|
177
|
-
run_idnits("#{base}.txt") if $options.idnits
|
178
|
-
end
|
179
|
-
|
180
57
|
case ARGV.size
|
181
58
|
when 1
|
182
59
|
fn = ARGV[0]
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
else # FIXME: copy/paste
|
188
|
-
process_the_xml(fn, $1)
|
189
|
-
end
|
190
|
-
when /(.*)\.mk?d\z/
|
191
|
-
xml = "#$1.xml"
|
192
|
-
process_mkd(fn, xml)
|
193
|
-
process_the_xml(xml, $1) unless $options.xml_only
|
194
|
-
else
|
195
|
-
warn "Unknown file type: #{fn}"
|
60
|
+
begin
|
61
|
+
kdrfc.process(fn)
|
62
|
+
rescue StandardError => e
|
63
|
+
warn e.to_s
|
196
64
|
exit 1
|
197
65
|
end
|
198
66
|
else
|
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
|
+
s.version = '1.5.1'
|
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,154 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'open3'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
module KramdownRFC
|
7
|
+
|
8
|
+
class KDRFC
|
9
|
+
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@options = OpenStruct.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# )))
|
17
|
+
|
18
|
+
KDRFC_PREPEND = [ENV["KDRFC_PREPEND"]].compact
|
19
|
+
|
20
|
+
def v3_flag?
|
21
|
+
@options.v3 ? ["--v3"] : []
|
22
|
+
end
|
23
|
+
|
24
|
+
def process_mkd(input, output)
|
25
|
+
warn "* converting locally from markdown #{input} to xml #{output}" if @options.verbose
|
26
|
+
o, s = Open3.capture2(*KDRFC_PREPEND, "kramdown-rfc2629", *v3_flag?, input)
|
27
|
+
if s.success?
|
28
|
+
File.open(output, "w") do |fo|
|
29
|
+
fo.print(o)
|
30
|
+
end
|
31
|
+
warn "* #{output} written" if @options.verbose
|
32
|
+
else
|
33
|
+
raise IOError.new("*** kramdown-rfc failed, status #{s.exitstatus}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def run_idnits(txt_fn)
|
38
|
+
unless system("idnits", txt_fn)
|
39
|
+
warn "*** problem #$? running idnits"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def process_xml(*args)
|
44
|
+
if @options.remote
|
45
|
+
process_xml_remotely(*args)
|
46
|
+
else
|
47
|
+
process_xml_locally(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def process_xml_locally(input, output, *flags)
|
52
|
+
warn "* converting locally from xml #{input} to txt #{output}" if @options.verbose
|
53
|
+
begin
|
54
|
+
o, s = Open3.capture2(*KDRFC_PREPEND, "xml2rfc", *v3_flag?, *flags, input)
|
55
|
+
puts o
|
56
|
+
if s.success?
|
57
|
+
warn "* #{output} written" if @options.verbose
|
58
|
+
else
|
59
|
+
raise IOError.new("*** xml2rfc failed, status #{s.exitstatus} (possibly try with -r)")
|
60
|
+
end
|
61
|
+
rescue Errno::ENOENT
|
62
|
+
warn "*** falling back to remote xml2rfc processing (web service)" # if @options.verbose
|
63
|
+
process_xml_remotely(input, output, *flags)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
XML2RFC_WEBSERVICE = ENV["KRAMDOWN_XML2RFC_WEBSERVICE"] ||
|
68
|
+
'http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc-dev.cgi'
|
69
|
+
|
70
|
+
MODE_AS_FORMAT = {
|
71
|
+
nil => { # v2
|
72
|
+
"--text" => "txt/ascii",
|
73
|
+
"--html" => "html/ascii",
|
74
|
+
},
|
75
|
+
true => { # v3
|
76
|
+
"--text" => "txt/v3ascii",
|
77
|
+
"--html" => "html/v3ascii",
|
78
|
+
"--v2v3" => "v3xml/ascii",
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
def process_xml_remotely(input, output, *flags)
|
83
|
+
warn "* converting remotely from xml #{input} to txt #{output}" if @options.verbose
|
84
|
+
format = flags[0] || "--text"
|
85
|
+
# warn [:V3, @options.v3].inspect
|
86
|
+
maf = MODE_AS_FORMAT[@options.v3][format]
|
87
|
+
unless maf
|
88
|
+
raise ArgumentError.new("*** don't know how to convert remotely from xml #{input} to txt #{output}")
|
89
|
+
end
|
90
|
+
url = URI(XML2RFC_WEBSERVICE)
|
91
|
+
req = Net::HTTP::Post.new(url)
|
92
|
+
form = [["modeAsFormat", maf],
|
93
|
+
["type", "binary"],
|
94
|
+
["input", File.open(input),
|
95
|
+
{filename: "input.xml",
|
96
|
+
content_type: "text/plain"}]]
|
97
|
+
diag = ["url/form: ", url, form].inspect
|
98
|
+
req.set_form(form, 'multipart/form-data')
|
99
|
+
res = Net::HTTP::start(url.hostname, url.port,
|
100
|
+
:use_ssl => url.scheme == 'https' ) {|http|
|
101
|
+
http.request(req)
|
102
|
+
}
|
103
|
+
case res
|
104
|
+
when Net::HTTPOK
|
105
|
+
case res.content_type
|
106
|
+
when 'application/octet-stream'
|
107
|
+
if res.body == ''
|
108
|
+
raise IOError.new("*** HTTP response is empty with status #{res.code}, not written")
|
109
|
+
end
|
110
|
+
File.open(output, "w") do |fo|
|
111
|
+
fo.print(res.body)
|
112
|
+
end
|
113
|
+
warn "* #{output} written" if @options.verbose
|
114
|
+
else
|
115
|
+
warning = "*** HTTP response has unexpected content_type #{res.content_type} with status #{res.code}, #{diag}"
|
116
|
+
warning << "\n"
|
117
|
+
warning << res.body
|
118
|
+
raise IOError.new(warning)
|
119
|
+
end
|
120
|
+
else
|
121
|
+
raise IOError.new("*** HTTP response: #{res.code}, #{diag}")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def process_the_xml(fn, base)
|
126
|
+
process_xml(fn, "#{base}.prepped.xml", "--preptool") if @options.prep
|
127
|
+
process_xml(fn, "#{base}.v2v3.xml", "--v2v3") if @options.v2v3
|
128
|
+
process_xml(fn, "#{base}.txt") if @options.txt || @options.idnits
|
129
|
+
process_xml(fn, "#{base}.html", "--html") if @options.html
|
130
|
+
process_xml(fn, "#{base}.pdf", "--pdf") if @options.pdf
|
131
|
+
run_idnits("#{base}.txt") if @options.idnits
|
132
|
+
end
|
133
|
+
|
134
|
+
def process(fn)
|
135
|
+
case fn
|
136
|
+
when /(.*)\.xml\z/
|
137
|
+
if @options.xml_only
|
138
|
+
warn "*** You already have XML"
|
139
|
+
else # FIXME: copy/paste
|
140
|
+
process_the_xml(fn, $1)
|
141
|
+
end
|
142
|
+
when /(.*)\.mk?d\z/
|
143
|
+
xml = "#$1.xml"
|
144
|
+
process_mkd(fn, xml)
|
145
|
+
process_the_xml(xml, $1) unless @options.xml_only
|
146
|
+
else
|
147
|
+
raise ArgumentError.new("Unknown file type: #{fn}")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# (((
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
data/lib/kramdown-rfc2629.rb
CHANGED
@@ -53,6 +53,9 @@ module Kramdown
|
|
53
53
|
|
54
54
|
def self.idref_cleanup(href)
|
55
55
|
# can't start an IDREF with a number or reserved start
|
56
|
+
if href =~ / /
|
57
|
+
warn "** space(s) in cross-reference '#{href}' -- are you trying to use section references?"
|
58
|
+
end
|
56
59
|
href.gsub(/\A(?:[0-9]|section-|u-|figure-|table-|iref-)/) { "_#{$&}" }
|
57
60
|
end
|
58
61
|
|
@@ -1032,18 +1035,30 @@ COLORS
|
|
1032
1035
|
# this would be more like xml2rfc v3:
|
1033
1036
|
# "\n#{' '*indent}<cref>\n#{inner(el.value, indent, opts).rstrip}\n#{' '*indent}</cref>"
|
1034
1037
|
content = inner(el.value, indent, opts).strip
|
1035
|
-
content =
|
1038
|
+
content = content.sub(/\A<t>(.*)<\/t>\z/m) {$1}
|
1036
1039
|
name = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(el.options[:name])
|
1040
|
+
o_name = name.dup
|
1037
1041
|
while @footnote_names_in_use[name] do
|
1038
|
-
if name =~
|
1042
|
+
if name =~ /_\d+\z/
|
1039
1043
|
name.succ!
|
1040
1044
|
else
|
1041
|
-
name << "
|
1045
|
+
name << "_1"
|
1042
1046
|
end
|
1043
1047
|
end
|
1044
1048
|
@footnote_names_in_use[name] = true
|
1045
1049
|
attrstring = el_html_attributes_with(el, {"anchor" => name})
|
1046
|
-
|
1050
|
+
if $options.v3
|
1051
|
+
if o_name[-1] == "-"
|
1052
|
+
# Ignore HTML attributes. Hmm.
|
1053
|
+
content
|
1054
|
+
else
|
1055
|
+
# do not indent span-level so we can stick to previous word. Good?
|
1056
|
+
"<cref#{attrstring}>#{content}</cref>"
|
1057
|
+
end
|
1058
|
+
else
|
1059
|
+
content = escape_html(content, :text) # text only...
|
1060
|
+
"\n#{' '*indent}<cref#{attrstring}>#{content}</cref>"
|
1061
|
+
end
|
1047
1062
|
end
|
1048
1063
|
|
1049
1064
|
def convert_raw(el, indent, opts)
|
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
|
+
version: 1.5.1
|
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-07-
|
11
|
+
date: 2021-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- kramdown-rfc2629.gemspec
|
81
81
|
- lib/kramdown-rfc/erb.rb
|
82
82
|
- lib/kramdown-rfc/gzip-clone.rb
|
83
|
+
- lib/kramdown-rfc/kdrfc-processor.rb
|
83
84
|
- lib/kramdown-rfc/parameterset.rb
|
84
85
|
- lib/kramdown-rfc/refxml.rb
|
85
86
|
- lib/kramdown-rfc2629.rb
|
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
103
|
- !ruby/object:Gem::Version
|
103
104
|
version: '0'
|
104
105
|
requirements: []
|
105
|
-
rubygems_version: 3.2.
|
106
|
+
rubygems_version: 3.2.22
|
106
107
|
signing_key:
|
107
108
|
specification_version: 4
|
108
109
|
summary: Kramdown extension for generating RFC 7749 XML.
|