kramdown-rfc2629 1.4.9 → 1.4.14.pre

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: 4be8093af3b860dba2fe1389dd720da6f34206ff112e84dcca98dd35ad200a07
4
- data.tar.gz: 2772970e704ad1bcea1930602e3b7f2e21cfe34a5bcdde3e1fdd0e2a71722bcf
3
+ metadata.gz: eae0eb8f4dd2fc504dae8740508bde5266b9e914780999977d1633d16537a1aa
4
+ data.tar.gz: f373cfb67d09360f2d79480acca773d3f8af0454e643600406e845a4ffb8072f
5
5
  SHA512:
6
- metadata.gz: 8feb2ef692ca46abe03f14dbfd34cce993856e03cb3eb2fa105db0c16766c931992facdcf6affbc0a164c6b48e3abe5110f2f76118c394c652d4c2bdff530769
7
- data.tar.gz: 5fab2d82e41c88603abbe33224a763534d0920da3751529b01110b885dec060564a4431bd4617360427cc1ef6aaac4b5375888ec2387983b62daabad1fb6822e
6
+ metadata.gz: 88e3ed1e8713e1cf2ba6ceb4dd3aff3b83ab3397339edc83a9230fab5a2ac716a133be9acfd22a0a9bde793e8fecb709976f04285bfd0ebb09dec3c005fd3a1a
7
+ data.tar.gz: 8fe774e5ee8ab20885472f2a30fe5c65aab4ea56d80f7e4e334af25a4997a927fca85afd289b78d9088273822385b5ab96f15b0536657b4775516acb62fb049e
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 = <<RFC8174
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 $1
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 $2
39
+ if $3
32
40
  if $options.v3
33
41
  ret << <<TAGGED
34
42
 
@@ -83,15 +91,75 @@ NORMINFORM = { "!" => :normative, "?" => :informative }
83
91
 
84
92
  def yaml_load(input, *args)
85
93
  if YAML.respond_to?(:safe_load)
86
- YAML.safe_load(input, *args)
94
+ begin
95
+ YAML.safe_load(input, *args)
96
+ rescue ArgumentError
97
+ YAML.safe_load(input, permitted_classes: args[0], permitted_symbols: args[1], aliases: args[2])
98
+ end
87
99
  else
88
100
  YAML.load(input)
89
- end
101
+ end
102
+ end
103
+
104
+ def process_kramdown_options(coding_override = nil,
105
+ smart_quotes = nil, typographic_symbols = nil,
106
+ header_kramdown_options = nil)
107
+
108
+ ascii_target = coding_override && coding_override =~ /ascii/
109
+ suppress_typography = ascii_target || $options.v3
110
+ entity_output = ascii_target ? :numeric : :as_char;
111
+
112
+ options = {input: 'RFC2629Kramdown', entity_output: entity_output, link_defs: {}}
113
+
114
+ if smart_quotes.nil? && suppress_typography
115
+ smart_quotes = false
116
+ end
117
+ if smart_quotes == false
118
+ smart_quotes = ["'".ord, "'".ord, '"'.ord, '"'.ord]
119
+ end
120
+ case smart_quotes
121
+ when Array
122
+ options[:smart_quotes] = smart_quotes
123
+ when nil, true
124
+ # nothin
125
+ else
126
+ warn "*** Can't deal with smart_quotes value #{smart_quotes.inspect}"
127
+ end
128
+
129
+ if typographic_symbols.nil? && suppress_typography
130
+ typographic_symbols = false
131
+ end
132
+ if typographic_symbols == false
133
+ typographic_symbols = Hash[::Kramdown::Parser::Kramdown::TYPOGRAPHIC_SYMS.map { |k, v|
134
+ if Symbol === v
135
+ [v.intern, k]
136
+ end
137
+ }.compact]
138
+ end
139
+ # warn [:TYPOGRAPHIC_SYMBOLS, typographic_symbols].to_yaml
140
+ case typographic_symbols
141
+ when Hash
142
+ options[:typographic_symbols] = typographic_symbols
143
+ when nil, true
144
+ # nothin
145
+ else
146
+ warn "*** Can't deal with typographic_symbols value #{typographic_symbols.inspect}"
147
+ end
148
+
149
+ if header_kramdown_options
150
+ options.merge! header_kramdown_options
151
+ end
152
+
153
+ $global_markdown_options = options # For nested calls in bibref annotation processing and xref text
154
+
155
+ options
90
156
  end
91
157
 
92
158
  XREF_SECTIONS_RE = ::Kramdown::Parser::RFC2629Kramdown::SECTIONS_RE
93
159
  XSR_PREFIX = "#{XREF_SECTIONS_RE} of "
94
- XSR_SUFFIX = ", (#{XREF_SECTIONS_RE})| \((#{XREF_SECTIONS_RE})\)"
160
+ XSR_SUFFIX = ", (#{XREF_SECTIONS_RE})| \\((#{XREF_SECTIONS_RE})\\)"
161
+ XREF_TXT = ::Kramdown::Parser::RFC2629Kramdown::XREF_TXT
162
+ XREF_TXT_SUFFIX = " \\(#{XREF_TXT}\\)"
95
163
 
96
164
  def spacify_re(s)
97
165
  s.gsub(' ', '[\u00A0\s]+')
@@ -113,10 +181,15 @@ def xml_from_sections(input)
113
181
  # We put back the "---" plus gratuitous blank lines to hack the line number in errors
114
182
  yaml_in = input[/---\s*/] << sections.shift[2]
115
183
  ps = KramdownRFC::ParameterSet.new(yaml_load(yaml_in, [Date], [], true))
184
+
116
185
  coding_override = ps.has(:coding)
117
186
  smart_quotes = ps[:smart_quotes]
118
187
  typographic_symbols = ps[:typographic_symbols]
119
- kramdown_options = ps[:kramdown_options]
188
+ header_kramdown_options = ps[:kramdown_options]
189
+
190
+ kramdown_options = process_kramdown_options(coding_override,
191
+ smart_quotes, typographic_symbols,
192
+ header_kramdown_options)
120
193
 
121
194
  # all the other sections are put in a Hash, possibly concatenated from parts there
122
195
  sechash = Hash.new{ |h,k| h[k] = ""}
@@ -169,6 +242,8 @@ def xml_from_sections(input)
169
242
  v.gsub!(/{{(#{
170
243
  spacify_re(XSR_PREFIX)
171
244
  })?(?:([?!])(-)?|(-))([\w._\-]+)(?:=([\w.\/_\-]+))?(#{
245
+ XREF_TXT_SUFFIX
246
+ })?(#{
172
247
  spacify_re(XSR_SUFFIX)
173
248
  })?}}/) do |match|
174
249
  xsr_prefix = $1
@@ -176,7 +251,8 @@ def xml_from_sections(input)
176
251
  replacing = $3 || $4
177
252
  word = $5
178
253
  bibref = $6
179
- xsr_suffix = $7
254
+ xrt_suffix = $7
255
+ xsr_suffix = $8
180
256
  if replacing
181
257
  if new = ref_replacements[word]
182
258
  word = new
@@ -200,7 +276,7 @@ def xml_from_sections(input)
200
276
  if norminform
201
277
  norm_ref[word] ||= norminform == '!' # one normative ref is enough
202
278
  end
203
- "{{#{xsr_prefix}#{word}#{xsr_suffix}}}"
279
+ "{{#{xsr_prefix}#{word}#{xrt_suffix}#{xsr_suffix}}}"
204
280
  end
205
281
  end
206
282
 
@@ -226,13 +302,12 @@ def xml_from_sections(input)
226
302
  end
227
303
 
228
304
  stand_alone = ps[:stand_alone]
229
- link_defs = {}
230
305
 
231
306
  [:normative, :informative].each do |sn|
232
307
  if refs = ps[sn]
233
308
  refs.each do |k, v|
234
309
  href = k.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an IDREF with a number
235
- link_defs[k] = ["##{href}", nil] # allow [RFC2119] in addition to {{RFC2119}}
310
+ kramdown_options[:link_defs][k] = ["##{href}", nil] # allow [RFC2119] in addition to {{RFC2119}}
236
311
 
237
312
  bibref = anchor_to_bibref[k] || k
238
313
  bts, url = bibtagsys(bibref, k, stand_alone)
@@ -253,8 +328,6 @@ def xml_from_sections(input)
253
328
  if bts && !v.delete("override")
254
329
  warn "*** warning: explicit settings completely override canned bibxml in reference #{k}"
255
330
  end
256
- options = {input: 'RFC2629Kramdown', entity_output: coding_override, link_defs: link_defs}
257
- $global_markdown_options = options # For recursive calls in bibref annotation processing.
258
331
  sechash[sn.to_s] << KramdownRFC::ref_to_xml(k, v)
259
332
  end
260
333
  end
@@ -272,7 +345,7 @@ def xml_from_sections(input)
272
345
  warn "*** sections left #{sechash.keys.inspect}!"
273
346
  end
274
347
 
275
- [input, coding_override, link_defs, smart_quotes, typographic_symbols, kramdown_options]
348
+ [input, kramdown_options, coding_override]
276
349
  end
277
350
 
278
351
  XML_RESOURCE_ORG_PREFIX = Kramdown::Converter::Rfc2629::XML_RESOURCE_ORG_PREFIX
@@ -354,7 +427,6 @@ if $options.verbose && $options.v3
354
427
  warn "*** not much RFCXMLv3 stuff implemented yet"
355
428
  end
356
429
 
357
- coding_override = :as_char
358
430
  input = ARGF.read
359
431
  if input[0] == "\uFEFF"
360
432
  warn "*** There is a leading byte order mark. Ignored."
@@ -375,59 +447,18 @@ if input =~ /[\t]/
375
447
  input = expand_tabs(input)
376
448
  end
377
449
 
378
- link_defs = {}
379
450
  if input =~ /\A---/ # this is a sectionized file
380
451
  do_the_tls_dance unless ENV["KRAMDOWN_DONT_VERIFY_HTTPS"]
381
- input, target_coding, link_defs, smart_quotes, typographic_symbols, kramdown_options = xml_from_sections(input)
452
+ input, options, coding_override = xml_from_sections(input)
453
+ else
454
+ options = process_kramdown_options # all default
382
455
  end
383
456
  if input =~ /\A<\?xml/ # if this is a whole XML file, protect it
384
457
  input = "{::nomarkdown}\n#{input}\n{:/nomarkdown}\n"
385
458
  end
386
- options = {input: 'RFC2629Kramdown', entity_output: coding_override, link_defs: link_defs}
387
- if smart_quotes.nil?
388
- if (target_coding && target_coding =~ /ascii/) || $options.v3
389
- smart_quotes = false
390
- end
391
- end
392
- if smart_quotes == false
393
- smart_quotes = ["'".ord, "'".ord, '"'.ord, '"'.ord]
394
- end
395
- case smart_quotes
396
- when Array
397
- options[:smart_quotes] = smart_quotes
398
- when nil, true
399
- # nothin
400
- else
401
- warn "*** Can't deal with smart_quotes value #{smart_quotes.inspect}"
402
- end
403
- if typographic_symbols.nil?
404
- if (target_coding && target_coding =~ /ascii/) || $options.v3
405
- typographic_symbols = false
406
- end
407
- end
408
- if typographic_symbols == false
409
- typographic_symbols = Hash[::Kramdown::Parser::Kramdown::TYPOGRAPHIC_SYMS.map { |k, v|
410
- if Symbol === v
411
- [v.intern, k]
412
- end
413
- }.compact]
414
- end
415
- # warn [:TYPOGRAPHIC_SYMBOLS, typographic_symbols].to_yaml
416
- case typographic_symbols
417
- when Hash
418
- options[:typographic_symbols] = typographic_symbols
419
- when nil, true
420
- # nothin
421
- else
422
- warn "*** Can't deal with typographic_symbols value #{typographic_symbols.inspect}"
423
- end
424
-
425
- if kramdown_options
426
- options.merge! kramdown_options
427
- end
428
459
 
429
- if target_coding
430
- input = input.encode(Encoding.find(target_coding), fallback: FALLBACK)
460
+ if coding_override
461
+ input = input.encode(Encoding.find(coding_override), fallback: FALLBACK)
431
462
  end
432
463
 
433
464
  # warn "options: #{options.inspect}"
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.4.9'
3
+ s.version = '1.4.14.pre'
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.}
@@ -363,6 +363,19 @@ COLORS
363
363
  end
364
364
  end
365
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
+
366
379
  def svg_clean(s) # expensive, risky
367
380
  d = REXML::Document.new(s)
368
381
  REXML::XPath.each(d.root, "//*[@shape-rendering]") { |x| x.attributes["shape-rendering"] = nil } #; warn x.inspect }
@@ -407,9 +420,12 @@ COLORS
407
420
  file = Tempfile.new("kramdown-rfc")
408
421
  file.write(result)
409
422
  file.close
423
+ dont_clean = false
424
+ dont_check = false
410
425
  case t
411
426
  when "goat"
412
427
  result1, err, _s = Open3.capture3("goat #{file.path}", stdin_data: result);
428
+ dont_clean = true
413
429
  when "ditaa" # XXX: This needs some form of option-setting
414
430
  result1, err, _s = Open3.capture3("ditaa #{file.path} --svg -o -", stdin_data: result);
415
431
  when "mscgen"
@@ -424,18 +440,27 @@ COLORS
424
440
  result1, err, _s = Open3.capture3("plantuml -pipe -tsvg", stdin_data: plantuml);
425
441
  result, err1, _s = Open3.capture3("plantuml -pipe -tutxt", stdin_data: plantuml) if t == "plantuml-utxt"
426
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
427
449
  when "math"
428
450
  result1, err, _s = Open3.capture3("tex2svg --font STIX --speech=false #{Shellwords.escape(' ' << result)}");
429
451
  result, err1, _s = Open3.capture3("asciitex -f #{file.path}")
430
452
  err << err1
431
453
  end
432
454
  capture_croak(t, err)
433
- # warn ["goat:", result1.inspect]
455
+ # warn ["text:", result.inspect]
456
+ # warn ["svg:", result1.inspect]
434
457
  file.unlink
435
- result1 = svg_clean(result1) unless t == "goat"
436
- result1, err, _s = Open3.capture3("svgcheck -Xqa", stdin_data: result1);
437
- capture_croak("svgcheck", err)
438
- # warn ["svgcheck:", result1.inspect]
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
439
464
  if result1 == ''
440
465
  warn "*** could not create svg for #{result.inspect[0...20]}..."
441
466
  exit 65 # EX_DATAERR
@@ -490,7 +515,8 @@ COLORS
490
515
  end
491
516
  end
492
517
  case t
493
- when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt", "mermaid", "math"
518
+ when "goat", "ditaa", "mscgen", "plantuml", "plantuml-utxt",
519
+ "railroad", "railroad-utf8", "mermaid", "math"
494
520
  if gi
495
521
  warn "*** Can't set GI #{gi} for composite SVG artset"
496
522
  end
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.9
4
+ version: 1.4.14.pre
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-04 00:00:00.000000000 Z
11
+ date: 2021-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -98,9 +98,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  version: 2.3.0
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - ">"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 1.3.1
104
104
  requirements: []
105
105
  rubygems_version: 3.2.15
106
106
  signing_key: