kramdown-rfc2629 1.3.8 → 1.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -0
- data/bin/doilit +1 -1
- data/bin/kdrfc +15 -2
- data/bin/kramdown-rfc2629 +16 -3
- data/kramdown-rfc2629.gemspec +1 -2
- data/lib/kramdown-rfc2629.rb +82 -25
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 935147add478f6b51b8baec2b762249c862a71c6f04b52c1e648a27e197a33f0
|
4
|
+
data.tar.gz: e0964c16f72f5d9164a3b7fa8bee23d3c1ba45e1388950738e0f3f8b4ea497cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caabe7a032917db314a4e26c84057a2bcca0c79f7b822f764f7eb0eef2c4434edd7d3a0926419844a5973f05513393e2888f658f177cfdf095be9a417ac1b77c
|
7
|
+
data.tar.gz: 351f6ee80ac9bcfb74cace2abd78601858c9dd8d67126b55f44d8547b30d0073469ea39dbb01ca81535c42de62962683ff25921f662429ea0e2cb8483a931efd
|
data/README.md
CHANGED
@@ -281,6 +281,31 @@ special support in XML2RFC), and HTML syntax of course.
|
|
281
281
|
A number of more esoteric features have recently been added.
|
282
282
|
(The minimum required version for each full feature is indicated.)
|
283
283
|
|
284
|
+
(1.3.x)
|
285
|
+
Slowly improving support for SVG generating tools for XML2RFCv3 (i.e.,
|
286
|
+
with `-3` flag).
|
287
|
+
These tools must be installed and callable from the command line.
|
288
|
+
|
289
|
+
The basic idea is to mark an input code block with one of the following
|
290
|
+
labels (language types), yielding some plaintext form in the .TXT
|
291
|
+
output and a graphical form in the .HTML output. The plaintext is the
|
292
|
+
input in some cases (e.g., ASCII art, `mscgen`), or some plaintext
|
293
|
+
output generated by the tool (e.g., `plantuml-utxt`).
|
294
|
+
|
295
|
+
Currently supported labels as of 1.3.9:
|
296
|
+
|
297
|
+
* goat, ditaa: ASCII (plaintext) art to figure conversion
|
298
|
+
* mscgen: Message Sequence Charts
|
299
|
+
* plantuml: widely used multi-purpose diagram generator
|
300
|
+
* plantuml-utxt: Like plantuml, except that a plantuml-generated
|
301
|
+
plaintext form is used
|
302
|
+
* mermaid: Very experimental; the conversion to SVG is prone to
|
303
|
+
generate black-on-black text in this version
|
304
|
+
|
305
|
+
Note that this feature does not play well with the CI (continuous
|
306
|
+
integration) support in Martin Thomson's [I-D Template][], as that may
|
307
|
+
not have the tools installed in its docker instance.
|
308
|
+
|
284
309
|
(1.2.9:)
|
285
310
|
The YAML header now allows specifying [kramdown_options][].
|
286
311
|
|
data/bin/doilit
CHANGED
@@ -39,7 +39,7 @@ ARGV.each do |doi|
|
|
39
39
|
warn "*** Usage: doilit [-c] [-v] [-h=handle|-x=xmlhandle] doi..."
|
40
40
|
exit 1
|
41
41
|
end
|
42
|
-
cite = JSON.parse(
|
42
|
+
cite = JSON.parse(URI("https://dx.doi.org/#{doi}").open(ACCEPT_CITE_JSON).read)
|
43
43
|
puts cite.to_yaml if $verbose
|
44
44
|
lit = {}
|
45
45
|
ser = lit["seriesinfo"] = {}
|
data/bin/kdrfc
CHANGED
@@ -3,6 +3,9 @@ require 'uri'
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'open3'
|
5
5
|
|
6
|
+
# try to get this from gemspec.
|
7
|
+
KDRFC_VERSION=Gem.loaded_specs["kramdown-rfc2629"].version rescue "unknown-version"
|
8
|
+
|
6
9
|
def v3_flag?
|
7
10
|
$options.v3 ? ["--v3"] : []
|
8
11
|
end
|
@@ -85,8 +88,18 @@ require 'ostruct'
|
|
85
88
|
$options = OpenStruct.new
|
86
89
|
$options.txt = true # default
|
87
90
|
op = OptionParser.new do |opts|
|
88
|
-
opts.banner =
|
89
|
-
|
91
|
+
opts.banner = <<BANNER
|
92
|
+
Usage: kdrfc [options] file.md|file.mkd|file.xml
|
93
|
+
Version: #{KDRFC_VERSION}
|
94
|
+
BANNER
|
95
|
+
opts.on("-V", "--version", "Show version and exit") do |v|
|
96
|
+
puts "kdrfc, from kramdown-rfc2629 #{KDRFC_VERSION}"
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
opts.on("-H", "--help", "Show option summary and exit") do |v|
|
100
|
+
puts opts
|
101
|
+
exit
|
102
|
+
end
|
90
103
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
91
104
|
$options.verbose = v
|
92
105
|
end
|
data/bin/kramdown-rfc2629
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
require 'kramdown-rfc2629'
|
4
4
|
require 'kramdown-rfc/parameterset'
|
@@ -7,6 +7,9 @@ require 'yaml'
|
|
7
7
|
require 'erb'
|
8
8
|
require 'date'
|
9
9
|
|
10
|
+
# try to get this from gemspec.
|
11
|
+
KDRFC_VERSION=Gem.loaded_specs["kramdown-rfc2629"].version rescue "unknown-version"
|
12
|
+
|
10
13
|
Encoding.default_external = "UTF-8" # wake up, smell the coffee
|
11
14
|
|
12
15
|
def boilerplate(key)
|
@@ -287,8 +290,18 @@ require 'ostruct'
|
|
287
290
|
|
288
291
|
$options = OpenStruct.new
|
289
292
|
op = OptionParser.new do |opts|
|
290
|
-
opts.banner =
|
291
|
-
|
293
|
+
opts.banner = <<BANNER
|
294
|
+
Usage: kramdown-rfc2629 [options] file.md|file.mkd > file.xml
|
295
|
+
Version: #{KDRFC_VERSION}
|
296
|
+
BANNER
|
297
|
+
opts.on("-V", "--version", "Show version and exit") do |v|
|
298
|
+
puts "kramdown-rfc2629 #{KDRFC_VERSION}"
|
299
|
+
exit
|
300
|
+
end
|
301
|
+
opts.on("-H", "--help", "Show option summary and exit") do |v|
|
302
|
+
puts opts
|
303
|
+
exit
|
304
|
+
end
|
292
305
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
293
306
|
$options.verbose = v
|
294
307
|
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.3.
|
3
|
+
s.version = '1.3.9'
|
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.}
|
@@ -9,7 +9,6 @@ spec = Gem::Specification.new do |s|
|
|
9
9
|
s.files = Dir['lib/**/*.rb'] + %w(README.md LICENSE kramdown-rfc2629.gemspec bin/kdrfc bin/kramdown-rfc2629 bin/doilit bin/kramdown-rfc-extract-markdown data/kramdown-rfc2629.erb data/encoding-fallbacks.txt)
|
10
10
|
s.require_path = 'lib'
|
11
11
|
s.executables = ['kramdown-rfc2629', 'doilit', 'kramdown-rfc-extract-markdown', 'kdrfc']
|
12
|
-
s.default_executable = 'kramdown-rfc2629'
|
13
12
|
s.required_ruby_version = '>= 2.3.0'
|
14
13
|
# s.requirements = 'wget'
|
15
14
|
# s.has_rdoc = true
|
data/lib/kramdown-rfc2629.rb
CHANGED
@@ -150,10 +150,42 @@ module Kramdown
|
|
150
150
|
generate_id(value).gsub(/-+/, '-')
|
151
151
|
end
|
152
152
|
|
153
|
+
SVG_COLORS = Hash.new {|h, k| k}
|
154
|
+
<<COLORS.each_line {|l| k, v = l.chomp.split; SVG_COLORS[k] = v}
|
155
|
+
black #000000
|
156
|
+
silver #C0C0C0
|
157
|
+
gray #808080
|
158
|
+
white #FFFFFF
|
159
|
+
maroon #800000
|
160
|
+
red #FF0000
|
161
|
+
purple #800080
|
162
|
+
fuchsia #FF00FF
|
163
|
+
green #008000
|
164
|
+
lime #00FF00
|
165
|
+
olive #808000
|
166
|
+
yellow #FFFF00
|
167
|
+
navy #000080
|
168
|
+
blue #0000FF
|
169
|
+
teal #008080
|
170
|
+
aqua #00FFFF
|
171
|
+
COLORS
|
172
|
+
|
173
|
+
def svg_munch_id(id)
|
174
|
+
id.gsub(/[^-._A-Za-z0-9]/) {|x| "_%02X" % x.ord}
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.hex_to_lin(h)
|
178
|
+
h.to_i(16)**2.22 # approximating sRGB gamma
|
179
|
+
end
|
180
|
+
define_method :hex_to_lin, &method(:hex_to_lin)
|
181
|
+
|
182
|
+
B_W_THRESHOLD = hex_to_lin("a4") # a little brighter than 1/2 0xFF -> white
|
183
|
+
|
153
184
|
def svg_munch_color(c, fill)
|
185
|
+
c = SVG_COLORS[c]
|
154
186
|
case c
|
155
187
|
when /\A#(..)(..)(..)\z/
|
156
|
-
if
|
188
|
+
if hex_to_lin($1)*0.2126 + hex_to_lin($2)*0.7152 + hex_to_lin($3)*0.0722 >= B_W_THRESHOLD
|
157
189
|
'white'
|
158
190
|
else
|
159
191
|
'black'
|
@@ -172,9 +204,56 @@ module Kramdown
|
|
172
204
|
REXML::XPath.each(d.root, "//*[@text-rendering]") { |x| x.attributes["text-rendering"] = nil } #; warn x.inspect }
|
173
205
|
REXML::XPath.each(d.root, "//*[@stroke]") { |x| x.attributes["stroke"] = svg_munch_color(x.attributes["stroke"], false) }
|
174
206
|
REXML::XPath.each(d.root, "//*[@fill]") { |x| x.attributes["fill"] = svg_munch_color(x.attributes["fill"], true) }
|
207
|
+
REXML::XPath.each(d.root, "//*[@id]") { |x| x.attributes["id"] = svg_munch_id(x.attributes["id"]) }
|
208
|
+
## REXML::XPath.each(d.root, "//rect") { |x| x.attributes["style"] = "fill:none;stroke:black;stroke-width:1" unless x.attributes["style"] }
|
175
209
|
d.to_s
|
176
210
|
end
|
177
211
|
|
212
|
+
def memoize(meth, *args)
|
213
|
+
require 'digest'
|
214
|
+
Dir.mkdir(REFCACHEDIR) unless Dir.exists?(REFCACHEDIR)
|
215
|
+
kdrfc_version = Gem.loaded_specs["kramdown-rfc2629"].version.to_s.gsub('.', '_') rescue "UNKNOWN"
|
216
|
+
fn = "#{REFCACHEDIR}/kdrfc-#{kdrfc_version}-#{meth}-#{Digest::SHA256.hexdigest(Marshal.dump(args))[0...40]}.cache"
|
217
|
+
begin
|
218
|
+
out = Marshal.load(File.binread(fn))
|
219
|
+
rescue StandardError => e
|
220
|
+
# warn e.inspect
|
221
|
+
out = method(meth).call(*args)
|
222
|
+
File.binwrite(fn, Marshal.dump(out))
|
223
|
+
end
|
224
|
+
out
|
225
|
+
end
|
226
|
+
|
227
|
+
def svg_tool_process(t, result)
|
228
|
+
require 'tempfile'
|
229
|
+
file = Tempfile.new("kramdown-rfc")
|
230
|
+
file.write(result)
|
231
|
+
file.close
|
232
|
+
case t
|
233
|
+
when "goat"
|
234
|
+
result1, _s = Open3.capture2("goat #{file.path}", stdin_data: result);
|
235
|
+
when "ditaa" # XXX: This needs some form of option-setting
|
236
|
+
result1, _s = Open3.capture2("ditaa #{file.path} --svg -o -", stdin_data: result);
|
237
|
+
when "mscgen"
|
238
|
+
result1, _s = Open3.capture2("mscgen -T svg -i #{file.path} -o -", stdin_data: result);
|
239
|
+
when "mermaid"
|
240
|
+
result1, _s = Open3.capture2("mmdc -i #{file.path}", stdin_data: result); # -b transparent
|
241
|
+
outpath = file.path + ".svg"
|
242
|
+
result1 = File.read(outpath)
|
243
|
+
File.unlink(outpath)
|
244
|
+
when "plantuml", "plantuml-utxt"
|
245
|
+
plantuml = "@startuml\n#{result}\n@enduml"
|
246
|
+
result1, _s = Open3.capture2("plantuml -pipe -tsvg", stdin_data: plantuml);
|
247
|
+
result, _s = Open3.capture2("plantuml -pipe -tutxt", stdin_data: plantuml) if t == "plantuml-utxt"
|
248
|
+
end
|
249
|
+
# warn ["goat:", result1.inspect]
|
250
|
+
file.unlink
|
251
|
+
result1 = svg_clean(result1) unless t == "goat"
|
252
|
+
result1, _s = Open3.capture2("svgcheck -qa", stdin_data: result1);
|
253
|
+
# warn ["svgcheck:", result1.inspect]
|
254
|
+
[result, result1]
|
255
|
+
end
|
256
|
+
|
178
257
|
def convert_codeblock(el, indent, opts)
|
179
258
|
# el.attr['anchor'] ||= saner_generate_id(el.value) -- no longer in 1.0.6
|
180
259
|
result = el.value
|
@@ -219,30 +298,8 @@ module Kramdown
|
|
219
298
|
end
|
220
299
|
end
|
221
300
|
case t
|
222
|
-
when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt"
|
223
|
-
|
224
|
-
file = Tempfile.new("kramdown-rfc")
|
225
|
-
file.write(result)
|
226
|
-
file.close
|
227
|
-
case t
|
228
|
-
when "goat"
|
229
|
-
result1, _s = Open3.capture2("goat #{file.path}", stdin_data: result);
|
230
|
-
when "ditaa" # XXX: This needs some form of option-setting
|
231
|
-
result1, _s = Open3.capture2("ditaa #{file.path} --svg -o -", stdin_data: result);
|
232
|
-
result1 = svg_clean(result1)
|
233
|
-
when "mscgen"
|
234
|
-
result1, _s = Open3.capture2("mscgen -T svg -i #{file.path} -o -", stdin_data: result);
|
235
|
-
result1 = svg_clean(result1)
|
236
|
-
when "plantuml", "plantuml-utxt"
|
237
|
-
plantuml = "@startuml\n#{result}\n@enduml"
|
238
|
-
result1, _s = Open3.capture2("plantuml -pipe -tsvg", stdin_data: plantuml);
|
239
|
-
result1 = svg_clean(result1)
|
240
|
-
result, _s = Open3.capture2("plantuml -pipe -tutxt", stdin_data: plantuml) if t == "plantuml-utxt"
|
241
|
-
end
|
242
|
-
# warn ["goat:", result1.inspect]
|
243
|
-
file.unlink
|
244
|
-
result1, _s = Open3.capture2("svgcheck -qa", stdin_data: result1);
|
245
|
-
# warn ["svgcheck:", result1.inspect]
|
301
|
+
when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt", "mermaid"
|
302
|
+
result, result1 = memoize(:svg_tool_process, t, result)
|
246
303
|
"#{' '*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"
|
247
304
|
else
|
248
305
|
"#{' '*indent}<figure#{el_html_attributes(el)}><artwork#{html_attributes(artwork_attr)}><![CDATA[#{result}#{result =~ /\n\Z/ ? '' : "\n"}]]></artwork></figure>\n"
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -67,7 +67,7 @@ homepage: http://github.com/cabo/kramdown-rfc2629
|
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
69
|
metadata: {}
|
70
|
-
post_install_message:
|
70
|
+
post_install_message:
|
71
71
|
rdoc_options: []
|
72
72
|
require_paths:
|
73
73
|
- lib
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubygems_version: 3.1.2
|
86
|
-
signing_key:
|
86
|
+
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Kramdown extension for generating RFC 7749 XML.
|
89
89
|
test_files: []
|