kramdown-rfc2629 1.3.7 → 1.3.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b34bf25043259c59faad1a28e37420d84708298d7d1132954855e9bc9f80469
4
- data.tar.gz: 598bdd61e5206c389e32e8014469688f516abf4c3b965fc8c14ddd9f10210d63
3
+ metadata.gz: 5d3330c913ba1b37ea44ab8809327795a034032a8c038644f589e0e7dd651b89
4
+ data.tar.gz: cd10426342a1efd28a7c5a9e641539a9982da6b9b4dc8568fe25504406e70efd
5
5
  SHA512:
6
- metadata.gz: ef912cb94fce48cb61f0a352d9a2b0c701eb9c8149fe46608fdff508f2e974289a777d773a5a95dbc433c7cfbbd667aacf0391b68371aa549baabf75a325890d
7
- data.tar.gz: c54c3cc14bdefcbae8a9650522653851af06b9c054ac239eb0555714c85fe5dd14e03fa5d16836c6e12ee83a559ed808c4c4e79d8665592966688f5b6fcba5bd
6
+ metadata.gz: 57cfd0d61702a4b6308ccf53407dcafd4d355fac59d01f7e36c73d287d3d4418410f7dc370c62a91870ae1af3418132aea313fab73103c9f719b14adf08dffaa
7
+ data.tar.gz: 04d8106f180f4b0340984a2e81bfea4736a98d16c38446d833b24588bdc5637076485c9fc5eaf89fe01b05d00a0c62242fc821a3bf20b652c1d268838158a5ec
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,11 +39,17 @@ 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(open("https://dx.doi.org/#{doi}", ACCEPT_CITE_JSON).read)
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"] = {}
46
46
  lit["title"] = cite["title"]
47
+ if (st = cite["subtitle"]) && Array === st # defensive
48
+ st.delete('')
49
+ if st != []
50
+ lit["title"] << ": " << st.join("; ")
51
+ end
52
+ end
47
53
  if authors = cite["author"]
48
54
  lit["author"] = authors.map do |au|
49
55
  lau = {}
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
@@ -46,16 +49,21 @@ def process_xml_locally(input, output, *flags)
46
49
  end
47
50
  end
48
51
 
52
+ XML2RFC_WEBSERVICE = ENV["KRAMDOWN_XML2RFC_WEBSERVICE"] ||
53
+ 'http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc-dev.cgi'
54
+
55
+
49
56
  def process_xml_remotely(input, output)
50
57
  warn "* converting remotely from xml #{input} to txt #{output}" if $options.verbose
51
- url = URI('http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc.cgi')
58
+ url = URI(XML2RFC_WEBSERVICE)
52
59
  req = Net::HTTP::Post.new(url)
53
- req.set_form([["modeAsFormat", "txt/#{"v3" if $options.v3}ascii"],
54
- ["type", "binary"],
55
- ["input", File.open(input),
56
- {filename: "input.xml",
57
- content_type: "text/plain"}]],
58
- 'multipart/form-data')
60
+ form = [["modeAsFormat", "txt/#{"v3" if $options.v3}ascii"],
61
+ ["type", "binary"],
62
+ ["input", File.open(input),
63
+ {filename: "input.xml",
64
+ content_type: "text/plain"}]]
65
+ diag = ["url/form: ", url, form].inspect
66
+ req.set_form(form, 'multipart/form-data')
59
67
  res = Net::HTTP::start(url.hostname, url.port,
60
68
  :use_ssl => url.scheme == 'https' ) {|http|
61
69
  http.request(req)
@@ -64,17 +72,21 @@ def process_xml_remotely(input, output)
64
72
  when Net::HTTPOK
65
73
  case res.content_type
66
74
  when 'application/octet-stream'
75
+ if res.body == ''
76
+ warn "*** HTTP response is empty with status #{res.code}, not written"
77
+ exit 1
78
+ end
67
79
  File.open(output, "w") do |fo|
68
80
  fo.print(res.body)
69
81
  end
70
82
  warn "* #{output} written" if $options.verbose
71
83
  else
72
- warn "*** HTTP response has unexpected content_type #{res.content_type} with status #{res.code}"
84
+ warn "*** HTTP response has unexpected content_type #{res.content_type} with status #{res.code}, #{diag}"
73
85
  warn res.body
74
86
  exit 1
75
87
  end
76
88
  else
77
- warn "*** HTTP response: #{res.code}"
89
+ warn "*** HTTP response: #{res.code}, #{diag}"
78
90
  exit 1
79
91
  end
80
92
  end
@@ -85,8 +97,18 @@ require 'ostruct'
85
97
  $options = OpenStruct.new
86
98
  $options.txt = true # default
87
99
  op = OptionParser.new do |opts|
88
- opts.banner = "Usage: kdrfc [options] file.md|file.mkd|file.xml"
89
-
100
+ opts.banner = <<BANNER
101
+ Usage: kdrfc [options] file.md|file.mkd|file.xml
102
+ Version: #{KDRFC_VERSION}
103
+ BANNER
104
+ opts.on("-V", "--version", "Show version and exit") do |v|
105
+ puts "kdrfc, from kramdown-rfc2629 #{KDRFC_VERSION}"
106
+ exit
107
+ end
108
+ opts.on("-H", "--help", "Show option summary and exit") do |v|
109
+ puts opts
110
+ exit
111
+ end
90
112
  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
91
113
  $options.verbose = v
92
114
  end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby2.1
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 = "Usage: kramdown-rfc2629 [options] file.md|file.mkd > file.xml"
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
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.3.7'
3
+ s.version = '1.3.12'
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
@@ -150,16 +150,110 @@ 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
+
184
+ def svg_munch_color(c, fill)
185
+ c = SVG_COLORS[c]
186
+ case c
187
+ when /\A#(..)(..)(..)\z/
188
+ if hex_to_lin($1)*0.2126 + hex_to_lin($2)*0.7152 + hex_to_lin($3)*0.0722 >= B_W_THRESHOLD
189
+ 'white'
190
+ else
191
+ 'black'
192
+ end
193
+ when 'none'
194
+ 'none' if fill # delete for stroke
195
+ else
196
+ c
197
+ end
198
+ end
199
+
153
200
  def svg_clean(s) # expensive, risky
154
201
  require "rexml/document"
155
202
  d = REXML::Document.new(s)
156
203
  REXML::XPath.each(d.root, "//*[@shape-rendering]") { |x| x.attributes["shape-rendering"] = nil } #; warn x.inspect }
157
204
  REXML::XPath.each(d.root, "//*[@text-rendering]") { |x| x.attributes["text-rendering"] = nil } #; warn x.inspect }
158
- REXML::XPath.each(d.root, "//*[@stroke='#000000']") { |x| x.attributes["stroke"] = "black" } #; warn x.inspect }
159
- REXML::XPath.each(d.root, "//*[@stroke='none']") { |x| x.attributes["stroke"] = nil } #; warn x.inspect }
205
+ REXML::XPath.each(d.root, "//*[@stroke]") { |x| x.attributes["stroke"] = svg_munch_color(x.attributes["stroke"], false) }
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"] }
160
209
  d.to_s
161
210
  end
162
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
+
163
257
  def convert_codeblock(el, indent, opts)
164
258
  # el.attr['anchor'] ||= saner_generate_id(el.value) -- no longer in 1.0.6
165
259
  result = el.value
@@ -204,25 +298,8 @@ module Kramdown
204
298
  end
205
299
  end
206
300
  case t
207
- when "goat", "ditaa", "mscgen"
208
- require 'tempfile'
209
- file = Tempfile.new("kramdown-rfc")
210
- file.write(result)
211
- file.close
212
- case t
213
- when "goat"
214
- result1, _s = Open3.capture2("goat #{file.path}", stdin_data: result);
215
- when "ditaa" # XXX: This needs some form of option-setting
216
- result1, _s = Open3.capture2("ditaa #{file.path} --svg -o -", stdin_data: result);
217
- result1 = svg_clean(result1)
218
- when "mscgen"
219
- result1, _s = Open3.capture2("mscgen -T svg -i #{file.path} -o -", stdin_data: result);
220
- result1 = svg_clean(result1)
221
- end
222
- # warn ["goat:", result1.inspect]
223
- file.unlink
224
- result1, _s = Open3.capture2("svgcheck -qa", stdin_data: result1);
225
- # warn ["svgcheck:", result1.inspect]
301
+ when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt", "mermaid"
302
+ result, result1 = memoize(:svg_tool_process, t, result)
226
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"
227
304
  else
228
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.7
4
+ version: 1.3.12
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-05-30 00:00:00.000000000 Z
11
+ date: 2020-09-03 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: []