kramdown-rfc2629 1.4.17 → 1.5.2

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: 995b589ce86783d0aa3f5e3193cdb0399ace572b239fade7995c5699f6e4f8de
4
- data.tar.gz: ea44d32db3e9c9a57210da431859ede63d5a2d756dd05f0beee9bbc1722e2cc3
3
+ metadata.gz: a4b5c45b8847c6578542b8920d23c017bd22ef3bf35fe005d871c8a305738219
4
+ data.tar.gz: 2f2ff22d21077a464373dfe592af271457e1f2cfec8c4f353da92e0ffd559e01
5
5
  SHA512:
6
- metadata.gz: 8e51f7d06bc29eb1cef1c475443f207474e23e903e0b9880ec29507a902aba034407821dbfa177aca297905571a6f404e651eefb62005bea55715fed885dd575
7
- data.tar.gz: fccef7a2f854bebea02100f3dea2ab5c5cbcd0800f2bcd83272869d40255d1455aa76ecc5137e78c22f4871b4971acbbc02a00b7656a12cd595ebe1444447fb7
6
+ metadata.gz: b9f8b2a133cfc9e511804df4bd7be41ed0b59203a2997d277fb888f2b7b3ac494988f8bb7a9ba084c4ebe7253a141daef4aa8f9c4147329d9a19ba1bdc62a649
7
+ data.tar.gz: 562538aacef3d53eed6fc976d08e78d72838c8c28ea29a9a47fa65652ebaed34d05fff26bbba1570161740431aa9e9bef487083216ab7833db8ad1e93c0045a3
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
 
@@ -558,7 +562,7 @@ remaining 20 % some more, but that hasn't been done.
558
562
 
559
563
  If you have XML, there is an experimental upconverter that does 99 %
560
564
  of the work. Please [contact the
561
- author](mailto:cabo@tzi.org?subject=Markdown for RFCXML) if you want
565
+ author](mailto:cabo@tzi.org?subject=Markdown%20for%20RFCXML) if you want
562
566
  to try it.
563
567
 
564
568
  Actually, if the XML was generated by kramdown-rfc2629, you can simply
data/bin/kdrfc CHANGED
@@ -1,107 +1,13 @@
1
1
  #!/usr/bin/env ruby -KU
2
- require 'uri'
3
- require 'net/http'
4
- require 'open3'
2
+ require 'kramdown-rfc/kdrfc-processor'
3
+ require 'optparse'
5
4
 
6
5
  # try to get this from gemspec.
7
6
  KDRFC_VERSION=Gem.loaded_specs["kramdown-rfc2629"].version rescue "unknown-version"
8
7
 
9
- def v3_flag?
10
- $options.v3 ? ["--v3"] : []
11
- end
12
-
13
- def process_mkd(input, output)
14
- warn "* converting locally from markdown #{input} to xml #{output}" if $options.verbose
15
- o, s = Open3.capture2("kramdown-rfc2629", *v3_flag?, input)
16
- if s.success?
17
- File.open(output, "w") do |fo|
18
- fo.print(o)
19
- end
20
- warn "* #{output} written" if $options.verbose
21
- else
22
- warn "*** kramdown-rfc failed, status #{s.exitstatus}"
23
- exit 1
24
- end
25
- end
26
-
27
- def run_idnits(txt_fn)
28
- unless system("idnits", txt_fn)
29
- warn "*** problem #$? running idnits"
30
- end
31
- end
8
+ kdrfc = KramdownRFC::KDRFC.new
9
+ kdrfc.options.txt = true # default
32
10
 
33
- def process_xml(*args)
34
- if $options.remote
35
- process_xml_remotely(*args)
36
- else
37
- process_xml_locally(*args)
38
- end
39
- end
40
-
41
- def process_xml_locally(input, output, *flags)
42
- warn "* converting locally from xml #{input} to txt #{output}" if $options.verbose
43
- begin
44
- o, s = Open3.capture2("xml2rfc", *v3_flag?, *flags, input)
45
- puts o
46
- if s.success?
47
- warn "* #{output} written" if $options.verbose
48
- else
49
- warn "*** xml2rfc failed, status #{s.exitstatus} (possibly try with -r)"
50
- exit 1
51
- end
52
- rescue Errno::ENOENT
53
- warn "*** falling back to remote processing" if $options.verbose
54
- process_xml_remotely(input, output)
55
- end
56
- end
57
-
58
- XML2RFC_WEBSERVICE = ENV["KRAMDOWN_XML2RFC_WEBSERVICE"] ||
59
- 'http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc-dev.cgi'
60
-
61
-
62
- def process_xml_remotely(input, output)
63
- warn "* converting remotely from xml #{input} to txt #{output}" if $options.verbose
64
- url = URI(XML2RFC_WEBSERVICE)
65
- req = Net::HTTP::Post.new(url)
66
- form = [["modeAsFormat", "txt/#{"v3" if $options.v3}ascii"],
67
- ["type", "binary"],
68
- ["input", File.open(input),
69
- {filename: "input.xml",
70
- content_type: "text/plain"}]]
71
- diag = ["url/form: ", url, form].inspect
72
- req.set_form(form, 'multipart/form-data')
73
- res = Net::HTTP::start(url.hostname, url.port,
74
- :use_ssl => url.scheme == 'https' ) {|http|
75
- http.request(req)
76
- }
77
- case res
78
- when Net::HTTPOK
79
- case res.content_type
80
- when 'application/octet-stream'
81
- if res.body == ''
82
- warn "*** HTTP response is empty with status #{res.code}, not written"
83
- exit 1
84
- end
85
- File.open(output, "w") do |fo|
86
- fo.print(res.body)
87
- end
88
- warn "* #{output} written" if $options.verbose
89
- else
90
- warn "*** HTTP response has unexpected content_type #{res.content_type} with status #{res.code}, #{diag}"
91
- warn res.body
92
- exit 1
93
- end
94
- else
95
- warn "*** HTTP response: #{res.code}, #{diag}"
96
- exit 1
97
- end
98
- end
99
-
100
- require 'optparse'
101
- require 'ostruct'
102
-
103
- $options = OpenStruct.new
104
- $options.txt = true # default
105
11
  op = OptionParser.new do |opts|
106
12
  opts.banner = <<BANNER
107
13
  Usage: kdrfc [options] file.md|file.mkd|file.xml
@@ -116,63 +22,45 @@ BANNER
116
22
  exit
117
23
  end
118
24
  opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
119
- $options.verbose = v
25
+ kdrfc.options.verbose = v
120
26
  end
121
27
  opts.on("-r", "--[no-]remote", "Run xml2rfc remotely even if there is a local one") do |v|
122
- $options.remote = v
28
+ kdrfc.options.remote = v
123
29
  end
124
30
  opts.on("-x", "--[no-]xml", "Convert to xml only") do |v|
125
- $options.xml_only = v
31
+ kdrfc.options.xml_only = v
126
32
  end
127
33
  opts.on("-p", "--[no-]prep", "Convert xml to prepped xml") do |v|
128
- $options.prep = v
34
+ kdrfc.options.prep = v
129
35
  end
130
36
  opts.on("-P", "-f", "--[no-]pdf", "Convert xml to PDF") do |v|
131
- $options.pdf = v
37
+ kdrfc.options.pdf = v
132
38
  end
133
39
  opts.on("-c", "--[no-]convert", "Convert xml to v3 xml") do |v|
134
- $options.v2v3 = v
40
+ kdrfc.options.v2v3 = v
135
41
  end
136
42
  opts.on("-i", "--[no-]idnits", "Run idnits on the resulting text") do |v|
137
- $options.idnits = v
43
+ kdrfc.options.idnits = v
138
44
  end
139
45
  opts.on("-h", "--[no-]html", "Convert to html as well") do |v|
140
- $options.html = v
46
+ kdrfc.options.html = v
141
47
  end
142
48
  opts.on("-t", "--[no-]txt", "Convert to txt as well") do |v|
143
- $options.txt = v
49
+ kdrfc.options.txt = v
144
50
  end
145
51
  opts.on("-3", "--[no-]v3", "Use RFCXML v3 processing rules") do |v|
146
- $options.v3 = v
52
+ kdrfc.options.v3 = v
147
53
  end
148
54
  end
149
55
  op.parse!
150
56
 
151
- def process_the_xml(fn, base)
152
- process_xml(fn, "#{base}.prepped.xml", "--preptool") if $options.prep
153
- process_xml(fn, "#{base}.v2v3.xml", "--v2v3") if $options.v2v3
154
- process_xml(fn, "#{base}.txt") if $options.txt || $options.idnits
155
- process_xml(fn, "#{base}.html", "--html") if $options.html
156
- process_xml(fn, "#{base}.pdf", "--pdf") if $options.pdf
157
- run_idnits("#{base}.txt") if $options.idnits
158
- end
159
-
160
57
  case ARGV.size
161
58
  when 1
162
59
  fn = ARGV[0]
163
- case fn
164
- when /(.*)\.xml\z/
165
- if $options.xml_only
166
- warn "*** You already have XML"
167
- else # FIXME: copy/paste
168
- process_the_xml(fn, $1)
169
- end
170
- when /(.*)\.mk?d\z/
171
- xml = "#$1.xml"
172
- process_mkd(fn, xml)
173
- process_the_xml(xml, $1) unless $options.xml_only
174
- else
175
- warn "Unknown file type: #{fn}"
60
+ begin
61
+ kdrfc.process(fn)
62
+ rescue StandardError => e
63
+ warn e.to_s
176
64
  exit 1
177
65
  end
178
66
  else
@@ -14,7 +14,7 @@ require 'fileutils'
14
14
 
15
15
  begin
16
16
  require 'net/http/persistent'
17
- rescue
17
+ rescue LoadError
18
18
  warn "*** please install net-http-persistent:"
19
19
  warn " gem install net-http-persistent"
20
20
  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
 
@@ -195,6 +195,7 @@ def xml_from_sections(input)
195
195
  sechash = Hash.new{ |h,k| h[k] = ""}
196
196
  snames = [] # a stack of section names
197
197
  sections.each do |sname, nmdflag, text|
198
+ # warn [:SNAME, sname, nmdflag, text[0..10]].inspect
198
199
  nmdin, nmdout = {
199
200
  "-" => ["", ""], # stay in nomarkdown
200
201
  "" => NMDTAGS, # pop out temporarily
@@ -306,7 +307,7 @@ def xml_from_sections(input)
306
307
  [:normative, :informative].each do |sn|
307
308
  if refs = ps[sn]
308
309
  refs.each do |k, v|
309
- href = k.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an IDREF with a number
310
+ href = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(k)
310
311
  kramdown_options[:link_defs][k] = ["##{href}", nil] # allow [RFC2119] in addition to {{RFC2119}}
311
312
 
312
313
  bibref = anchor_to_bibref[k] || k
@@ -363,7 +364,7 @@ def bibtagsys(bib, anchor=nil, stand_alone=true)
363
364
  elsif bib =~ /\A([-A-Z0-9]+)\./ &&
364
365
  (xro = Kramdown::Converter::Rfc2629::XML_RESOURCE_ORG_MAP[$1])
365
366
  dir, _ttl, rewrite_anchor = xro
366
- bib1 = bib.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an ID with a number
367
+ bib1 = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(bib)
367
368
  if anchor && bib1 != anchor
368
369
  if rewrite_anchor
369
370
  a = %{?anchor=#{anchor}}
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.4.17'
3
+ s.version = '1.5.2'
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.}
@@ -0,0 +1,154 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'open3'
4
+ require 'ostruct'
5
+
6
+ module KramdownRFC
7
+
8
+ class KDRFC
9
+
10
+ attr_reader :options
11
+
12
+ def initialize
13
+ @options = OpenStruct.new
14
+ end
15
+
16
+ # )))
17
+
18
+ KDRFC_PREPEND = [ENV["KDRFC_PREPEND"]].compact
19
+
20
+ def v3_flag?
21
+ @options.v3 ? ["--v3"] : []
22
+ end
23
+
24
+ def process_mkd(input, output)
25
+ warn "* converting locally from markdown #{input} to xml #{output}" if @options.verbose
26
+ o, s = Open3.capture2(*KDRFC_PREPEND, "kramdown-rfc2629", *v3_flag?, input)
27
+ if s.success?
28
+ File.open(output, "w") do |fo|
29
+ fo.print(o)
30
+ end
31
+ warn "* #{output} written" if @options.verbose
32
+ else
33
+ raise IOError.new("*** kramdown-rfc failed, status #{s.exitstatus}")
34
+ end
35
+ end
36
+
37
+ def run_idnits(txt_fn)
38
+ unless system("idnits", txt_fn)
39
+ warn "*** problem #$? running idnits"
40
+ end
41
+ end
42
+
43
+ def process_xml(*args)
44
+ if @options.remote
45
+ process_xml_remotely(*args)
46
+ else
47
+ process_xml_locally(*args)
48
+ end
49
+ end
50
+
51
+ def process_xml_locally(input, output, *flags)
52
+ warn "* converting locally from xml #{input} to txt #{output}" if @options.verbose
53
+ begin
54
+ o, s = Open3.capture2(*KDRFC_PREPEND, "xml2rfc", *v3_flag?, *flags, input)
55
+ puts o
56
+ if s.success?
57
+ warn "* #{output} written" if @options.verbose
58
+ else
59
+ raise IOError.new("*** xml2rfc failed, status #{s.exitstatus} (possibly try with -r)")
60
+ end
61
+ rescue Errno::ENOENT
62
+ warn "*** falling back to remote xml2rfc processing (web service)" # if @options.verbose
63
+ process_xml_remotely(input, output, *flags)
64
+ end
65
+ end
66
+
67
+ XML2RFC_WEBSERVICE = ENV["KRAMDOWN_XML2RFC_WEBSERVICE"] ||
68
+ 'http://xml2rfc.tools.ietf.org/cgi-bin/xml2rfc-dev.cgi'
69
+
70
+ MODE_AS_FORMAT = {
71
+ nil => { # v2
72
+ "--text" => "txt/ascii",
73
+ "--html" => "html/ascii",
74
+ },
75
+ true => { # v3
76
+ "--text" => "txt/v3ascii",
77
+ "--html" => "html/v3ascii",
78
+ "--v2v3" => "v3xml/ascii",
79
+ }
80
+ }
81
+
82
+ def process_xml_remotely(input, output, *flags)
83
+ warn "* converting remotely from xml #{input} to txt #{output}" if @options.verbose
84
+ format = flags[0] || "--text"
85
+ # warn [:V3, @options.v3].inspect
86
+ maf = MODE_AS_FORMAT[@options.v3][format]
87
+ unless maf
88
+ raise ArgumentError.new("*** don't know how to convert remotely from xml #{input} to txt #{output}")
89
+ end
90
+ url = URI(XML2RFC_WEBSERVICE)
91
+ req = Net::HTTP::Post.new(url)
92
+ form = [["modeAsFormat", maf],
93
+ ["type", "binary"],
94
+ ["input", File.open(input),
95
+ {filename: "input.xml",
96
+ content_type: "text/plain"}]]
97
+ diag = ["url/form: ", url, form].inspect
98
+ req.set_form(form, 'multipart/form-data')
99
+ res = Net::HTTP::start(url.hostname, url.port,
100
+ :use_ssl => url.scheme == 'https' ) {|http|
101
+ http.request(req)
102
+ }
103
+ case res
104
+ when Net::HTTPOK
105
+ case res.content_type
106
+ when 'application/octet-stream'
107
+ if res.body == ''
108
+ raise IOError.new("*** HTTP response is empty with status #{res.code}, not written")
109
+ end
110
+ File.open(output, "w") do |fo|
111
+ fo.print(res.body)
112
+ end
113
+ warn "* #{output} written" if @options.verbose
114
+ else
115
+ warning = "*** HTTP response has unexpected content_type #{res.content_type} with status #{res.code}, #{diag}"
116
+ warning << "\n"
117
+ warning << res.body
118
+ raise IOError.new(warning)
119
+ end
120
+ else
121
+ raise IOError.new("*** HTTP response: #{res.code}, #{diag}")
122
+ end
123
+ end
124
+
125
+ def process_the_xml(fn, base)
126
+ process_xml(fn, "#{base}.prepped.xml", "--preptool") if @options.prep
127
+ process_xml(fn, "#{base}.v2v3.xml", "--v2v3") if @options.v2v3
128
+ process_xml(fn, "#{base}.txt") if @options.txt || @options.idnits
129
+ process_xml(fn, "#{base}.html", "--html") if @options.html
130
+ process_xml(fn, "#{base}.pdf", "--pdf") if @options.pdf
131
+ run_idnits("#{base}.txt") if @options.idnits
132
+ end
133
+
134
+ def process(fn)
135
+ case fn
136
+ when /(.*)\.xml\z/
137
+ if @options.xml_only
138
+ warn "*** You already have XML"
139
+ else # FIXME: copy/paste
140
+ process_the_xml(fn, $1)
141
+ end
142
+ when /(.*)\.mk?d\z/
143
+ xml = "#$1.xml"
144
+ process_mkd(fn, xml)
145
+ process_the_xml(xml, $1) unless @options.xml_only
146
+ else
147
+ raise ArgumentError.new("Unknown file type: #{fn}")
148
+ end
149
+ end
150
+
151
+ # (((
152
+ end
153
+
154
+ end
@@ -57,17 +57,35 @@ module KramdownRFC
57
57
  aups
58
58
  end
59
59
 
60
+ # The below anticipates the "postalLine" changes.
61
+ # If a postalLine is used (abbreviated "postal" in YAML),
62
+ # non-postalLine elements are appended as further postalLines.
63
+ # This prepares for how "country" is expected to be handled
64
+ # specially with the next schema update.
65
+ # So an address is now best keyboarded as:
66
+ # postal:
67
+ # - Foo Street
68
+ # - 28359 Bar
69
+ # country: Germany
70
+
60
71
  PERSON_ERB = <<~ERB
61
72
  <<%= element_name%> <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
62
73
  <%= aups.ele("organization=org", aups.attrs("abbrev=orgabbrev",
63
74
  *[$options.v3 && "ascii=orgascii"]), "") %>
64
75
  <address>
65
- <% postal = %w{street city region code country}.select{|gi| aups.has(gi)}
66
- if postal != [] -%>
76
+ <% postal_elements = %w{extaddr pobox street cityarea city region code sortingcode country postal}.select{|gi| aups.has(gi)}
77
+ if postal_elements != [] -%>
67
78
  <postal>
68
- <% postal.each do |gi| -%>
79
+ <% if pl = postal_elements.delete("postal") -%>
80
+ <%= aups.ele("postalLine=postal") %>
81
+ <% postal_elements.each do |gi| -%>
82
+ <%= aups.ele("postalLine=" << gi) %>
83
+ <% end -%>
84
+ <% else -%>
85
+ <% postal_elements.each do |gi| -%>
69
86
  <%= aups.ele(gi) %>
70
87
  <% end -%>
88
+ <% end -%>
71
89
  </postal>
72
90
  <% end -%>
73
91
  <% %w{phone facsimile email uri}.select{|gi| aups.has(gi)}.each do |gi| -%>
@@ -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,14 @@ 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
+ if href =~ / /
57
+ warn "** space(s) in cross-reference '#{href}' -- are you trying to use section references?"
58
+ end
59
+ href.gsub(/\A(?:[0-9]|section-|u-|figure-|table-|iref-)/) { "_#{$&}" }
60
+ end
61
+
54
62
  def handle_bares(s, attr, format, href, last_join = nil)
55
63
  if s.match(/\A(#{XREF_ANY}) and (#{XREF_ANY})\z/)
56
64
  handle_bares($1, {}, nil, href, " and ")
@@ -120,7 +128,7 @@ module Kramdown
120
128
  when /\A(.*) \((#{SECTIONS_RE})\)\z/
121
129
  href = $1
122
130
  handle_bares($2, attr, "parens", href)
123
- when /\A([\w.]+)<(.+)\z/
131
+ when /\A(#{XREF_BASE})<(.+)\z/
124
132
  href = $2
125
133
  attr['section'] = $1
126
134
  attr['sectionFormat'] = 'bare'
@@ -132,11 +140,11 @@ module Kramdown
132
140
  attr['format'] = 'counter'
133
141
  end
134
142
  end
135
- if href.match(XREF_RE_M)
143
+ if href.match(/#{XREF_RE_M}\z/)
136
144
  href = $1
137
145
  attr['text'] = $2
138
146
  end
139
- href = href.gsub(/\A[0-9]/) { "_#{$&}" } # can't start an IDREF with a number
147
+ href = self.class.idref_cleanup(href)
140
148
  attr['target'] = href
141
149
  el = Element.new(:xref, nil, attr)
142
150
  end
@@ -212,10 +220,10 @@ module Kramdown
212
220
  def rfc2629_fix
213
221
  if a = attr
214
222
  if anchor = a.delete('id')
215
- a['anchor'] = anchor
223
+ a['anchor'] = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
216
224
  end
217
225
  if anchor = a.delete('href')
218
- a['target'] = anchor
226
+ a['target'] = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
219
227
  end
220
228
  attr.keys.each do |k|
221
229
  if (d = k.gsub(/_(.|$)/) { $1.upcase }) != k or d = STUDLY_ATTR_MAP[k]
@@ -959,7 +967,7 @@ COLORS
959
967
  warn "*** missing anchor for '#{src}'"
960
968
  src
961
969
  )
962
- anchor.sub!(/\A[0-9]/) { "_#{$&}" } # can't start an ID with a number
970
+ anchor = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(anchor)
963
971
  anchor.gsub!('/', '_') # should take out all illegals
964
972
  to_insert = ""
965
973
  src.scan(/(W3C|3GPP|[A-Z-]+)[.]?([A-Za-z_0-9.\/\+-]+)/) do |t, n|
@@ -1027,18 +1035,30 @@ COLORS
1027
1035
  # this would be more like xml2rfc v3:
1028
1036
  # "\n#{' '*indent}<cref>\n#{inner(el.value, indent, opts).rstrip}\n#{' '*indent}</cref>"
1029
1037
  content = inner(el.value, indent, opts).strip
1030
- content = escape_html(content.sub(/\A<t>(.*)<\/t>\z/m) {$1}, :text) # text only...
1031
- name = el.options[:name].sub(/\A[0-9]/) {"_" << $&}
1038
+ content = content.sub(/\A<t>(.*)<\/t>\z/m) {$1}
1039
+ name = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(el.options[:name])
1040
+ o_name = name.dup
1032
1041
  while @footnote_names_in_use[name] do
1033
- if name =~ /:\d+\z/
1042
+ if name =~ /_\d+\z/
1034
1043
  name.succ!
1035
1044
  else
1036
- name << ":1"
1045
+ name << "_1"
1037
1046
  end
1038
1047
  end
1039
1048
  @footnote_names_in_use[name] = true
1040
1049
  attrstring = el_html_attributes_with(el, {"anchor" => name})
1041
- "\n#{' '*indent}<cref#{attrstring}>#{content}</cref>"
1050
+ if $options.v3
1051
+ if o_name[-1] == "-"
1052
+ # Ignore HTML attributes. Hmm.
1053
+ content
1054
+ else
1055
+ # do not indent span-level so we can stick to previous word. Good?
1056
+ "<cref#{attrstring}>#{content}</cref>"
1057
+ end
1058
+ else
1059
+ content = escape_html(content, :text) # text only...
1060
+ "\n#{' '*indent}<cref#{attrstring}>#{content}</cref>"
1061
+ end
1042
1062
  end
1043
1063
 
1044
1064
  def convert_raw(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.4.17
4
+ version: 1.5.2
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-06-18 00:00:00.000000000 Z
11
+ date: 2021-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -80,6 +80,7 @@ files:
80
80
  - kramdown-rfc2629.gemspec
81
81
  - lib/kramdown-rfc/erb.rb
82
82
  - lib/kramdown-rfc/gzip-clone.rb
83
+ - lib/kramdown-rfc/kdrfc-processor.rb
83
84
  - lib/kramdown-rfc/parameterset.rb
84
85
  - lib/kramdown-rfc/refxml.rb
85
86
  - lib/kramdown-rfc2629.rb
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  - !ruby/object:Gem::Version
103
104
  version: '0'
104
105
  requirements: []
105
- rubygems_version: 3.2.15
106
+ rubygems_version: 3.2.22
106
107
  signing_key:
107
108
  specification_version: 4
108
109
  summary: Kramdown extension for generating RFC 7749 XML.