kramdown-rfc2629 1.4.13 → 1.4.18

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: 509111a53b346a7af409423bc1aea0e64c3fbded3e42868a875de6b867392429
4
- data.tar.gz: 3c882b8d76cbbfcc9e070157c453a25105fe23de1d061a2c0bc56591857e7f08
3
+ metadata.gz: f351fb251c634da227a9ce9202094ee20ac11689be7b2144f118ba07aa2b31fb
4
+ data.tar.gz: 45d0559f1f6c6ff2c4ba18bab26a4e88bec8faad622cf0b9183c144eb419441f
5
5
  SHA512:
6
- metadata.gz: a42a8122990612bb885799121492673d37f47285d1481a0b2db4e0a2e12b2ebee9b630131596f228a99daed62190fcf411317b37434dc46cf84e429ede139bdb
7
- data.tar.gz: e5197f5394cfa12dd11042bb5c90d73dd02e6582f05175e7b2516c1d731fbd13d7699106666f43b1bd1ec1c98473229ba618f3cfde48a40759ec137d1e10087f
6
+ metadata.gz: 2d3acf198070f8d7b69995f9f581302a6d20bbb24241350a169ef8cc5ccfeb49d191adfaaa11442df5859534812761d91c7f7c5a8b22b5a2aec19c8d2a02e48b
7
+ data.tar.gz: b1c5d6d9c968d82a453bcdfcc234e1dc4f3844ba9084942f73fd5212258d0d1e361f55fc1cb36910b58a4c2e68286cfe20695cf8d6d1c9e538a9907164d89d71
data/README.md CHANGED
@@ -317,6 +317,10 @@ Note that this feature does not play well with the CI (continuous
317
317
  integration) support in Martin Thomson's [I-D Template][], as that may
318
318
  not have the tools installed in its docker instance.
319
319
 
320
+ More details have been collected on the [wiki][svg].
321
+
322
+ [svg]: https://github.com/cabo/kramdown-rfc2629/wiki/SVG
323
+
320
324
  (1.2.9:)
321
325
  The YAML header now allows specifying [kramdown_options][].
322
326
 
data/bin/kdrfc CHANGED
@@ -127,7 +127,7 @@ BANNER
127
127
  opts.on("-p", "--[no-]prep", "Convert xml to prepped xml") do |v|
128
128
  $options.prep = v
129
129
  end
130
- opts.on("-P", "--[no-]pdf", "Convert xml to PDF") do |v|
130
+ opts.on("-P", "-f", "--[no-]pdf", "Convert xml to PDF") do |v|
131
131
  $options.pdf = v
132
132
  end
133
133
  opts.on("-c", "--[no-]convert", "Convert xml to v3 xml") do |v|
@@ -15,7 +15,7 @@ require 'fileutils'
15
15
 
16
16
  begin
17
17
  require 'net/http/persistent'
18
- rescue
18
+ rescue LoadError
19
19
  warn "*** please install net-http-persistent:"
20
20
  warn " gem install net-http-persistent"
21
21
  warn "(prefix by sudo only if required)."
data/bin/kramdown-rfc2629 CHANGED
@@ -83,7 +83,7 @@ def do_the_tls_dance
83
83
  end
84
84
 
85
85
  RE_NL = /(?:\n|\r|\r\n)/
86
- RE_SECTION = /---(?:\s+(\w+)(-?))?\s*#{RE_NL}(.*?#{RE_NL})(?=---(?:\s+\w+-?)?\s*#{RE_NL}|\Z)/m
86
+ RE_SECTION = /---(?: +(\w+)(-?))?\s*#{RE_NL}(.*?#{RE_NL})(?=---(?:\s+\w+-?)?\s*#{RE_NL}|\Z)/m
87
87
 
88
88
  NMDTAGS = ["{:/nomarkdown}\n\n", "\n\n{::nomarkdown}\n"]
89
89
 
@@ -98,7 +98,61 @@ def yaml_load(input, *args)
98
98
  end
99
99
  else
100
100
  YAML.load(input)
101
- 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
102
156
  end
103
157
 
104
158
  XREF_SECTIONS_RE = ::Kramdown::Parser::RFC2629Kramdown::SECTIONS_RE
@@ -127,15 +181,21 @@ def xml_from_sections(input)
127
181
  # We put back the "---" plus gratuitous blank lines to hack the line number in errors
128
182
  yaml_in = input[/---\s*/] << sections.shift[2]
129
183
  ps = KramdownRFC::ParameterSet.new(yaml_load(yaml_in, [Date], [], true))
184
+
130
185
  coding_override = ps.has(:coding)
131
186
  smart_quotes = ps[:smart_quotes]
132
187
  typographic_symbols = ps[:typographic_symbols]
133
- 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)
134
193
 
135
194
  # all the other sections are put in a Hash, possibly concatenated from parts there
136
195
  sechash = Hash.new{ |h,k| h[k] = ""}
137
196
  snames = [] # a stack of section names
138
197
  sections.each do |sname, nmdflag, text|
198
+ # warn [:SNAME, sname, nmdflag, text[0..10]].inspect
139
199
  nmdin, nmdout = {
140
200
  "-" => ["", ""], # stay in nomarkdown
141
201
  "" => NMDTAGS, # pop out temporarily
@@ -243,13 +303,12 @@ def xml_from_sections(input)
243
303
  end
244
304
 
245
305
  stand_alone = ps[:stand_alone]
246
- link_defs = {}
247
306
 
248
307
  [:normative, :informative].each do |sn|
249
308
  if refs = ps[sn]
250
309
  refs.each do |k, v|
251
- href = k.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an IDREF with a number
252
- link_defs[k] = ["##{href}", nil] # allow [RFC2119] in addition to {{RFC2119}}
310
+ href = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(k)
311
+ kramdown_options[:link_defs][k] = ["##{href}", nil] # allow [RFC2119] in addition to {{RFC2119}}
253
312
 
254
313
  bibref = anchor_to_bibref[k] || k
255
314
  bts, url = bibtagsys(bibref, k, stand_alone)
@@ -270,9 +329,7 @@ def xml_from_sections(input)
270
329
  if bts && !v.delete("override")
271
330
  warn "*** warning: explicit settings completely override canned bibxml in reference #{k}"
272
331
  end
273
- options = {input: 'RFC2629Kramdown', entity_output: coding_override, link_defs: link_defs}
274
- $global_markdown_options = options # For recursive calls in bibref annotation processing.
275
- sechash[sn.to_s] << KramdownRFC::ref_to_xml(k, v)
332
+ sechash[sn.to_s] << KramdownRFC::ref_to_xml(href, v)
276
333
  end
277
334
  end
278
335
  end
@@ -289,7 +346,7 @@ def xml_from_sections(input)
289
346
  warn "*** sections left #{sechash.keys.inspect}!"
290
347
  end
291
348
 
292
- [input, coding_override, link_defs, smart_quotes, typographic_symbols, kramdown_options]
349
+ [input, kramdown_options, coding_override]
293
350
  end
294
351
 
295
352
  XML_RESOURCE_ORG_PREFIX = Kramdown::Converter::Rfc2629::XML_RESOURCE_ORG_PREFIX
@@ -307,7 +364,7 @@ def bibtagsys(bib, anchor=nil, stand_alone=true)
307
364
  elsif bib =~ /\A([-A-Z0-9]+)\./ &&
308
365
  (xro = Kramdown::Converter::Rfc2629::XML_RESOURCE_ORG_MAP[$1])
309
366
  dir, _ttl, rewrite_anchor = xro
310
- bib1 = bib.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an ID with a number
367
+ bib1 = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(bib)
311
368
  if anchor && bib1 != anchor
312
369
  if rewrite_anchor
313
370
  a = %{?anchor=#{anchor}}
@@ -371,7 +428,6 @@ if $options.verbose && $options.v3
371
428
  warn "*** not much RFCXMLv3 stuff implemented yet"
372
429
  end
373
430
 
374
- coding_override = :as_char
375
431
  input = ARGF.read
376
432
  if input[0] == "\uFEFF"
377
433
  warn "*** There is a leading byte order mark. Ignored."
@@ -392,62 +448,32 @@ if input =~ /[\t]/
392
448
  input = expand_tabs(input)
393
449
  end
394
450
 
395
- link_defs = {}
396
451
  if input =~ /\A---/ # this is a sectionized file
397
452
  do_the_tls_dance unless ENV["KRAMDOWN_DONT_VERIFY_HTTPS"]
398
- input, target_coding, link_defs, smart_quotes, typographic_symbols, kramdown_options = xml_from_sections(input)
453
+ input, options, coding_override = xml_from_sections(input)
454
+ else
455
+ options = process_kramdown_options # all default
399
456
  end
400
457
  if input =~ /\A<\?xml/ # if this is a whole XML file, protect it
401
458
  input = "{::nomarkdown}\n#{input}\n{:/nomarkdown}\n"
402
459
  end
403
- options = {input: 'RFC2629Kramdown', entity_output: coding_override, link_defs: link_defs}
404
- if smart_quotes.nil?
405
- if (target_coding && target_coding =~ /ascii/) || $options.v3
406
- smart_quotes = false
407
- end
408
- end
409
- if smart_quotes == false
410
- smart_quotes = ["'".ord, "'".ord, '"'.ord, '"'.ord]
411
- end
412
- case smart_quotes
413
- when Array
414
- options[:smart_quotes] = smart_quotes
415
- when nil, true
416
- # nothin
417
- else
418
- warn "*** Can't deal with smart_quotes value #{smart_quotes.inspect}"
419
- end
420
- if typographic_symbols.nil?
421
- if (target_coding && target_coding =~ /ascii/) || $options.v3
422
- typographic_symbols = false
423
- end
424
- end
425
- if typographic_symbols == false
426
- typographic_symbols = Hash[::Kramdown::Parser::Kramdown::TYPOGRAPHIC_SYMS.map { |k, v|
427
- if Symbol === v
428
- [v.intern, k]
429
- end
430
- }.compact]
431
- end
432
- # warn [:TYPOGRAPHIC_SYMBOLS, typographic_symbols].to_yaml
433
- case typographic_symbols
434
- when Hash
435
- options[:typographic_symbols] = typographic_symbols
436
- when nil, true
437
- # nothin
438
- else
439
- warn "*** Can't deal with typographic_symbols value #{typographic_symbols.inspect}"
440
- end
441
460
 
442
- if kramdown_options
443
- options.merge! kramdown_options
461
+ if coding_override
462
+ input = input.encode(Encoding.find(coding_override), fallback: FALLBACK)
444
463
  end
445
464
 
446
- if target_coding
447
- input = input.encode(Encoding.find(target_coding), fallback: FALLBACK)
465
+ # 1.4.17: because of UTF-8 bibxml files, kramdown always needs to see UTF-8 (!)
466
+ if input.encoding != Encoding::UTF_8
467
+ input = input.encode(Encoding::UTF_8)
448
468
  end
449
469
 
450
470
  # warn "options: #{options.inspect}"
451
471
  doc = Kramdown::Document.new(input, options)
452
472
  $stderr.puts doc.warnings.to_yaml unless doc.warnings.empty?
453
- puts doc.to_rfc2629
473
+ output = doc.to_rfc2629
474
+
475
+ if coding_override
476
+ output = output.encode(Encoding.find(coding_override), fallback: FALLBACK)
477
+ end
478
+
479
+ puts output
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.4.13'
3
+ s.version = '1.4.18'
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.}
@@ -42,7 +42,7 @@ module Kramdown
42
42
  @block_parsers.unshift(:block_pi)
43
43
  end
44
44
 
45
- XREF_BASE = /[\w.-]+/ # a token for a reference
45
+ XREF_BASE = /#{REXML::XMLTokens::NAME_CHAR}+/ # a token for a reference
46
46
  XREF_TXT = /(?:[^\(]|\([^\)]*\))+/ # parenthesized text
47
47
  XREF_RE = /#{XREF_BASE}(?: \(#{XREF_TXT}\))?/
48
48
  XREF_RE_M = /\A(#{XREF_BASE})(?: \((#{XREF_TXT})\))?/ # matching version of XREF_RE
@@ -51,6 +51,11 @@ module Kramdown
51
51
  XREF_ANY = /(?:#{XREF_SINGLE}|#{XREF_MULTI})/
52
52
  SECTIONS_RE = /(?:#{XREF_ANY} and )?#{XREF_ANY}/
53
53
 
54
+ def self.idref_cleanup(href)
55
+ # can't start an IDREF with a number or reserved start
56
+ href.gsub(/\A(?:[0-9]|section-|u-|figure-|table-|iref-)/) { "_#{$&}" }
57
+ end
58
+
54
59
  def handle_bares(s, attr, format, href, last_join = nil)
55
60
  if s.match(/\A(#{XREF_ANY}) and (#{XREF_ANY})\z/)
56
61
  handle_bares($1, {}, nil, href, " and ")
@@ -132,11 +137,11 @@ module Kramdown
132
137
  attr['format'] = 'counter'
133
138
  end
134
139
  end
135
- if href.match(XREF_RE_M)
140
+ if href.match(/#{XREF_RE_M}\z/)
136
141
  href = $1
137
142
  attr['text'] = $2
138
143
  end
139
- href = href.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an IDREF with a number
144
+ href = self.class.idref_cleanup(href)
140
145
  attr['target'] = href
141
146
  el = Element.new(:xref, nil, attr)
142
147
  end
@@ -212,10 +217,10 @@ module Kramdown
212
217
  def rfc2629_fix
213
218
  if a = attr
214
219
  if anchor = a.delete('id')
215
- a['anchor'] = anchor
220
+ a['anchor'] = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
216
221
  end
217
222
  if anchor = a.delete('href')
218
- a['target'] = anchor
223
+ a['target'] = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
219
224
  end
220
225
  attr.keys.each do |k|
221
226
  if (d = k.gsub(/_(.|$)/) { $1.upcase }) != k or d = STUDLY_ATTR_MAP[k]
@@ -251,7 +256,10 @@ module Kramdown
251
256
  require 'net/http/persistent'
252
257
  $http = Net::HTTP::Persistent.new name: 'kramdown-rfc'
253
258
  rescue Exception => e
254
- warn "** Can't set up persistent HTTP -- #{e}"
259
+ warn "** Not using persistent HTTP -- #{e}"
260
+ warn "** To silence this message and get full speed, try:"
261
+ warn "** gem install net-http-persistent"
262
+ warn "** If this doesn't work, you can ignore this warning."
255
263
  end
256
264
  end
257
265
 
@@ -917,6 +925,7 @@ COLORS
917
925
  ],
918
926
  "W3C" => "bibxml4",
919
927
  "3GPP" => "bibxml5",
928
+ "SDO-3GPP" => "bibxml5",
920
929
  "ANSI" => "bibxml2",
921
930
  "CCITT" => "bibxml2",
922
931
  "FIPS" => "bibxml2",
@@ -955,7 +964,7 @@ COLORS
955
964
  warn "*** missing anchor for '#{src}'"
956
965
  src
957
966
  )
958
- anchor.sub!(/\A[0-9]/) { "_#{$&}" } # can't start an ID with a number
967
+ anchor = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
959
968
  anchor.gsub!('/', '_') # should take out all illegals
960
969
  to_insert = ""
961
970
  src.scan(/(W3C|3GPP|[A-Z-]+)[.]?([A-Za-z_0-9.\/\+-]+)/) do |t, n|
@@ -1024,7 +1033,7 @@ COLORS
1024
1033
  # "\n#{' '*indent}<cref>\n#{inner(el.value, indent, opts).rstrip}\n#{' '*indent}</cref>"
1025
1034
  content = inner(el.value, indent, opts).strip
1026
1035
  content = escape_html(content.sub(/\A<t>(.*)<\/t>\z/m) {$1}, :text) # text only...
1027
- name = el.options[:name].sub(/\A[0-9]/) {"_" << $&}
1036
+ name = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(el.options[:name])
1028
1037
  while @footnote_names_in_use[name] do
1029
1038
  if name =~ /:\d+\z/
1030
1039
  name.succ!
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.13
4
+ version: 1.4.18
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-21 00:00:00.000000000 Z
11
+ date: 2021-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown