kramdown-rfc2629 1.4.7 → 1.4.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 +4 -4
- data/bin/kramdown-rfc2629 +37 -10
- data/kramdown-rfc2629.gemspec +1 -1
- data/lib/kramdown-rfc/parameterset.rb +6 -7
- data/lib/kramdown-rfc2629.rb +92 -32
- 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: c6549880c8c2aa06b25b83e8f6fa1bf1bb13d49d99a7250d386ed625114e4ed5
|
4
|
+
data.tar.gz: f16be76792e4158738ff09fca7b36a211ef9fdb5e4ea82c8f2b5c26afbc7e4b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe85445d876074a4e580d1c43016455c9cac6f17b40c3e31a635f42ef1e7eb0f5ecffc1072c7182eff7b887f8e2647aec4742e3b465292bb4e3699af0922b756
|
7
|
+
data.tar.gz: 9027e158afcfc98e233fbbc1a5161c8e2d066907a47fdadc01f89cf3c077035904348218faba1395a70017f6645445133e4f5780818063ea8bee7cf37ae93210
|
data/bin/kramdown-rfc2629
CHANGED
@@ -14,21 +14,29 @@ Encoding.default_external = "UTF-8" # wake up, smell the coffee
|
|
14
14
|
|
15
15
|
def boilerplate(key)
|
16
16
|
case key.downcase
|
17
|
-
when /\Abcp14(\+)?(-tagged)?\z/i
|
18
|
-
ret =
|
17
|
+
when /\Abcp14(info)?(\+)?(-tagged)?\z/i
|
18
|
+
ret = ''
|
19
|
+
if $1
|
20
|
+
ret << <<RFC8174ise
|
21
|
+
Although this document is not an IETF Standards Track publication it
|
22
|
+
adopts the conventions for normative language to provide clarity of
|
23
|
+
instructions to the implementer.
|
24
|
+
RFC8174ise
|
25
|
+
end
|
26
|
+
ret << <<RFC8174
|
19
27
|
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL
|
20
28
|
NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED",
|
21
29
|
"MAY", and "OPTIONAL" in this document are to be interpreted as
|
22
30
|
described in BCP 14 {{!RFC2119}} {{!RFC8174}} when, and only when, they
|
23
31
|
appear in all capitals, as shown here.
|
24
32
|
RFC8174
|
25
|
-
if $
|
33
|
+
if $2
|
26
34
|
ret << <<PLUS
|
27
35
|
These words may also appear in this document in
|
28
36
|
lower case as plain English words, absent their normative meanings.
|
29
37
|
PLUS
|
30
38
|
end
|
31
|
-
if $
|
39
|
+
if $3
|
32
40
|
if $options.v3
|
33
41
|
ret << <<TAGGED
|
34
42
|
|
@@ -89,6 +97,16 @@ def yaml_load(input, *args)
|
|
89
97
|
end
|
90
98
|
end
|
91
99
|
|
100
|
+
XREF_SECTIONS_RE = ::Kramdown::Parser::RFC2629Kramdown::SECTIONS_RE
|
101
|
+
XSR_PREFIX = "#{XREF_SECTIONS_RE} of "
|
102
|
+
XSR_SUFFIX = ", (#{XREF_SECTIONS_RE})| \\((#{XREF_SECTIONS_RE})\\)"
|
103
|
+
XREF_TXT = ::Kramdown::Parser::RFC2629Kramdown::XREF_TXT
|
104
|
+
XREF_TXT_SUFFIX = " \\(#{XREF_TXT}\\)"
|
105
|
+
|
106
|
+
def spacify_re(s)
|
107
|
+
s.gsub(' ', '[\u00A0\s]+')
|
108
|
+
end
|
109
|
+
|
92
110
|
def xml_from_sections(input)
|
93
111
|
|
94
112
|
unless ENV["KRAMDOWN_NO_SOURCE"]
|
@@ -158,11 +176,20 @@ def xml_from_sections(input)
|
|
158
176
|
# collect normative/informative tagging {{!RFC2119}} {{?RFC4711}}
|
159
177
|
sechash.each do |k, v|
|
160
178
|
next if k == "fluff"
|
161
|
-
v.gsub!(/{{(
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
179
|
+
v.gsub!(/{{(#{
|
180
|
+
spacify_re(XSR_PREFIX)
|
181
|
+
})?(?:([?!])(-)?|(-))([\w._\-]+)(?:=([\w.\/_\-]+))?(#{
|
182
|
+
XREF_TXT_SUFFIX
|
183
|
+
})?(#{
|
184
|
+
spacify_re(XSR_SUFFIX)
|
185
|
+
})?}}/) do |match|
|
186
|
+
xsr_prefix = $1
|
187
|
+
norminform = $2
|
188
|
+
replacing = $3 || $4
|
189
|
+
word = $5
|
190
|
+
bibref = $6
|
191
|
+
xrt_suffix = $7
|
192
|
+
xsr_suffix = $8
|
166
193
|
if replacing
|
167
194
|
if new = ref_replacements[word]
|
168
195
|
word = new
|
@@ -186,7 +213,7 @@ def xml_from_sections(input)
|
|
186
213
|
if norminform
|
187
214
|
norm_ref[word] ||= norminform == '!' # one normative ref is enough
|
188
215
|
end
|
189
|
-
"{{#{word}}}"
|
216
|
+
"{{#{xsr_prefix}#{word}#{xrt_suffix}#{xsr_suffix}}}"
|
190
217
|
end
|
191
218
|
end
|
192
219
|
|
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.4.
|
3
|
+
s.version = '1.4.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.}
|
@@ -34,13 +34,12 @@ module KramdownRFC
|
|
34
34
|
val ||= defcontent
|
35
35
|
Array(val).map do |val1|
|
36
36
|
v = val1.to_s.strip
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
37
|
+
contents =
|
38
|
+
if markdown
|
39
|
+
::Kramdown::Converter::Rfc2629::process_markdown(v)
|
40
|
+
else
|
41
|
+
escape_html(v)
|
42
|
+
end
|
44
43
|
%{<#{[an, *Array(attr).map(&:to_s)].join(" ").strip}>#{contents}</#{an}>}
|
45
44
|
end.join(" ")
|
46
45
|
end
|
data/lib/kramdown-rfc2629.rb
CHANGED
@@ -42,32 +42,50 @@ module Kramdown
|
|
42
42
|
@block_parsers.unshift(:block_pi)
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
45
|
+
XREF_BASE = /[\w.-]+/ # a token for a reference
|
46
|
+
XREF_TXT = /(?:[^\(]|\([^\)]*\))+/ # parenthesized text
|
47
|
+
XREF_RE = /#{XREF_BASE}(?: \(#{XREF_TXT}\))?/
|
48
|
+
XREF_RE_M = /\A(#{XREF_BASE})(?: \((#{XREF_TXT})\))?/ # matching version of XREF_RE
|
49
|
+
XREF_SINGLE = /(?:Section|Appendix) #{XREF_RE}/
|
50
|
+
XREF_MULTI = /(?:Sections|Appendices) (?:#{XREF_RE}, )*#{XREF_RE},? and #{XREF_RE}/
|
51
|
+
XREF_ANY = /(?:#{XREF_SINGLE}|#{XREF_MULTI})/
|
52
|
+
SECTIONS_RE = /(?:#{XREF_ANY} and )?#{XREF_ANY}/
|
53
|
+
|
54
|
+
def handle_bares(s, attr, format, href, last_join = nil)
|
55
|
+
if s.match(/\A(#{XREF_ANY}) and (#{XREF_ANY})\z/)
|
56
|
+
handle_bares($1, {}, nil, href, " and ")
|
57
|
+
handle_bares($2, {}, nil, href, " of ")
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
href = href.split(' ')[0] # Remove any trailing (...)
|
62
|
+
multi = last_join != nil
|
63
|
+
(sn, s) = s.split(' ', 2)
|
64
|
+
loop do
|
65
|
+
m = s.match(/\A#{XREF_RE_M}(, (?:and )?| and )?/)
|
66
|
+
break if not m
|
67
|
+
|
68
|
+
if not multi and not m[2] and not m[3]
|
69
|
+
# Modify |attr| if there is a single reference. This can only be
|
70
|
+
# used if there is only one section reference and the section part
|
71
|
+
# has no title.
|
72
|
+
attr['section'] = m[1]
|
73
|
+
attr['sectionFormat'] = format
|
74
|
+
attr['text'] = m[2]
|
75
|
+
return
|
66
76
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
77
|
+
|
78
|
+
if sn
|
79
|
+
@tree.children << Element.new(:text, "#{sn} ", {})
|
80
|
+
sn = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
multi = true
|
84
|
+
s[m[0]] = ''
|
85
|
+
|
86
|
+
attr1 = { 'target' => href, 'section' => m[1], 'sectionFormat' => 'bare', 'text' => m[2] }
|
87
|
+
@tree.children << Element.new(:xref, nil, attr1)
|
88
|
+
@tree.children << Element.new(:text, m[3] || last_join || " of ", {})
|
71
89
|
end
|
72
90
|
end
|
73
91
|
|
@@ -114,6 +132,10 @@ module Kramdown
|
|
114
132
|
attr['format'] = 'counter'
|
115
133
|
end
|
116
134
|
end
|
135
|
+
if href.match(XREF_RE_M)
|
136
|
+
href = $1
|
137
|
+
attr['text'] = $2
|
138
|
+
end
|
117
139
|
href = href.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an IDREF with a number
|
118
140
|
attr['target'] = href
|
119
141
|
el = Element.new(:xref, nil, attr)
|
@@ -288,6 +310,12 @@ module Kramdown
|
|
288
310
|
generate_id(value).gsub(/-+/, '-')
|
289
311
|
end
|
290
312
|
|
313
|
+
def self.process_markdown(v) # Uuh. Heavy coupling.
|
314
|
+
doc = ::Kramdown::Document.new(v, $global_markdown_options)
|
315
|
+
$stderr.puts doc.warnings.to_yaml unless doc.warnings.empty?
|
316
|
+
doc.to_rfc2629[3..-6] # skip <t>...</t>\n
|
317
|
+
end
|
318
|
+
|
291
319
|
SVG_COLORS = Hash.new {|h, k| k}
|
292
320
|
<<COLORS.each_line {|l| k, v = l.chomp.split; SVG_COLORS[k] = v}
|
293
321
|
black #000000
|
@@ -335,6 +363,19 @@ COLORS
|
|
335
363
|
end
|
336
364
|
end
|
337
365
|
|
366
|
+
def svg_clean_kgt(s)
|
367
|
+
d = REXML::Document.new(s)
|
368
|
+
REXML::XPath.each(d.root, "//rect|//line|//path") do |x|
|
369
|
+
x.attributes["fill"] = "none"
|
370
|
+
x.attributes["stroke"] = "black"
|
371
|
+
x.attributes["stroke-width"] = "1.5"
|
372
|
+
end
|
373
|
+
d.to_s
|
374
|
+
rescue => detail
|
375
|
+
warn "*** Can't clean SVG: #{detail}"
|
376
|
+
d
|
377
|
+
end
|
378
|
+
|
338
379
|
def svg_clean(s) # expensive, risky
|
339
380
|
d = REXML::Document.new(s)
|
340
381
|
REXML::XPath.each(d.root, "//*[@shape-rendering]") { |x| x.attributes["shape-rendering"] = nil } #; warn x.inspect }
|
@@ -379,9 +420,12 @@ COLORS
|
|
379
420
|
file = Tempfile.new("kramdown-rfc")
|
380
421
|
file.write(result)
|
381
422
|
file.close
|
423
|
+
dont_clean = false
|
424
|
+
dont_check = false
|
382
425
|
case t
|
383
426
|
when "goat"
|
384
427
|
result1, err, _s = Open3.capture3("goat #{file.path}", stdin_data: result);
|
428
|
+
dont_clean = true
|
385
429
|
when "ditaa" # XXX: This needs some form of option-setting
|
386
430
|
result1, err, _s = Open3.capture3("ditaa #{file.path} --svg -o -", stdin_data: result);
|
387
431
|
when "mscgen"
|
@@ -396,18 +440,27 @@ COLORS
|
|
396
440
|
result1, err, _s = Open3.capture3("plantuml -pipe -tsvg", stdin_data: plantuml);
|
397
441
|
result, err1, _s = Open3.capture3("plantuml -pipe -tutxt", stdin_data: plantuml) if t == "plantuml-utxt"
|
398
442
|
err << err1.to_s
|
443
|
+
when "railroad", "railroad-utf8"
|
444
|
+
result1, err1, _s = Open3.capture3("kgt -l abnf -e svg", stdin_data: result);
|
445
|
+
result1 = svg_clean_kgt(result1); dont_clean = true
|
446
|
+
result, err, _s = Open3.capture3("kgt -l abnf -e rr#{t == "railroad" ? "text" : "utf8"}",
|
447
|
+
stdin_data: result);
|
448
|
+
err << err1.to_s
|
399
449
|
when "math"
|
400
450
|
result1, err, _s = Open3.capture3("tex2svg --font STIX --speech=false #{Shellwords.escape(' ' << result)}");
|
401
451
|
result, err1, _s = Open3.capture3("asciitex -f #{file.path}")
|
402
452
|
err << err1
|
403
453
|
end
|
404
454
|
capture_croak(t, err)
|
405
|
-
# warn ["
|
455
|
+
# warn ["text:", result.inspect]
|
456
|
+
# warn ["svg:", result1.inspect]
|
406
457
|
file.unlink
|
407
|
-
result1 = svg_clean(result1) unless
|
408
|
-
|
409
|
-
|
410
|
-
|
458
|
+
result1 = svg_clean(result1) unless dont_clean
|
459
|
+
unless dont_check
|
460
|
+
result1, err, _s = Open3.capture3("svgcheck -Xqa", stdin_data: result1);
|
461
|
+
# warn ["svgcheck:", result1.inspect]
|
462
|
+
capture_croak("svgcheck", err)
|
463
|
+
end
|
411
464
|
if result1 == ''
|
412
465
|
warn "*** could not create svg for #{result.inspect[0...20]}..."
|
413
466
|
exit 65 # EX_DATAERR
|
@@ -462,7 +515,8 @@ COLORS
|
|
462
515
|
end
|
463
516
|
end
|
464
517
|
case t
|
465
|
-
when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt",
|
518
|
+
when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt",
|
519
|
+
"railroad", "railroad-utf8", "mermaid", "math"
|
466
520
|
if gi
|
467
521
|
warn "*** Can't set GI #{gi} for composite SVG artset"
|
468
522
|
end
|
@@ -729,6 +783,7 @@ COLORS
|
|
729
783
|
|
730
784
|
def convert_xref(el, indent, opts)
|
731
785
|
gi = el.attr.delete('gi')
|
786
|
+
text = el.attr.delete('text')
|
732
787
|
target = el.attr['target']
|
733
788
|
if target[0] == "&"
|
734
789
|
"#{target};"
|
@@ -738,7 +793,12 @@ COLORS
|
|
738
793
|
else
|
739
794
|
gi ||= "xref"
|
740
795
|
end
|
741
|
-
|
796
|
+
if text
|
797
|
+
tail = ">#{Rfc2629::process_markdown(text)}</#{gi}>"
|
798
|
+
else
|
799
|
+
tail = "/>"
|
800
|
+
end
|
801
|
+
"<#{gi}#{el_html_attributes(el)}#{tail}"
|
742
802
|
end
|
743
803
|
end
|
744
804
|
|
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.
|
4
|
+
version: 1.4.12
|
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-05-
|
11
|
+
date: 2021-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|