kramdown-rfc2629 0.13.2 → 0.13.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/bin/kramdown-rfc2629 +100 -27
- data/data/kramdown-rfc2629.erb +7 -12
- data/kramdown-rfc2629.gemspec +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -48,6 +48,8 @@ supported by kramdown-rfc2629. The document metadata are in a short
|
|
48
48
|
piece of YAML at the start, and from there, `abstract`, `middle`,
|
49
49
|
references (`normative` and `informative`) and `back` are sections
|
50
50
|
delimited in the markdown file. See the example for how this works.
|
51
|
+
The sections `normative` and `informative` can be populated right from
|
52
|
+
the metadata, so there is never a need to write XML any more.
|
51
53
|
Much less scary, and no `{:/nomarkdown}` etc. is needed any more.
|
52
54
|
Similarly, `stupid-s.xml` and `stupid-s.txt` show what
|
53
55
|
kramdown-rfc2629 and xml2rfc make out of this.
|
data/bin/kramdown-rfc2629
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
require 'kramdown-rfc2629'
|
4
4
|
require 'yaml'
|
5
|
-
require 'pp'
|
6
5
|
require 'erb'
|
7
|
-
require 'ostruct'
|
8
6
|
require 'date'
|
9
7
|
|
10
8
|
Encoding.default_external = "UTF-8" # wake up, smell the coffee
|
@@ -12,40 +10,90 @@ Encoding.default_external = "UTF-8" # wake up, smell the coffee
|
|
12
10
|
RE_NL = /(?:\n|\r|\r\n)/
|
13
11
|
RE_SECTION = /---(?:\s+(\w+)(-?))?\s*#{RE_NL}(.*?#{RE_NL})(?=---(?:\s+\w+-?)?\s*#{RE_NL}|\Z)/m
|
14
12
|
|
13
|
+
NMDTAGS = ["{:/nomarkdown}\n\n", "\n{::nomarkdown}\n"]
|
14
|
+
|
15
15
|
def xml_from_sections(input)
|
16
|
-
sections = input.scan(RE_SECTION)
|
16
|
+
sections = input.scan(RE_SECTION)
|
17
|
+
# resulting in an array; each section is [section-label, nomarkdown-flag, section-text]
|
17
18
|
|
18
|
-
|
19
|
+
# the first section is a YAML with front matter parameters (don't put a label here)
|
20
|
+
ps = ParameterSet.new(YAML.load(sections.shift[2]))
|
19
21
|
coding_override = (ps.has(:coding) =~ /ascii/i) ? :symbolic : :as_char
|
20
22
|
|
23
|
+
# all the other sections are put in a Hash, possibly concatenated from parts there
|
21
24
|
sechash = Hash.new{ |h,k| h[k] = ""}
|
22
|
-
snames = []
|
25
|
+
snames = [] # a stack of section names
|
23
26
|
sections.each do |sname, nmdflag, text|
|
24
27
|
nmdin, nmdout = {
|
25
|
-
"-" => ["", ""],
|
26
|
-
"" =>
|
28
|
+
"-" => ["", ""], # stay in nomarkdown
|
29
|
+
"" => NMDTAGS, # pop out temporarily
|
27
30
|
}[nmdflag || ""]
|
28
31
|
if sname
|
29
|
-
snames << sname # --- label -> push label
|
32
|
+
snames << sname # "--- label" -> push label (now current)
|
30
33
|
else
|
31
|
-
snames.pop # --- -> pop label
|
34
|
+
snames.pop # just "---" -> pop label (previous now current)
|
32
35
|
end
|
33
36
|
sechash[snames.last] << "#{nmdin}#{text}#{nmdout}"
|
34
37
|
end
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
stand_alone = ps[:stand_alone]
|
40
|
+
|
41
|
+
[:normative, :informative].each do |sn|
|
42
|
+
if refs = ps[sn]
|
43
|
+
refs.each do |k, v|
|
44
|
+
if bts = bibtagsys(k)
|
45
|
+
warn "*** redundant in #{k}: #{v.inspect}" if v
|
46
|
+
if stand_alone
|
47
|
+
sechash[sn.to_s] << %{\n#{NMDTAGS[0]}\n![:include:](#{bts[0]})\n#{NMDTAGS[1]}\n}
|
48
|
+
else
|
49
|
+
(ps.rest["bibxml"] ||= []) << k
|
50
|
+
sechash[sn.to_s] << %{&#{bts[0]};\n}
|
51
|
+
end
|
52
|
+
else
|
53
|
+
vps = ParameterSet.new(v)
|
54
|
+
erb = ERB.new <<-REFERB
|
55
|
+
<reference anchor="<%= k %>" <%= vps.attr("target") %>>
|
56
|
+
<front>
|
57
|
+
<%= vps.ele("title") %>
|
58
|
+
|
59
|
+
<% vps.arr("author") do |au|
|
60
|
+
aups = authorps_from_hash(au)
|
61
|
+
%>
|
62
|
+
<author <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
|
63
|
+
<%= aups.ele("organization=org", aups.attr("abbrev=orgabbrev"), "") %>
|
64
|
+
</author>
|
65
|
+
<% aups.warn_if_leftovers %>
|
66
|
+
<% end %>
|
67
|
+
|
68
|
+
<% if date = vps[:date] %>
|
69
|
+
<date <%= dateattrs(date) %>/>
|
70
|
+
<% end %>
|
71
|
+
</front>
|
72
|
+
</reference>
|
73
|
+
REFERB
|
74
|
+
sechash[sn.to_s] << erb.result(binding)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
erbfilename = File.expand_path '../../data/kramdown-rfc2629.erb', __FILE__
|
81
|
+
erbfile = File.read(erbfilename, coding: "UTF-8")
|
82
|
+
erb = ERB.new(erbfile)
|
83
|
+
# remove redundant nomarkdown pop outs/pop ins as they confuse kramdown
|
84
|
+
input = erb.result(binding).gsub(%r"{::nomarkdown}\s*{:/nomarkdown}"m, "")
|
39
85
|
ps.warn_if_leftovers
|
40
|
-
sechash.delete("fluff")
|
41
|
-
if !sechash.empty?
|
86
|
+
sechash.delete("fluff") # fluff is a "commented out" section
|
87
|
+
if !sechash.empty? # any sections unused by the ERb file?
|
42
88
|
warn "*** sections left #{sechash.keys.inspect}!"
|
43
89
|
end
|
44
90
|
|
45
|
-
[input
|
91
|
+
[input, coding_override]
|
46
92
|
end
|
47
93
|
|
48
94
|
class ParameterSet
|
95
|
+
include Kramdown::Utils::Html
|
96
|
+
|
49
97
|
attr_reader :f
|
50
98
|
def initialize(y)
|
51
99
|
@f = y
|
@@ -66,19 +114,19 @@ class ParameterSet
|
|
66
114
|
%{#{an}="#{val}"} if val
|
67
115
|
end
|
68
116
|
def attrs(*pns)
|
69
|
-
pns.map{ |pn| attr(pn) }.join(" ")
|
117
|
+
pns.map{ |pn| attr(pn) }.compact.join(" ")
|
70
118
|
end
|
71
|
-
def ele(pn, attr=nil)
|
119
|
+
def ele(pn, attr=nil, defcontent=nil)
|
72
120
|
val, an = van(pn)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end.join(" ")
|
78
|
-
end
|
121
|
+
val ||= defcontent
|
122
|
+
Array(val).map do |val1|
|
123
|
+
%{<#{[an, *Array(attr).map(&:to_s)].join(" ").strip}>#{escape_html(val1.to_s)}</#{an}>}
|
124
|
+
end.join(" ")
|
79
125
|
end
|
80
|
-
def arr(an, &block)
|
81
|
-
|
126
|
+
def arr(an, converthash=true, &block)
|
127
|
+
arr = self[an] || []
|
128
|
+
arr = [arr] if Hash === arr && converthash
|
129
|
+
Array(arr).each(&block)
|
82
130
|
end
|
83
131
|
def rest
|
84
132
|
@f
|
@@ -95,12 +143,37 @@ def bibtagsys(bib)
|
|
95
143
|
rfc4d = "%04d" % $1.to_i
|
96
144
|
[bib.upcase,
|
97
145
|
"http://xml.resource.org/public/rfc/bibxml/reference.RFC.#{rfc4d}.xml"]
|
98
|
-
|
146
|
+
elsif bib =~ /\AI-D\./i
|
99
147
|
[bib,
|
100
148
|
"http://xml.resource.org/public/rfc/bibxml3/reference.#{bib}.xml"]
|
101
149
|
end
|
102
150
|
end
|
103
151
|
|
152
|
+
def authorps_from_hash(au)
|
153
|
+
aups = ParameterSet.new(au)
|
154
|
+
if ins = aups[:ins]
|
155
|
+
parts = ins.split('.').map(&:strip)
|
156
|
+
aups.rest["initials"] = parts[0..-2].join('.') << '.'
|
157
|
+
aups.rest["surname"] = parts[-1]
|
158
|
+
end
|
159
|
+
aups
|
160
|
+
end
|
161
|
+
|
162
|
+
def dateattrs(date)
|
163
|
+
begin
|
164
|
+
case date
|
165
|
+
when Integer
|
166
|
+
%{year="#{"%04d" % date}"}
|
167
|
+
when String
|
168
|
+
Date.parse("#{date}-01").strftime(%{year="%Y" month="%B"})
|
169
|
+
when Date
|
170
|
+
date.strftime(%{year="%Y" month="%B" day="%d"})
|
171
|
+
end
|
172
|
+
|
173
|
+
rescue ArgumentError
|
174
|
+
warn "*** Invalid date: #{date} -- use 2012, 2012-07, or 2012-07-28"
|
175
|
+
end
|
176
|
+
end
|
104
177
|
|
105
178
|
coding_override = :as_char
|
106
179
|
input = ARGF.read.gsub(/\{::include\s+(.*?)\}/) {
|
@@ -113,7 +186,7 @@ if input =~ /\A<\?xml/ # if this is a whole XML file, protect it
|
|
113
186
|
input = "{::nomarkdown}\n#{input}\n{:/nomarkdown}\n"
|
114
187
|
end
|
115
188
|
options = {input: 'RFC2629Kramdown', entity_output: coding_override}
|
116
|
-
warn "options: #{options.inspect}"
|
189
|
+
# warn "options: #{options.inspect}"
|
117
190
|
doc = Kramdown::Document.new(input, options)
|
118
191
|
$stderr.puts doc.warnings.to_yaml unless doc.warnings.empty?
|
119
192
|
puts doc.to_rfc2629
|
data/data/kramdown-rfc2629.erb
CHANGED
@@ -6,32 +6,27 @@
|
|
6
6
|
tag, sys = bibtagsys(bib) %>
|
7
7
|
<!ENTITY <%= tag %> SYSTEM "<%= sys %>">
|
8
8
|
<% end %>
|
9
|
-
<% ps.arr("entity") do |en, ev| %>
|
9
|
+
<% ps.arr("entity", false) do |en, ev| %>
|
10
10
|
<!ENTITY <%=en%> "<%=ev%>">
|
11
11
|
<% end %>
|
12
12
|
]>
|
13
13
|
|
14
14
|
<rfc <%= ps.attrs("ipr", "docName=docname", "category=cat",
|
15
|
-
"number", "obsoletes", "updates", "seriesNo=seriesno")
|
15
|
+
"number", "obsoletes", "updates", "seriesNo=seriesno") %>>
|
16
16
|
|
17
|
-
<% ps.arr("pi") do |pi| %>
|
18
|
-
<?rfc <%=pi%>="yes"?>
|
17
|
+
<% ps.arr("pi", false) do |pi, val| %>
|
18
|
+
<?rfc <%=pi%>="<%= {true => "yes", false => "no", nil => "yes"}[val] || val %>"?>
|
19
19
|
<% end %>
|
20
20
|
|
21
21
|
<front>
|
22
22
|
<%= ps.ele("title", ps.attr("abbrev=titleabbrev")) %>
|
23
23
|
|
24
24
|
<% ps.arr("author") do |au|
|
25
|
-
aups =
|
26
|
-
if ins = aups[:ins]
|
27
|
-
parts = ins.split('.').map(&:strip)
|
28
|
-
aups.rest["initials"] = parts[0..-2].join('.') << '.'
|
29
|
-
aups.rest["surname"] = parts[-1]
|
30
|
-
end
|
25
|
+
aups = authorps_from_hash(au)
|
31
26
|
%>
|
32
27
|
|
33
28
|
<author <%=aups.attrs("initials", "surname", "fullname=name", "role")%>>
|
34
|
-
<%= aups.ele("organization=org", aups.attr("abbrev=orgabbrev")) %>
|
29
|
+
<%= aups.ele("organization=org", aups.attr("abbrev=orgabbrev"), "") %>
|
35
30
|
<address>
|
36
31
|
<% if aups.has("street") %>
|
37
32
|
<postal>
|
@@ -52,7 +47,7 @@
|
|
52
47
|
<% aups.warn_if_leftovers %>
|
53
48
|
<% end %>
|
54
49
|
|
55
|
-
<date <%= (ps[:date]||Date.today)
|
50
|
+
<date <%= dateattrs(ps[:date]||Date.today) %>/>
|
56
51
|
|
57
52
|
<%= ps.ele("area") %>
|
58
53
|
<%= ps.ele("workgroup=wg") %>
|
data/kramdown-rfc2629.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'kramdown-rfc2629'
|
3
|
-
s.version = '0.13.
|
3
|
+
s.version = '0.13.3'
|
4
4
|
s.summary = "Kramdown extension for generating RFC 2629 XML."
|
5
5
|
s.description = %{An RFC2629 (XML2RFC) generating backend for Thomas Leitner's
|
6
6
|
"kramdown" markdown parser. Mostly useful for RFC writers.}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown-rfc2629
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: kramdown
|
16
|
-
requirement: &
|
16
|
+
requirement: &70123750840660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0.13'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70123750840660
|
25
25
|
description: ! 'An RFC2629 (XML2RFC) generating backend for Thomas Leitner''s
|
26
26
|
|
27
27
|
"kramdown" markdown parser. Mostly useful for RFC writers.'
|