kramdown-rfc2629 1.5.18 → 1.5.22

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: 1899e3dda0205ba1affda979ec1e972a27fc7d13ae721737e14cf4ab737b13ff
4
- data.tar.gz: 442106a989c71107a357d7c0bfec6ed9cf6b51c23cbfe870c81a26adc4542438
3
+ metadata.gz: 90fd02030501ff7ce234af8b2f2412b5c1372c8e865b368db995ab0a32347dc0
4
+ data.tar.gz: 31d7f8eed4b7adc64e8ff4458368e1380351089aa44478faf2987a78239d5cae
5
5
  SHA512:
6
- metadata.gz: 1072b3d275c6ff6692bdc2cb3e666ac76f3c4838d6978b822c034b6ac4c70bf29a5d0be20aad42881bd9dcdf1ef5b69decb59114ecbfbb4457988ef0b0a2f3aa
7
- data.tar.gz: 81360978cd5ff6692263c0b0b3aff2780b0b806ed83edd2d96ac40e5f705120ed54a529b874a51b27d25be10b44f14fd4bb84a7d7fe067dd3b2b73e4e1234714
6
+ metadata.gz: a39fa3bf7a2703f958dbc443d1d8d850a0a89ec9797f619218e921cdadd372e4466f628a1a3dbf13f178163a16f92141026ac34bfd52c82f1950fd3780d187aa
7
+ data.tar.gz: f02da291a9a611a4cb21097c2f31ee490a6327558cf1d66018279c89ef5f56f4ad87884046b19e44d347d5946346d0108a017e19aabb6b0db180f53a9847430a
data/README.md CHANGED
@@ -28,7 +28,8 @@ structure provided by kramdown. `bin/kramdown-rfc2629` started out as
28
28
  a simple command-line program showing how to use this, but can now do
29
29
  much more (see below).
30
30
 
31
- To use kramdown-rfc2629, you'll need a Ruby 2.x, and maybe
31
+ To use kramdown-rfc2629, you'll need Ruby (at least version 2.3, but
32
+ preferably a current version), and maybe
32
33
  [XML2RFC][] if you want to see the fruits of your work.
33
34
 
34
35
  kramdown-rfc2629 mydraft.mkd >mydraft.xml
data/bin/kramdown-rfc2629 CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'kramdown-rfc2629'
4
4
  require 'kramdown-rfc/parameterset'
5
5
  require 'kramdown-rfc/refxml'
6
+ require 'kramdown-rfc/rfc8792'
6
7
  require 'yaml'
7
8
  require 'kramdown-rfc/erb'
8
9
  require 'date'
@@ -24,8 +25,9 @@ def add_quote(s)
24
25
  l.map {|li| "> #{li}"}.join
25
26
  end
26
27
 
27
- def process_chunk(s, dedent, quote)
28
+ def process_chunk(s, dedent, fold, quote)
28
29
  s = remove_indentation(s) if dedent
30
+ s = fold8792_1(s) if fold
29
31
  s = add_quote(s) if quote
30
32
  s
31
33
  end
@@ -460,6 +462,7 @@ input.gsub!(/^\{::include((?:-[a-z]+)*)\s+(.*?)\}/) {
460
462
  fn = [$2]
461
463
  chunks = false
462
464
  dedent = false
465
+ fold = false
463
466
  quote = false
464
467
  include_flags.split("-") do |flag|
465
468
  case flag
@@ -468,11 +471,13 @@ input.gsub!(/^\{::include((?:-[a-z]+)*)\s+(.*?)\}/) {
468
471
  quote = true
469
472
  when "dedent"
470
473
  dedent = true
474
+ when "fold"
475
+ fold = true
471
476
  when "all", "last"
472
477
  fn = fn.flat_map{|n| Dir[n]}
473
478
  fn = [fn.last] if flag == "last"
474
479
  chunks = fn.map{ |f|
475
- ret = process_chunk(File.read(f), dedent, quote)
480
+ ret = process_chunk(File.read(f), dedent, fold, quote)
476
481
  dedent = false; quote = false
477
482
  ret
478
483
  }
@@ -481,7 +486,7 @@ input.gsub!(/^\{::include((?:-[a-z]+)*)\s+(.*?)\}/) {
481
486
  end
482
487
  end
483
488
  chunks = fn.map{|f| File.read(f)} unless chunks # no all/last
484
- chunks = chunks.map {|ch| process_chunk(ch, dedent, quote)}
489
+ chunks = chunks.map {|ch| process_chunk(ch, dedent, fold, quote)}
485
490
  chunks.join.chomp
486
491
  } unless ENV["KRAMDOWN_SAFE"]
487
492
  input.gsub!(/^\{::boilerplate\s+(.*?)\}/) {
@@ -12,14 +12,37 @@
12
12
  <% end -%>
13
13
  ]>
14
14
 
15
- <% ps.arr("pi", false) do |pi, val| -%>
16
- <?rfc <%=pi%>="<%= {true => "yes", false => "no", nil => "yes"}[val] || val %>"?>
15
+ <%
16
+ ps.rest.fetch("consensus") do
17
+ # consensus not given -- default intelligently
18
+ cat = ps.has("category") || ps.has("cat")
19
+ MUST_CONSENSUS = {"std" => true, "bcp" => true}
20
+ ps["consensus"] = true if MUST_CONSENSUS[cat]
21
+ end
22
+ rfcattrs = ps.attrs("ipr", "docName=docname", "category=cat",
23
+ "consensus", "submissionType=submissiontype", "xml:lang=lang",
24
+ "number", "obsoletes", "updates", "seriesNo=seriesno")
25
+ TRUE_FALSE = {nil => "true", false => "false", true => "true",
26
+ "yes" => "true", "no" => "false"}
27
+ YES_NO = {"true" => "yes", "false" => "no"}
28
+ pis = KramdownRFC::ParameterSet.new({})
29
+ ps.arr("pi", false) do |pi, val|
30
+ pis[pi] = TRUE_FALSE[val] || val
31
+ end
32
+ if $options.v3
33
+ piattrs = pis.attrs("tocDepth=tocdepth", "tocInclude=toc",
34
+ "sortRefs=sortrefs", "symRefs=symrefs", "indexInclude=index")
35
+ if piattrs != ""
36
+ rfcattrs << " " << piattrs
37
+ end
38
+ end
39
+ pis.rest.each do |pi, val|
40
+ v = YES_NO[val] || pis.escattr(val)
41
+ -%>
42
+ <?rfc <%=pi%>="<%=v%>"?>
17
43
  <% end -%>
18
44
 
19
- <rfc <%= ps.attrs("ipr", "docName=docname", "category=cat",
20
- "consensus", "submissionType=submissiontype", "xml:lang=lang",
21
- "number", "obsoletes", "updates", "seriesNo=seriesno") %>>
22
-
45
+ <rfc <%=rfcattrs%>>
23
46
  <front>
24
47
  <%= ps.ele("title", ps.attr("abbrev=titleabbrev")) %>
25
48
 
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.5.18'
3
+ s.version = '1.5.22'
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.}
@@ -13,6 +13,9 @@ module KramdownRFC
13
13
  def [](pn)
14
14
  @f.delete(pn.to_s)
15
15
  end
16
+ def []=(pn, val)
17
+ @f[pn] = val
18
+ end
16
19
  def has(pn)
17
20
  @f[pn.to_s]
18
21
  end
@@ -30,7 +33,7 @@ module KramdownRFC
30
33
  %{#{an}="#{escattr(val)}"} if val
31
34
  end
32
35
  def attrs(*pns)
33
- pns.map{ |pn| attr(pn) }.compact.join(" ")
36
+ pns.map{ |pn| attr(pn) if pn }.compact.join(" ")
34
37
  end
35
38
  def ele(pn, attr=nil, defcontent=nil, markdown=false)
36
39
  val, an = van(pn)
@@ -62,5 +65,4 @@ module KramdownRFC
62
65
  end
63
66
  end
64
67
 
65
-
66
68
  end
@@ -0,0 +1,59 @@
1
+ FOLD_COLUMNS = 69
2
+ RE_IDENT = /\A[A-Za-z0-9_]\z/
3
+
4
+ def fold8792_1(s, columns = FOLD_COLUMNS)
5
+ if s.index("\t")
6
+ warn "*** HT (\"TAB\") in text to be folded. Giving up."
7
+ return s
8
+ end
9
+
10
+ lines = s.lines.map(&:chomp)
11
+ did_fold = false
12
+ ix = 0
13
+ while li = lines[ix]
14
+ col = columns
15
+ if li[col].nil?
16
+ if li[-1] == "\\"
17
+ lines[ix..ix] = [li << "\\", ""]
18
+ ix += 1
19
+ end
20
+ ix += 1
21
+ else
22
+ did_fold = true
23
+ col -= 1 # space for "\\"
24
+ while li[col] == " " # can't start new line with " "
25
+ col -= 1
26
+ end
27
+ if col <= 0
28
+ warn "*** Cannot RFC8792-fold1 #{li.inspect}"
29
+ else
30
+ if RE_IDENT === li[col] # Don't split IDs
31
+ col2 = col
32
+ while col2 > 0 && RE_IDENT === li[col2-1]
33
+ col2 -= 1
34
+ end
35
+ if col2 > 0
36
+ col = col2
37
+ end
38
+ end
39
+ rest = li[col..-1]
40
+ indent = columns - rest.size
41
+ if li[-1] == "\\"
42
+ indent -= 1 # leave space for next round
43
+ end
44
+ if indent > 0
45
+ rest = " " * indent + rest
46
+ end
47
+ lines[ix..ix] = [li[0...col] << "\\", rest]
48
+ end
49
+ ix += 1
50
+ end
51
+ end
52
+
53
+ if did_fold
54
+ lines[0...0] = ["=== NOTE: '\\' line wrapping per RFC 8792 ===", ""]
55
+ lines.map{|x| x << "\n"}.join
56
+ else
57
+ s
58
+ end
59
+ 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.5.18
4
+ version: 1.5.22
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-11-29 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -99,6 +99,7 @@ files:
99
99
  - lib/kramdown-rfc/kdrfc-processor.rb
100
100
  - lib/kramdown-rfc/parameterset.rb
101
101
  - lib/kramdown-rfc/refxml.rb
102
+ - lib/kramdown-rfc/rfc8792.rb
102
103
  - lib/kramdown-rfc2629.rb
103
104
  homepage: http://github.com/cabo/kramdown-rfc2629
104
105
  licenses:
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements: []
122
- rubygems_version: 3.2.22
123
+ rubygems_version: 3.2.32
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: Kramdown extension for generating RFC 7749 XML.