kramdown-rfc2629 1.7.10 → 1.7.12

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: b0a5264ae5d33d3262c29ecb664f1e40d0ad952fe43eea5858d291aab075159b
4
- data.tar.gz: b3658555f711dce89c2c2919520b7e1734d620cdebba552b2eec33a24de78bf2
3
+ metadata.gz: a02556065093c31f3e45dd93a7497bd94a08e304d8eb00a409d2ee15da28987c
4
+ data.tar.gz: 8bb1dd4ea40f37625497b6742fa0c8822620c9a237e773ed1d2f6797e47269ba
5
5
  SHA512:
6
- metadata.gz: 9624afa4465c9e3307568787cbd49f18efa8f8924d12398b3c40c413607af0dd23b592e3456fe21d18ce7ac4a37cf8925aefc86f32ef8d5c183ded1197c52404
7
- data.tar.gz: 4627bc17140218836e34cb22237a7cea860c9f6b74452292dcab4e83ced32444386236c247848984afd62a7d5db84500b46890c2a369e12cfda5510c838b6bc0
6
+ metadata.gz: bd31dc90ac74e3f080491ef7df46814f90b7f60d801547598c8e4086215462280fa78e58c01b25b28c26753fb5021025828c768bbb8a792db67c494d398f05e7
7
+ data.tar.gz: 917ebce9132621c9117160273cdab943cf1ec947cc632f320557c0cdb18dbcc01c1c9ead0e79c3a254671d34eb3c4cf91f4fdc6578b0bd6c7454348cb3999a48
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env ruby -KU
2
+ # frozen_string_literal: true
3
+ require 'rexml/document' # for SVG and bibxml acrobatics
4
+ require 'yaml'
5
+ require 'json'
6
+ require 'shellwords'
7
+ require 'fileutils'
8
+ begin
9
+ require 'open-uri/cached'
10
+ rescue LoadError
11
+ warn '*** please "gem install open-uri-cached" to enable caching'
12
+ require 'open-uri'
13
+ end
14
+ require_relative '../lib/kramdown-rfc/rexml-all-text.rb'
15
+
16
+ target = :shortname
17
+ require 'optparse'
18
+ begin
19
+ op = OptionParser.new do |opts|
20
+ opts.banner = "Usage: kramdown-rfc-lsr [options] xml-source"
21
+ opts.on("-u", "--url", "Source is URL") do |v|
22
+ target = :url
23
+ end
24
+ opts.on("-s", "--shortname", "Source is shortname (default)") do |v|
25
+ target = :shortname
26
+ end
27
+ opts.on("-f", "--file", "Source is filename") do |v|
28
+ target = :file
29
+ end
30
+ end
31
+ op.parse!
32
+ rescue Exception => e
33
+ warn e
34
+ exit 1
35
+ end
36
+
37
+ $exit_code = 0
38
+
39
+ if target != :file && ARGV.size != 1
40
+ puts op
41
+ exit 1
42
+ end
43
+ xmlsource = ARGV[0]
44
+ if target == :shortname
45
+ xmlsource = case xmlsource
46
+ when /^(?:rfc)?(\d+)$/i
47
+ "https://www.rfc-editor.org/rfc/rfc#{$1.to_i.to_s}.xml"
48
+ when /^(?:draft-|I-D.|)(.*-\d\d)$/
49
+ "https://www.ietf.org/archive/id/draft-#$1.xml"
50
+ # XXX find xml source for most recent version!
51
+ else
52
+ warn "*** Can't parse shortname #{xmlsource.inspect}"
53
+ puts op
54
+ exit 1
55
+ end
56
+ target = :url
57
+ end
58
+
59
+ begin
60
+ xml = case target
61
+ when :file
62
+ ARGF.read
63
+ when :url
64
+ URI(xmlsource).open.read
65
+ else
66
+ fail
67
+ end
68
+ rescue Exception => e
69
+ warn "#{xmlsource.inspect}: #{e}"
70
+ exit 1
71
+ end
72
+
73
+ doc = REXML::Document.new(xml)
74
+
75
+ def series_info_to_URI(si)
76
+ case si[:name]
77
+ when "RFC"
78
+ "https://www.rfc-editor.org/rfc/rfc#{si[:value]}.xml"
79
+ when "Internet-Draft"
80
+ "https://www.ietf.org/archive/id/#{si[:value]}.xml"
81
+ end
82
+ end
83
+
84
+
85
+ def series_info_to_name(si)
86
+ case si[:name]
87
+ when "RFC"
88
+ "RFC#{si[:value]}"
89
+ when "Internet-Draft"
90
+ si[:value]
91
+ end
92
+ end
93
+
94
+ def section_number_to_pn(s)
95
+ if /^[0-9]/ =~ s
96
+ "section-#{s}"
97
+ elsif /[.]/ =~ s
98
+ "section-#{s.downcase}"
99
+ else
100
+ "section-appendix.#{s.downcase}"
101
+ end
102
+ end
103
+
104
+ references = Hash[REXML::XPath.match(doc.root, "//reference").map {|r|
105
+ si = REXML::XPath.match(r, "seriesInfo").map {|s|
106
+ series_info_to_URI(s)}.compact.first
107
+ sn = REXML::XPath.match(r, "seriesInfo").map {|s|
108
+ series_info_to_name(s)}.compact.first
109
+ [r[:anchor], si ? [si, sn] : nil]
110
+ }] # XXX duplicates?
111
+
112
+ puts "# #{xmlsource}"
113
+
114
+ per_reference = Hash.new { |h, k| h[k] = Set[]}
115
+
116
+ REXML::XPath.each(doc.root, "//xref[@section]") do |x|
117
+ trg = x[:target]
118
+ if x[:relative]
119
+ puts "\n## #{x[:target]}#{x[:relative]}: #{x[:section]}"
120
+ else
121
+ # p x
122
+ per_reference[trg] << x[:section]
123
+ end
124
+ end
125
+
126
+ def error_out(s)
127
+ warn ""
128
+ warn s
129
+ warn ""
130
+ $exit_code = 1
131
+ end
132
+
133
+ per_reference.keys.sort.each do |trg|
134
+ uri, sname = references[trg]
135
+ add = +''
136
+ if sname != trg
137
+ add << " [#{sname}]"
138
+ end
139
+ begin
140
+ ref = URI(uri).open.read
141
+ refdoc = REXML::Document.new(ref)
142
+ add << " (#{REXML::XPath.match(refdoc.root, "//title").first.all_text})"
143
+ rescue OpenURI::HTTPError => e
144
+ begin
145
+ refjson = URI(uri.sub(/\.xml$/, ".json")).open.read
146
+ refdata = JSON.load(refjson)
147
+ add << " (#{refdata["title"]})"
148
+ rescue Exception => e
149
+ add << " [No XML or JSON]"
150
+ end
151
+ rescue Exception => e
152
+ warn "*** error getting #{uri.inspect}: #{e}"
153
+ end
154
+ puts "\n## #{trg}#{add}"
155
+ per_reference[trg].to_a.sort.each do |s| # XXX numerically
156
+ secterm = if /^[0-9]/ =~ s
157
+ "Section"
158
+ else
159
+ "Appendix"
160
+ end
161
+ add = +''
162
+ if refdoc
163
+ # find section name from anchor s
164
+ # secname = "DUMMY" # REXML::XPath.match(refdoc.root, "//section").first.all_text
165
+ secpn = section_number_to_pn(s)
166
+ secs = REXML::XPath.match(refdoc.root, "//section[@pn=$pn]", {}, {"pn" => secpn})
167
+ secname = nil
168
+ case secs.size
169
+ when 0
170
+ error_out "*** cannot match #{secpn} in #{trg}"
171
+ secname = "*** DOESN'T EXIST ***"
172
+ when 1
173
+ sec = secs.first
174
+ secname = sec[:title] || sec.elements["name"].all_text
175
+ else
176
+ error_out "*** multiple matches for #{secpn} in #{trg}"
177
+ secname = "*** MULTIPLE MATCHES ***"
178
+ end
179
+ add << " (#{secname})"
180
+ end
181
+ puts "* #{secterm} #{s}#{add}"
182
+ end
183
+ end
184
+
185
+ exit $exit_code
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.7.10'
3
+ s.version = '1.7.12'
4
4
  s.summary = "Kramdown extension for generating RFCXML (RFC 799x)."
5
5
  s.description = %{An RFCXML (RFC 799x) generating backend for Thomas Leitner's
6
6
  "kramdown" markdown parser. Mostly useful for RFC writers.}
@@ -13,11 +13,12 @@ spec = Gem::Specification.new do |s|
13
13
  s.add_dependency('unicode-scripts', '~> 1.0')
14
14
  s.add_dependency('net-http-persistent', '~> 4.0')
15
15
  s.add_dependency('differ', '~>0.1')
16
- s.files = Dir['lib/**/*.rb'] + %w(README.md LICENSE kramdown-rfc2629.gemspec bin/kdrfc bin/kramdown-rfc bin/kramdown-rfc2629 bin/doilit bin/echars bin/kramdown-rfc-extract-markdown bin/kramdown-rfc-extract-sourcecode data/kramdown-rfc2629.erb data/encoding-fallbacks.txt data/math.json bin/kramdown-rfc-cache-subseries-bibxml bin/kramdown-rfc-autolink-iref-cleanup bin/de-gfm bin/kramdown-rfc-clean-svg-ids)
16
+ s.files = Dir['lib/**/*.rb'] + %w(README.md LICENSE kramdown-rfc2629.gemspec bin/kdrfc bin/kramdown-rfc bin/kramdown-rfc2629 bin/doilit bin/echars bin/kramdown-rfc-extract-markdown bin/kramdown-rfc-extract-sourcecode bin/kramdown-rfc-lsr data/kramdown-rfc2629.erb data/encoding-fallbacks.txt data/math.json bin/kramdown-rfc-cache-subseries-bibxml bin/kramdown-rfc-autolink-iref-cleanup bin/de-gfm bin/kramdown-rfc-clean-svg-ids)
17
17
  s.require_path = 'lib'
18
18
  s.executables = ['kramdown-rfc', 'kramdown-rfc2629', 'doilit', 'echars',
19
19
  'kramdown-rfc-extract-markdown',
20
20
  'kramdown-rfc-extract-sourcecode',
21
+ 'kramdown-rfc-lsr',
21
22
  'kdrfc', 'kramdown-rfc-cache-i-d-bibxml',
22
23
  'kramdown-rfc-cache-subseries-bibxml',
23
24
  'kramdown-rfc-autolink-iref-cleanup',
@@ -33,6 +33,15 @@ end
33
33
 
34
34
  module Kramdown
35
35
 
36
+ Kramdown::Options.define(:ol_start_at_first_marker, Kramdown::Options::Boolean, false, <<~EOF)
37
+ If this option is `true`, an ordered list (<ol) will use the
38
+ number in its first marker (1 for 1. etc.) as the default value
39
+ of the start= attribute.
40
+
41
+ Default: false (for backward compatibility)
42
+ Used by: RFCXML converter
43
+ EOF
44
+
36
45
  Kramdown::Options.define(:nested_ol_types, Object, %w[1], <<~EOF) do |val|
37
46
  Values for type= attribute for nested ordered lists (ol).
38
47
  The value needs to be an array of <ol type= values, expressed as one of:
@@ -919,6 +928,10 @@ COLORS
919
928
  end
920
929
 
921
930
  def convert_ol(el, indent, opts)
931
+ if @options[:ol_start_at_first_marker] and (first_list_marker =
932
+ el.options[:first_list_marker])
933
+ el.attr['start'] ||= first_list_marker[/\d+/]
934
+ end
922
935
  nested_types = opts[:nested_ol_types] || ["1"]
923
936
  # warn "** ol opts #{opts.inspect} types #{nested_types.inspect}"
924
937
  if nested_attr = el.attr.delete('nestedOlTypes')
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.7.10
4
+ version: 1.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-21 00:00:00.000000000 Z
11
+ date: 2024-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -147,6 +147,7 @@ executables:
147
147
  - echars
148
148
  - kramdown-rfc-extract-markdown
149
149
  - kramdown-rfc-extract-sourcecode
150
+ - kramdown-rfc-lsr
150
151
  - kdrfc
151
152
  - kramdown-rfc-cache-i-d-bibxml
152
153
  - kramdown-rfc-cache-subseries-bibxml
@@ -169,6 +170,7 @@ files:
169
170
  - bin/kramdown-rfc-clean-svg-ids
170
171
  - bin/kramdown-rfc-extract-markdown
171
172
  - bin/kramdown-rfc-extract-sourcecode
173
+ - bin/kramdown-rfc-lsr
172
174
  - bin/kramdown-rfc2629
173
175
  - data/encoding-fallbacks.txt
174
176
  - data/kramdown-rfc2629.erb
@@ -206,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
208
  - !ruby/object:Gem::Version
207
209
  version: '0'
208
210
  requirements: []
209
- rubygems_version: 3.5.4
211
+ rubygems_version: 3.5.9
210
212
  signing_key:
211
213
  specification_version: 4
212
214
  summary: Kramdown extension for generating RFCXML (RFC 799x).