kramdown-rfc2629 1.5.12 → 1.5.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bb5b3f39e014d065b0dd2b72bd851804856c97610b1e24f863bd4c7c48a5c71
4
- data.tar.gz: '09f66a0f2557a18c023d0d991d009a5fe48568a7fd4c20a39540d111d4610c02'
3
+ metadata.gz: def25c3e3ddc2683800f2521956c7b7546da22ff963d08ea373bdb3626f5be6f
4
+ data.tar.gz: 453b9c763e43fa1930fe6f9239efb4951d73e479c4a82df1578443c872cec588
5
5
  SHA512:
6
- metadata.gz: 8a18e3db3281a30d45d60cf2f7e82f1addece4ff7867c70db1bfa104cbb015d416475659d677525ac50cc99ee83f46c874fddaba1bc04aa5109752bc7de56a6d
7
- data.tar.gz: f3f0e0da73244c8c78cdf1148b5036e412dbb95bd0e6d743b0d262bb5d52a2e595ef982433f527dd0ecabba2e75a544da0c17990943382fd67c21fda140adacc
6
+ metadata.gz: c7b09f669ef3c392e932264a1818db17679956178095a426d00ec0858c83dd5305752f2c9dfd042117f7f2786b085b750aa397f5afe0cf114a0811ca316fcbee
7
+ data.tar.gz: a14a50df013430d0e73b1d1e03a954cf6b54feef3cdaaca402546b93b086eb954bb22f85484fc5eda8da2859e6e0cd8dcc2a073d1509825e99dcb8c9754f03b3
@@ -42,6 +42,31 @@
42
42
 
43
43
  </abstract>
44
44
 
45
+ <% if $options.v3 -%>
46
+ <% venue = ps[:venue] -%>
47
+ <% if venue -%>
48
+ <% venue = KramdownRFC::ParameterSet.new(venue) -%>
49
+ <note title="Discussion Venues" removeInRFC="true">
50
+ <% if mail = venue[:mail] -%>
51
+ <% mail_local, mail_host = mail.split("@", 2) -%>
52
+ <% mail_subdomain, mail_domain = mail_host.split(".", 2) -%>
53
+ <% group = venue[:group] || mail_local # XXX -%>
54
+ <% arch = venue[:arch] || "https://mailarchive.ietf.org/arch/browse/#{mail_local}/" -%>
55
+ <% GROUPS = {"ietf" => "Working ", "irtf" => "Research "} -%>
56
+ <% type = venue[:type] || "#{GROUPS[mail_subdomain]}Group" -%>
57
+ <t>Discussion of this document takes place on the
58
+ <%=group%> <%=type%> mailing list (<%=mail%>),
59
+ which is archived at <eref target="<%=arch%>"/>.</t>
60
+ <% end -%>
61
+ <% if gh = venue[:github] -%>
62
+ <t>Source for this draft and an issue tracker can be found at
63
+ <eref target="https://github.com/<%=gh%>"/>.</t>
64
+ <% end -%>
65
+ </note>
66
+ <% venue.warn_if_leftovers -%>
67
+ <% end -%>
68
+ <% end -%>
69
+
45
70
  <% sechash.keys.each do |k| -%>
46
71
  <% if k =~ /\A(to_be_removed_)?note_(.*)/ -%>
47
72
 
@@ -78,6 +103,7 @@
78
103
  {:removeinrfc: removeinrfc="true"}
79
104
  {:notoc: toc="exclude"}
80
105
  {:compact: spacing="compact"}
106
+ {:noabbrev: noabbrev="true"}
81
107
  {::nomarkdown}
82
108
 
83
109
  <%= sechash.delete("middle") %>
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.5.12'
3
+ s.version = '1.5.16'
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,6 +34,18 @@ module Kramdown
34
34
 
35
35
  class RFC2629Kramdown < Kramdown
36
36
 
37
+ def replace_abbreviations(el, regexps = nil)
38
+ unless regexps # DUPLICATED AND MODIFIED CODE FROM UPSTREAM, CHECK ON UPSTREAM UPGRADE
39
+ sorted_abbrevs = @root.options[:abbrev_defs].keys.sort {|a, b| b.length <=> a.length }
40
+ regexps = [Regexp.union(*sorted_abbrevs.map {|k|
41
+ /#{Regexp.escape(k).gsub(/\\\s/, "[\\s\\p{Z}]+").force_encoding(Encoding::UTF_8)}/})]
42
+ # warn regexps.inspect
43
+ regexps << /(?=(?:\W|^)#{regexps.first}(?!\w))/ # regexp should only match on word boundaries
44
+ end
45
+ super(el, regexps)
46
+ end
47
+
48
+
37
49
  def initialize(*doc)
38
50
  super
39
51
  @span_parsers.unshift(:xref)
@@ -226,7 +238,11 @@ module Kramdown
226
238
  )
227
239
  STUDLY_ATTR_MAP = Hash[STUDLY_ATTR.map {|s| [s.downcase, s]}]
228
240
 
229
- def rfc2629_fix
241
+ TRUTHY = Hash.new {|h, k| k}
242
+ TRUTHY["false"] = false
243
+ TRUTHY["no"] = false
244
+
245
+ def rfc2629_fix(opts)
230
246
  if a = attr
231
247
  if anchor = a.delete('id')
232
248
  a['anchor'] = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
@@ -234,12 +250,16 @@ module Kramdown
234
250
  if anchor = a.delete('href')
235
251
  a['target'] = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
236
252
  end
253
+ if av = a.delete('noabbrev') # pseudo attribute -> opts
254
+ opts = opts.merge(noabbrev: TRUTHY[av]) # updated copy
255
+ end
237
256
  attr.keys.each do |k|
238
257
  if (d = k.gsub(/_(.|$)/) { $1.upcase }) != k or d = STUDLY_ATTR_MAP[k]
239
258
  a[d] = a.delete(k)
240
259
  end
241
260
  end
242
261
  end
262
+ opts
243
263
  end
244
264
  end
245
265
 
@@ -294,15 +314,15 @@ module Kramdown
294
314
  end
295
315
 
296
316
  def convert1(el, indent, opts = {})
297
- el.rfc2629_fix
298
- send("convert_#{el.type}", el, indent, opts)
317
+ nopts = el.rfc2629_fix(opts)
318
+ send("convert_#{el.type}", el, indent, nopts)
299
319
  end
300
320
 
301
321
  def inner_a(el, indent, opts)
302
322
  indent += INDENTATION
303
323
  el.children.map do |inner_el|
304
- inner_el.rfc2629_fix
305
- send("convert_#{inner_el.type}", inner_el, indent, opts)
324
+ nopts = inner_el.rfc2629_fix(opts)
325
+ send("convert_#{inner_el.type}", inner_el, indent, nopts)
306
326
  end
307
327
  end
308
328
 
@@ -447,59 +467,67 @@ COLORS
447
467
  end
448
468
  end
449
469
 
450
- def svg_tool_process(t, result)
470
+ def shell_prepare(opt)
471
+ " " << opt.shellsplit.shelljoin
472
+ end
473
+
474
+ DEFAULT_AASVG="aasvg --spaces=1"
475
+
476
+ def svg_tool_process(t, svg_opt, txt_opt, result)
451
477
  require 'tempfile'
452
478
  file = Tempfile.new("kramdown-rfc")
453
479
  file.write(result)
454
480
  file.close
455
481
  dont_clean = false
456
482
  dont_check = false
483
+ svg_opt = shell_prepare(svg_opt) if svg_opt
484
+ txt_opt = shell_prepare(txt_opt) if txt_opt
457
485
  case t
458
486
  when "protocol", "protocol-goat", "protocol-aasvg"
459
487
  cmdparm = result.lines.map(&:strip).select {|x| x != ''}.join(',')
460
- result, err, _s = Open3.capture3("protocol #{Shellwords.escape(cmdparm)}", stdin_data: '')
488
+ result, err, _s = Open3.capture3("protocol #{Shellwords.escape(cmdparm)}#{txt_opt}", stdin_data: '')
461
489
  if t == "protocol-goat"
462
490
  file.unlink
463
491
  file = Tempfile.new("kramdown-rfc")
464
492
  file.write(result)
465
493
  file.close
466
- result1, err, _s = Open3.capture3("goat #{file.path}", stdin_data: result);
494
+ result1, err, _s = Open3.capture3("goat#{svg_opt} #{file.path}", stdin_data: result);
467
495
  dont_clean = true
468
496
  elsif t == "protocol-aasvg"
469
- result1, err, _s = Open3.capture3("aasvg", stdin_data: result);
497
+ result1, err, _s = Open3.capture3("#{DEFAULT_AASVG}#{svg_opt}", stdin_data: result);
470
498
  dont_clean = true
471
499
  else
472
500
  result1 = nil
473
501
  end
474
502
  when "goat"
475
- result1, err, _s = Open3.capture3("goat #{file.path}", stdin_data: result);
503
+ result1, err, _s = Open3.capture3("goat#{svg_opt} #{file.path}", stdin_data: result);
476
504
  dont_clean = true
477
505
  when "aasvg"
478
- result1, err, _s = Open3.capture3("aasvg", stdin_data: result);
506
+ result1, err, _s = Open3.capture3("#{DEFAULT_AASVG}#{svg_opt}", stdin_data: result);
479
507
  dont_clean = true
480
508
  when "ditaa" # XXX: This needs some form of option-setting
481
- result1, err, _s = Open3.capture3("ditaa #{file.path} --svg -o -", stdin_data: result);
509
+ result1, err, _s = Open3.capture3("ditaa #{file.path} --svg -o -#{svg_opt}", stdin_data: result);
482
510
  when "mscgen"
483
- result1, err, _s = Open3.capture3("mscgen -T svg -i #{file.path} -o -", stdin_data: result);
511
+ result1, err, _s = Open3.capture3("mscgen -T svg -i #{file.path} -o -#{svg_opt}", stdin_data: result);
484
512
  when "mermaid"
485
- result1, err, _s = Open3.capture3("mmdc -i #{file.path}", stdin_data: result); # -b transparent
513
+ result1, err, _s = Open3.capture3("mmdc -i #{file.path}#{svg_opt}", stdin_data: result); # -b transparent
486
514
  outpath = file.path + ".svg"
487
515
  result1 = File.read(outpath) rescue '' # don't die before providing error message
488
516
  File.unlink(outpath) rescue nil # ditto
489
517
  when "plantuml", "plantuml-utxt"
490
518
  plantuml = "@startuml\n#{result}\n@enduml"
491
- result1, err, _s = Open3.capture3("plantuml -pipe -tsvg", stdin_data: plantuml);
492
- result, err1, _s = Open3.capture3("plantuml -pipe -tutxt", stdin_data: plantuml) if t == "plantuml-utxt"
519
+ result1, err, _s = Open3.capture3("plantuml -pipe -tsvg#{svg_opt}", stdin_data: plantuml);
520
+ result, err1, _s = Open3.capture3("plantuml -pipe -tutxt#{txt_opt}", stdin_data: plantuml) if t == "plantuml-utxt"
493
521
  err << err1.to_s
494
522
  when "railroad", "railroad-utf8"
495
- result1, err1, _s = Open3.capture3("kgt -l abnf -e svg", stdin_data: result);
523
+ result1, err1, _s = Open3.capture3("kgt -l abnf -e svg#{svg_opt}", stdin_data: result);
496
524
  result1 = svg_clean_kgt(result1); dont_clean = true
497
- result, err, _s = Open3.capture3("kgt -l abnf -e rr#{t == "railroad" ? "text" : "utf8"}",
525
+ result, err, _s = Open3.capture3("kgt -l abnf -e rr#{t == "railroad" ? "text" : "utf8"}#{txt_opt}",
498
526
  stdin_data: result);
499
527
  err << err1.to_s
500
528
  when "math"
501
- result1, err, _s = Open3.capture3("tex2svg --font STIX --speech=false #{Shellwords.escape(' ' << result)}");
502
- result, err1, _s = Open3.capture3("asciitex -f #{file.path}")
529
+ result1, err, _s = Open3.capture3("tex2svg --font STIX --speech=false#{svg_opt} #{Shellwords.escape(' ' << result)}");
530
+ result, err1, _s = Open3.capture3("asciitex -f #{file.path}#{txt_opt}")
503
531
  err << err1
504
532
  end
505
533
  capture_croak(t, err)
@@ -576,12 +604,18 @@ COLORS
576
604
  if gi
577
605
  warn "*** Can't set GI #{gi} for composite SVG artset"
578
606
  end
579
- result, result1 = memoize(:svg_tool_process, t, result)
580
- if result1 # refactor!
581
- "#{' '*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"
582
- else
583
- "#{' '*indent}<figure#{el_html_attributes(el)}><artwork #{html_attributes(artwork_attr.merge("type"=> "ascii-art"))}><![CDATA[#{result}#{result =~ /\n\Z/ ? '' : "\n"}]]></artwork></figure>\n"
607
+ result, result1 = memoize(:svg_tool_process, t,
608
+ artwork_attr.delete("svg-options"),
609
+ artwork_attr.delete("txt-options"),
610
+ result)
611
+ retart = mk_artwork(artwork_attr, "ascii-art",
612
+ "<![CDATA[#{result}#{result =~ /\n\Z/ ? '' : "\n"}]]>")
613
+ if result1 # nest TXT in artset with SVG
614
+ retsvg = mk_artwork(artwork_attr, "svg",
615
+ result1.sub(/.*?<svg/m, "<svg"))
616
+ retart = "<artset>#{retsvg}#{retart}</artset>"
584
617
  end
618
+ "#{' '*indent}<figure#{el_html_attributes(el)}>#{retart}</figure>\n"
585
619
  else
586
620
  gi ||= (
587
621
  if !$options.v3 || !t || ARTWORK_TYPES.include?(t) || artwork_attr["align"]
@@ -595,6 +629,10 @@ COLORS
595
629
  end
596
630
  end
597
631
 
632
+ def mk_artwork(artwork_attr, typ, content)
633
+ "<artwork #{html_attributes(artwork_attr.merge("type" => typ))}>#{content}</artwork>"
634
+ end
635
+
598
636
  def convert_blockquote(el, indent, opts)
599
637
  text = inner(el, indent, opts)
600
638
  if $options.v3
@@ -646,7 +684,8 @@ COLORS
646
684
  if sl = el.attr.delete('slugifiedName') # could do general name- play
647
685
  attrstring = html_attributes({'slugifiedName' => sl})
648
686
  end
649
- irefs = "<name#{attrstring}>#{inner(el, indent, opts)}</name>" #
687
+ # noabbrev: true -- Workaround for https://trac.ietf.org/trac/xml2rfc/ticket/683
688
+ irefs = "<name#{attrstring}>#{inner(el, indent, opts.merge(noabbrev: true))}</name>" #
650
689
  else
651
690
  clean, irefs = clean_pcdata(inner_a(el, indent, opts))
652
691
  el.attr['title'] = clean
@@ -1233,13 +1272,35 @@ COLORS
1233
1272
  end
1234
1273
 
1235
1274
  def convert_abbreviation(el, indent, opts) # XXX: This is wrong
1236
- title = @root.options[:abbrev_defs][el.value]
1237
- title = nil if title.empty?
1275
+ if opts[:noabbrev]
1276
+ return el.value
1277
+ end
1278
+
1238
1279
  value = el.value
1239
- if item = title
1240
- if item == "<bcp14>" && $options.v3
1241
- return "<bcp14>#{el.value}</bcp14>"
1280
+ ix = value.gsub(/[\s\p{Z}]+/, " ")
1281
+ title = @root.options[:abbrev_defs][ix]
1282
+ if title.nil?
1283
+ warn "*** abbrev mismatch: value = #{value.inspect} ix = #{ix.inspect}"
1284
+ else
1285
+ title = nil if title.empty?
1286
+ end
1287
+
1288
+ if title == "<bcp14>" && $options.v3
1289
+ return "<bcp14>#{value}</bcp14>"
1290
+ end
1291
+
1292
+ if title && title[0] == "#"
1293
+ target, title = title.split(' ', 2)
1294
+ if target == "#"
1295
+ target = value
1296
+ else
1297
+ target = target[1..]
1242
1298
  end
1299
+ else
1300
+ target = nil
1301
+ end
1302
+
1303
+ if item = title
1243
1304
  m = title.scan(Parser::RFC2629Kramdown::IREF_START)
1244
1305
  if m.empty?
1245
1306
  subitem = value
@@ -1250,7 +1311,11 @@ COLORS
1250
1311
  item = value
1251
1312
  end
1252
1313
  iref ||= "<iref#{html_attributes(item: item, subitem: subitem)}/>"
1253
- "#{el.value}#{iref}"
1314
+ if target
1315
+ "<xref#{html_attributes(target: target, format: "none")}>#{value}</xref>#{iref}"
1316
+ else
1317
+ "#{value}#{iref}"
1318
+ end
1254
1319
  end
1255
1320
 
1256
1321
  def convert_root(el, indent, opts)
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.5.12
4
+ version: 1.5.16
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-10-20 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown