kramdown-rfc2629 1.4.18 → 1.5.3

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: f351fb251c634da227a9ce9202094ee20ac11689be7b2144f118ba07aa2b31fb
4
- data.tar.gz: 45d0559f1f6c6ff2c4ba18bab26a4e88bec8faad622cf0b9183c144eb419441f
3
+ metadata.gz: aca914cd77e805824fc1d15d642e3f0e453f12e5ffe0ee17f56b0a497b047382
4
+ data.tar.gz: df4c1b4c6d73a796183ba2bf8503ff8b7b943025fd61842767250de4107b27be
5
5
  SHA512:
6
- metadata.gz: 2d3acf198070f8d7b69995f9f581302a6d20bbb24241350a169ef8cc5ccfeb49d191adfaaa11442df5859534812761d91c7f7c5a8b22b5a2aec19c8d2a02e48b
7
- data.tar.gz: b1c5d6d9c968d82a453bcdfcc234e1dc4f3844ba9084942f73fd5212258d0d1e361f55fc1cb36910b58a4c2e68286cfe20695cf8d6d1c9e538a9907164d89d71
6
+ metadata.gz: 5219932525720483e742f5c0e0bb90957c1766c9a019c76491b45b05351e3a864be4ff69bebff5ec942dfb39a090c4b0fbf7f6b4b502f4f526105b46b03c00ca
7
+ data.tar.gz: eb2d6d95a67cb80ca52ba46eb299d6edb4a11d9e760c09c36377372876b8c99cfcfd36b6e6461a47797d7e15bd85c3ce1f9e00aa8317a1140361cfea7658cfee
data/README.md CHANGED
@@ -562,7 +562,7 @@ remaining 20 % some more, but that hasn't been done.
562
562
 
563
563
  If you have XML, there is an experimental upconverter that does 99 %
564
564
  of the work. Please [contact the
565
- 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
566
566
  to try it.
567
567
 
568
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)."
@@ -69,6 +69,17 @@
69
69
 
70
70
  <middle>
71
71
 
72
+ {:/nomarkdown}
73
+ {:quote: gi="blockquote"}
74
+ {:aside: gi="aside"}
75
+ {:markers: sourcecode-markers="true"}
76
+ {:unnumbered: numbered="false"}
77
+ {:vspace: vspace="0"}
78
+ {:removeinrfc: removeinrfc="true"}
79
+ {:notoc: toc="exclude"}
80
+ {:compact: spacing="compact"}
81
+ {::nomarkdown}
82
+
72
83
  <%= sechash.delete("middle") %>
73
84
 
74
85
  </middle>
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'kramdown-rfc2629'
3
- s.version = '1.4.18'
3
+ s.version = '1.5.3'
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| -%>
@@ -53,6 +53,9 @@ module Kramdown
53
53
 
54
54
  def self.idref_cleanup(href)
55
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
56
59
  href.gsub(/\A(?:[0-9]|section-|u-|figure-|table-|iref-)/) { "_#{$&}" }
57
60
  end
58
61
 
@@ -125,7 +128,7 @@ module Kramdown
125
128
  when /\A(.*) \((#{SECTIONS_RE})\)\z/
126
129
  href = $1
127
130
  handle_bares($2, attr, "parens", href)
128
- when /\A([\w.]+)<(.+)\z/
131
+ when /\A(#{XREF_BASE})<(.+)\z/
129
132
  href = $2
130
133
  attr['section'] = $1
131
134
  attr['sectionFormat'] = 'bare'
@@ -545,8 +548,17 @@ COLORS
545
548
 
546
549
  def convert_blockquote(el, indent, opts)
547
550
  text = inner(el, indent, opts)
551
+ if $options.v3
552
+ gi = el.attr.delete('gi')
553
+ if gi && gi != 'ul'
554
+ "#{' '*indent}<#{gi}#{el_html_attributes(el)}>\n#{text}#{' '*indent}</#{gi}>\n"
555
+ else
556
+ "#{' '*indent}<ul#{el_html_attributes_with(el, {"empty" => 'true'})}><li>\n#{text}#{' '*indent}</li></ul>\n"
557
+ end
558
+ else
548
559
  text = "<t></t>" unless text =~ /</ # empty block quote
549
560
  "#{' '*indent}<t><list style='empty'#{el_html_attributes(el)}>\n#{text}#{' '*indent}</list></t>\n"
561
+ end
550
562
  end
551
563
 
552
564
  def end_sections(to_level, indent)
@@ -1032,18 +1044,30 @@ COLORS
1032
1044
  # this would be more like xml2rfc v3:
1033
1045
  # "\n#{' '*indent}<cref>\n#{inner(el.value, indent, opts).rstrip}\n#{' '*indent}</cref>"
1034
1046
  content = inner(el.value, indent, opts).strip
1035
- content = escape_html(content.sub(/\A<t>(.*)<\/t>\z/m) {$1}, :text) # text only...
1047
+ content = content.sub(/\A<t>(.*)<\/t>\z/m) {$1}
1036
1048
  name = ::Kramdown::Parser::RFC2629Kramdown.idref_cleanup(el.options[:name])
1049
+ o_name = name.dup
1037
1050
  while @footnote_names_in_use[name] do
1038
- if name =~ /:\d+\z/
1051
+ if name =~ /_\d+\z/
1039
1052
  name.succ!
1040
1053
  else
1041
- name << ":1"
1054
+ name << "_1"
1042
1055
  end
1043
1056
  end
1044
1057
  @footnote_names_in_use[name] = true
1045
1058
  attrstring = el_html_attributes_with(el, {"anchor" => name})
1046
- "\n#{' '*indent}<cref#{attrstring}>#{content}</cref>"
1059
+ if $options.v3
1060
+ if o_name[-1] == "-"
1061
+ # Ignore HTML attributes. Hmm.
1062
+ content
1063
+ else
1064
+ # do not indent span-level so we can stick to previous word. Good?
1065
+ "<cref#{attrstring}>#{content}</cref>"
1066
+ end
1067
+ else
1068
+ content = escape_html(content, :text) # text only...
1069
+ "\n#{' '*indent}<cref#{attrstring}>#{content}</cref>"
1070
+ end
1047
1071
  end
1048
1072
 
1049
1073
  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.18
4
+ version: 1.5.3
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-28 00:00:00.000000000 Z
11
+ date: 2021-07-23 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.