kramdown-rfc2629 1.4.7 → 1.4.8

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: 92b7379a1d7172926d1d84ccdc5c816821a0c62c838b597dbc4e92cac91cff0d
4
- data.tar.gz: b501c48e3ff1bddaca7abec20125dc360de97f67076341d2b9812a3913cbf314
3
+ metadata.gz: cc148b7d5a6a85688d2fb08e18c43eaed83d2d260a09a76411ac5b843b6fe826
4
+ data.tar.gz: 81b2b54cea8334913f060748f41e70f9af5986930d57c2181355149a17a47077
5
5
  SHA512:
6
- metadata.gz: 3ae6bd5ad655d1300c426b06b00c92a7f56c15636b990d3d0ee02e2cc2a0481a7900d002e6076baa467aa2b3dc309719bedff0fd9e85912f083e85b0a9ef332c
7
- data.tar.gz: c5cce63d97840efc638bd14240f6652955bb291c46cc038426bb8209c2b65725c14ee3db850954e8ba1bf5f23781f44d388c5d9984be38a4a0f55e63eaef6b1f
6
+ metadata.gz: 3030de20ba98b79a56f391c69a38ff44c470f39830b550cfd96bbf3c2202f2eb3e5ffe60071657c81e91bbe4307b41b803e7d4a9778bf06aa61a9ec1ff87bb7b
7
+ data.tar.gz: c83e052a005012a7b2e5a595e1a4c1e133d651ee6e70e2bda135295a007f8a97b89cde5e1c1e7f9985333dd28df9f1f7566a3b57ce890e87229aaa412c84eacd
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.4.7'
3
+ s.version = '1.4.8'
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
- if markdown # Uuh. Heavy coupling.
38
- doc = Kramdown::Document.new(v, $global_markdown_options)
39
- $stderr.puts doc.warnings.to_yaml unless doc.warnings.empty?
40
- contents = doc.to_rfc2629[3..-6] # skip <t>...</t>\n
41
- else
42
- contents = escape_html(v)
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
@@ -42,32 +42,50 @@ module Kramdown
42
42
  @block_parsers.unshift(:block_pi)
43
43
  end
44
44
 
45
- SECTIONS_RE = /Section(?:s (?:[\w.]+, )*[\w.]+,? and)? [\w.]+/
46
-
47
- def handle_bares(s, attr, format, href)
48
- sa = s.sub(/\A\S+\s/, '').split(/,? and /)
49
- sa[0..0] = *sa[0].split(', ')
50
- sz = sa.size
51
- if sz != 1 # we have to redo xml2rfc's work here
52
- @tree.children << Element.new(:text, "Sections ", {}) # XXX needs to split into Section/Appendix
53
- sa.each_with_index do |sec, i|
54
- attr1 = {"target" => href, "section" => sec, "sectionFormat" => "bare"}
55
- @tree.children << Element.new(:xref, nil, attr1)
56
- text = if i == 0 && sz == 2
57
- " and "
58
- elsif i == sz-1
59
- " of "
60
- elsif i == sz-2
61
- ", and "
62
- else
63
- ", "
64
- end
65
- @tree.children << Element.new(:text, text, {})
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
- # attr stays unchanged, no section added
68
- else
69
- attr['section'] = sa[-1]
70
- attr['sectionFormat'] = format
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
@@ -729,6 +757,7 @@ COLORS
729
757
 
730
758
  def convert_xref(el, indent, opts)
731
759
  gi = el.attr.delete('gi')
760
+ text = el.attr.delete('text')
732
761
  target = el.attr['target']
733
762
  if target[0] == "&"
734
763
  "#{target};"
@@ -738,7 +767,12 @@ COLORS
738
767
  else
739
768
  gi ||= "xref"
740
769
  end
741
- "<#{gi}#{el_html_attributes(el)}/>"
770
+ if text
771
+ tail = ">#{Rfc2629::process_markdown(text)}</#{gi}>"
772
+ else
773
+ tail = "/>"
774
+ end
775
+ "<#{gi}#{el_html_attributes(el)}#{tail}"
742
776
  end
743
777
  end
744
778
 
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.7
4
+ version: 1.4.8
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-03 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown