asciidoctor-rfc 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.oss-guides.rubocop.yml +1077 -0
- data/.rspec +1 -0
- data/.rubocop.yml +19 -1063
- data/.travis.yml +3 -2
- data/Guardfile +22 -0
- data/README.adoc +1151 -0
- data/Rakefile +1 -1
- data/asciidoctor-rfc.gemspec +20 -3
- data/bin/asciidoctor-rfc2 +15 -0
- data/bin/asciidoctor-rfc3 +15 -0
- data/bin/rspec +0 -1
- data/lib/asciidoctor-rfc.rb +4 -0
- data/lib/asciidoctor/rfc/common/base.rb +218 -0
- data/lib/asciidoctor/rfc/common/front.rb +120 -0
- data/lib/asciidoctor/rfc/v2/base.rb +341 -0
- data/lib/asciidoctor/rfc/v2/blocks.rb +192 -0
- data/lib/asciidoctor/rfc/v2/converter.rb +64 -0
- data/lib/asciidoctor/rfc/v2/front.rb +69 -0
- data/lib/asciidoctor/rfc/v2/inline_anchor.rb +102 -0
- data/lib/asciidoctor/rfc/v2/lists.rb +134 -0
- data/lib/asciidoctor/rfc/v2/table.rb +112 -0
- data/lib/asciidoctor/rfc/v2/validate.rb +738 -0
- data/lib/asciidoctor/rfc/v2/validate2.rng +716 -0
- data/lib/asciidoctor/rfc/v3/base.rb +358 -0
- data/lib/asciidoctor/rfc/v3/blocks.rb +203 -0
- data/lib/asciidoctor/rfc/v3/converter.rb +64 -0
- data/lib/asciidoctor/rfc/v3/front.rb +115 -0
- data/lib/asciidoctor/rfc/v3/inline_anchor.rb +90 -0
- data/lib/asciidoctor/rfc/v3/lists.rb +190 -0
- data/lib/asciidoctor/rfc/v3/svg.rng +9081 -0
- data/lib/asciidoctor/rfc/v3/table.rb +65 -0
- data/lib/asciidoctor/rfc/v3/validate.rb +2168 -0
- data/lib/asciidoctor/rfc/v3/validate.rng +2143 -0
- data/lib/asciidoctor/rfc/version.rb +2 -2
- data/spec/asciidoctor/rfc/v2/appendix_spec.rb +124 -0
- data/spec/asciidoctor/rfc/v2/area_spec.rb +60 -0
- data/spec/asciidoctor/rfc/v2/author_spec.rb +444 -0
- data/spec/asciidoctor/rfc/v2/comments_spec.rb +316 -0
- data/spec/asciidoctor/rfc/v2/crossref_spec.rb +205 -0
- data/spec/asciidoctor/rfc/v2/date_spec.rb +166 -0
- data/spec/asciidoctor/rfc/v2/dlist_spec.rb +108 -0
- data/spec/asciidoctor/rfc/v2/document_spec.rb +161 -0
- data/spec/asciidoctor/rfc/v2/example_spec.rb +50 -0
- data/spec/asciidoctor/rfc/v2/front_spec.rb +75 -0
- data/spec/asciidoctor/rfc/v2/image_spec.rb +81 -0
- data/spec/asciidoctor/rfc/v2/indexterm_spec.rb +66 -0
- data/spec/asciidoctor/rfc/v2/inline_formatting_spec.rb +177 -0
- data/spec/asciidoctor/rfc/v2/keyword_spec.rb +63 -0
- data/spec/asciidoctor/rfc/v2/listing_spec.rb +59 -0
- data/spec/asciidoctor/rfc/v2/literal_spec.rb +53 -0
- data/spec/asciidoctor/rfc/v2/olist_spec.rb +147 -0
- data/spec/asciidoctor/rfc/v2/paragraph_spec.rb +68 -0
- data/spec/asciidoctor/rfc/v2/preamble_spec.rb +140 -0
- data/spec/asciidoctor/rfc/v2/quote_spec.rb +24 -0
- data/spec/asciidoctor/rfc/v2/references_spec.rb +96 -0
- data/spec/asciidoctor/rfc/v2/section_spec.rb +260 -0
- data/spec/asciidoctor/rfc/v2/sidebar_spec.rb +32 -0
- data/spec/asciidoctor/rfc/v2/table_spec.rb +293 -0
- data/spec/asciidoctor/rfc/v2/ulist_spec.rb +96 -0
- data/spec/asciidoctor/rfc/v2/workgroup_spec.rb +60 -0
- data/spec/asciidoctor/rfc/v3/appendix_spec.rb +130 -0
- data/spec/asciidoctor/rfc/v3/area_spec.rb +63 -0
- data/spec/asciidoctor/rfc/v3/author_spec.rb +540 -0
- data/spec/asciidoctor/rfc/v3/comments_spec.rb +308 -0
- data/spec/asciidoctor/rfc/v3/crossref_spec.rb +269 -0
- data/spec/asciidoctor/rfc/v3/date_spec.rb +149 -0
- data/spec/asciidoctor/rfc/v3/dlist_spec.rb +121 -0
- data/spec/asciidoctor/rfc/v3/document_spec.rb +109 -0
- data/spec/asciidoctor/rfc/v3/example_spec.rb +34 -0
- data/spec/asciidoctor/rfc/v3/front_spec.rb +43 -0
- data/spec/asciidoctor/rfc/v3/image_spec.rb +81 -0
- data/spec/asciidoctor/rfc/v3/indexterm_spec.rb +69 -0
- data/spec/asciidoctor/rfc/v3/inline_formatting_spec.rb +319 -0
- data/spec/asciidoctor/rfc/v3/keyword_spec.rb +33 -0
- data/spec/asciidoctor/rfc/v3/link_spec.rb +34 -0
- data/spec/asciidoctor/rfc/v3/listing_spec.rb +59 -0
- data/spec/asciidoctor/rfc/v3/literal_spec.rb +51 -0
- data/spec/asciidoctor/rfc/v3/olist_spec.rb +168 -0
- data/spec/asciidoctor/rfc/v3/paragraph_spec.rb +73 -0
- data/spec/asciidoctor/rfc/v3/preamble_spec.rb +112 -0
- data/spec/asciidoctor/rfc/v3/quote_spec.rb +91 -0
- data/spec/asciidoctor/rfc/v3/references_spec.rb +147 -0
- data/spec/asciidoctor/rfc/v3/section_spec.rb +198 -0
- data/spec/asciidoctor/rfc/v3/series_info_spec.rb +151 -0
- data/spec/asciidoctor/rfc/v3/sidebar_spec.rb +30 -0
- data/spec/asciidoctor/rfc/v3/table_spec.rb +275 -0
- data/spec/asciidoctor/rfc/v3/ulist_spec.rb +74 -0
- data/spec/asciidoctor/rfc/v3/workgroup_spec.rb +33 -0
- data/spec/examples/davies-template-bare-06.adoc +361 -0
- data/spec/examples/davies-template-bare-06.xml.orig +426 -0
- data/spec/examples/example-v2.adoc +181 -0
- data/spec/examples/example-v2.xml +675 -0
- data/spec/examples/example-v3.adoc +185 -0
- data/spec/examples/example-v3.xml +1009 -0
- data/spec/examples/mib-doc-template-xml-06.adoc +596 -0
- data/spec/examples/mib-doc-template-xml-06.xml.orig +654 -0
- data/spec/examples/rfc1149.md +76 -0
- data/spec/examples/rfc1149.md.2.xml +94 -0
- data/spec/examples/rfc1149.md.3.xml +93 -0
- data/spec/examples/rfc1149.md.adoc +65 -0
- data/spec/examples/rfc2100.md +149 -0
- data/spec/examples/rfc2100.md.2.xml +169 -0
- data/spec/examples/rfc2100.md.3.xml +163 -0
- data/spec/examples/rfc2100.md.adoc +136 -0
- data/spec/examples/rfc3514.md +203 -0
- data/spec/examples/rfc3514.md.2.xml +238 -0
- data/spec/examples/rfc3514.md.3.xml +258 -0
- data/spec/examples/rfc3514.md.adoc +324 -0
- data/spec/examples/rfc5841.md +342 -0
- data/spec/examples/rfc5841.md.2.xml +393 -0
- data/spec/examples/rfc5841.md.3.xml +449 -0
- data/spec/examples/rfc5841.md.adoc +414 -0
- data/spec/examples/rfc6350.adoc +3499 -0
- data/spec/examples/rfc6350.bib +763 -0
- data/spec/examples/rfc748.md +79 -0
- data/spec/examples/rfc748.md.2.xml +116 -0
- data/spec/examples/rfc748.md.3.xml +109 -0
- data/spec/examples/rfc748.md.adoc +80 -0
- data/spec/examples/rfc7511.md +257 -0
- data/spec/examples/rfc7511.md.2.xml +300 -0
- data/spec/examples/rfc7511.md.3.xml +347 -0
- data/spec/examples/rfc7511.md.adoc +417 -0
- data/spec/spec_helper.rb +115 -5
- metadata +274 -9
- data/.hound.yml +0 -3
- data/README.md +0 -84
- data/lib/asciidoctor/rfc.rb +0 -7
- data/spec/asciidoctor-rfc/.keep +0 -0
@@ -0,0 +1,358 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module RFC::V3
|
3
|
+
module Base
|
4
|
+
# Syntax:
|
5
|
+
# =Title
|
6
|
+
# Author
|
7
|
+
# :ipr
|
8
|
+
# :obsoletes
|
9
|
+
# :updates
|
10
|
+
# :submissionType
|
11
|
+
# :indexInclude
|
12
|
+
# :iprExtract
|
13
|
+
# :sortRefs
|
14
|
+
# :symRefs
|
15
|
+
# :tocInclude
|
16
|
+
# :tocDepth
|
17
|
+
#
|
18
|
+
# ABSTRACT
|
19
|
+
#
|
20
|
+
# NOTEs
|
21
|
+
#
|
22
|
+
# ==first title
|
23
|
+
# CONTENT
|
24
|
+
#
|
25
|
+
# [bibliography] # start of back matter
|
26
|
+
# == Bibliography
|
27
|
+
#
|
28
|
+
# [appendix] # start of back matter if not already started
|
29
|
+
# == Appendix
|
30
|
+
def document(node)
|
31
|
+
$seen_back_matter = false
|
32
|
+
$seen_abstract = false
|
33
|
+
# If this is present, then BCP14 keywords in boldface are not assumed to be <bcp14> tags. By default they are.
|
34
|
+
$bcp_bold = !(node.attr? "no-rfc-bold-bcp14")
|
35
|
+
$smart_quotes = (node.attr("smart-quotes") != "false")
|
36
|
+
result = []
|
37
|
+
result << '<?xml version="1.0" encoding="UTF-8"?>'
|
38
|
+
|
39
|
+
t = Time.now.getutc
|
40
|
+
preptime = sprintf(
|
41
|
+
"%04d-%02d-%02dT%02d:%02d:%02dZ",
|
42
|
+
t.year, t.month, t.day, t.hour, t.min, t.sec
|
43
|
+
)
|
44
|
+
|
45
|
+
rfc_attributes = {
|
46
|
+
ipr: node.attr("ipr"),
|
47
|
+
obsoletes: node.attr("obsoletes"),
|
48
|
+
updates: node.attr("updates"),
|
49
|
+
indexInclude: node.attr("index-include"),
|
50
|
+
iprExtract: node.attr("ipr-extract"),
|
51
|
+
sortRefs: node.attr("sort-refs"),
|
52
|
+
symRefs: node.attr("sym-refs"),
|
53
|
+
tocInclude: node.attr("toc-include"),
|
54
|
+
tocDepth: node.attr("toc-depth"),
|
55
|
+
submissionType: node.attr("submission-type") || "IETF",
|
56
|
+
'xml:lang': node.attr("xml-lang"),
|
57
|
+
prepTime: preptime,
|
58
|
+
version: "3",
|
59
|
+
}
|
60
|
+
|
61
|
+
rfc_open = noko { |xml| xml.rfc **attr_code(rfc_attributes) }.join.gsub(/\/>$/, ">")
|
62
|
+
result << rfc_open
|
63
|
+
|
64
|
+
result << (link node)
|
65
|
+
|
66
|
+
result << noko { |xml| front node, xml }
|
67
|
+
result.last.last.gsub! /<\/front>$/, "" # FIXME: this is a hack!
|
68
|
+
result << "</front><middle1>"
|
69
|
+
|
70
|
+
result << node.content if node.blocks?
|
71
|
+
result << ($seen_back_matter ? "</back>" : "</middle>")
|
72
|
+
result << "</rfc>"
|
73
|
+
|
74
|
+
# <middle> needs to move after preamble
|
75
|
+
result = result.flatten
|
76
|
+
result = if result.any? { |e| e =~ /<\/front><middle>/ } && result.any? { |e| e =~ /<\/front><middle1>/ }
|
77
|
+
result.reject { |e| e =~ /<\/front><middle1>/ }
|
78
|
+
else
|
79
|
+
result.map { |e| e =~ /<\/front><middle1>/ ? "</front><middle>" : e }
|
80
|
+
end
|
81
|
+
ret = result * "\n"
|
82
|
+
ret = set_pis(node, Nokogiri::XML(ret)).to_xml
|
83
|
+
ret = cleanup ret
|
84
|
+
Validate::validate(ret)
|
85
|
+
ret
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_pis(node, doc)
|
89
|
+
# Below are generally applicable Processing Instructions (PIs)
|
90
|
+
# that most I-Ds might want to use. (Here they are set differently than
|
91
|
+
# their defaults in xml2rfc v1.32)
|
92
|
+
rfc_pis = {
|
93
|
+
# give errors regarding ID-nits and DTD validation
|
94
|
+
strict: "yes",
|
95
|
+
|
96
|
+
# TOC control
|
97
|
+
# generate a ToC
|
98
|
+
toc: node.attr("toc-include") == "false" ? "no" : "yes",
|
99
|
+
|
100
|
+
# the number of levels of subsections in ToC. default: 3
|
101
|
+
tocdepth: node.attr("toc-depth") || "4",
|
102
|
+
|
103
|
+
# References control
|
104
|
+
|
105
|
+
# use symbolic references tags, i.e, [RFC2119] instead of [1]
|
106
|
+
symrefs: node.attr("sym-refs"),
|
107
|
+
|
108
|
+
# sort the reference entries alphabetically
|
109
|
+
sortrefs: node.attr("sort-refs"),
|
110
|
+
|
111
|
+
# Vertical whitespace control
|
112
|
+
# (using these PIs as follows is recommended by the RFC Editor)
|
113
|
+
|
114
|
+
# do not start each main section on a new page
|
115
|
+
compact: "yes",
|
116
|
+
|
117
|
+
# keep one blank line between list items
|
118
|
+
subcompact: "no",
|
119
|
+
}
|
120
|
+
|
121
|
+
doc.create_internal_subset("rfc", nil, "rfc2629.dtd")
|
122
|
+
rfc_pis.each_pair do |k, v|
|
123
|
+
pi = Nokogiri::XML::ProcessingInstruction.new(doc,
|
124
|
+
"rfc",
|
125
|
+
"#{k}=\"#{v}\"")
|
126
|
+
doc.root.add_previous_sibling(pi)
|
127
|
+
end
|
128
|
+
|
129
|
+
doc
|
130
|
+
end
|
131
|
+
|
132
|
+
# Syntax:
|
133
|
+
# = Title
|
134
|
+
# Author
|
135
|
+
# :link href,href rel
|
136
|
+
def link(node)
|
137
|
+
result = []
|
138
|
+
result << noko do |xml|
|
139
|
+
links = (node.attr("link") || "").split(/,/)
|
140
|
+
links.each do |link|
|
141
|
+
matched = /^(?<href>\S+)\s+(?<rel>\S+)$/.match link
|
142
|
+
link_attributes = {
|
143
|
+
href: matched.nil? ? link : matched[:href],
|
144
|
+
rel: matched.nil? ? nil : matched[:rel],
|
145
|
+
}
|
146
|
+
xml.link **attr_code(link_attributes)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
result
|
150
|
+
end
|
151
|
+
|
152
|
+
def inline_break(node)
|
153
|
+
# <br> is only defined within tables
|
154
|
+
noko do |xml|
|
155
|
+
xml << node.text
|
156
|
+
xml.br if node.parent.context == :cell
|
157
|
+
end.join
|
158
|
+
end
|
159
|
+
|
160
|
+
def inline_quoted(node)
|
161
|
+
noko do |xml|
|
162
|
+
case node.type
|
163
|
+
when :emphasis then xml.em node.text
|
164
|
+
when :strong
|
165
|
+
if $bcp_bold && node.text =~ /^(MUST|MUST NOT|REQUIRED|SHALL|SHALL NOT|SHOULD|SHOULD NOT|RECOMMENDED|MAY|OPTIONAL)$/
|
166
|
+
xml.bcp14 node.text
|
167
|
+
else
|
168
|
+
xml.strong node.text
|
169
|
+
end
|
170
|
+
when :monospaced then xml.tt node.text
|
171
|
+
when :double
|
172
|
+
xml << ($smart_quotes ? "“#{node.text}”" : "\"#{node.text}\"")
|
173
|
+
when :single
|
174
|
+
xml << ($smart_quotes ? "‘#{node.text}’" : "'#{node.text}'")
|
175
|
+
when :superscript then xml.sup node.text
|
176
|
+
when :subscript then xml.sub node.text
|
177
|
+
else
|
178
|
+
# [bcp14]#MUST NOT#
|
179
|
+
if node.role == "bcp14"
|
180
|
+
xml.bcp14 node.text.upcase
|
181
|
+
else
|
182
|
+
xml << node.text
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end.join
|
186
|
+
end
|
187
|
+
|
188
|
+
# Syntax:
|
189
|
+
# [[id]]
|
190
|
+
# [keepWithNext=true,keepWithPrevious=true] (optional)
|
191
|
+
# Text
|
192
|
+
def paragraph(node)
|
193
|
+
result = []
|
194
|
+
|
195
|
+
if (node.parent.context == :preamble) && !$seen_abstract
|
196
|
+
$seen_abstract = true
|
197
|
+
result << "<abstract>"
|
198
|
+
end
|
199
|
+
|
200
|
+
t_attributes = {
|
201
|
+
anchor: node.id,
|
202
|
+
keepWithNext: node.attr("keep-with-next"),
|
203
|
+
keepWithPrevious: node.attr("keep-with-previous"),
|
204
|
+
}
|
205
|
+
|
206
|
+
result << noko do |xml|
|
207
|
+
xml.t **attr_code(t_attributes) do |xml_t|
|
208
|
+
xml_t << node.content
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
result
|
213
|
+
end
|
214
|
+
|
215
|
+
# Syntax:
|
216
|
+
# :sectnums: (toggle)
|
217
|
+
# :sectnums!: (toggle)
|
218
|
+
# [[id]]
|
219
|
+
# [removeInRFC=true,toc=include|exclude|default] (optional)
|
220
|
+
# == title
|
221
|
+
# Content
|
222
|
+
#
|
223
|
+
# [[id]]
|
224
|
+
# [bibliography]
|
225
|
+
# == Normative|Informative References
|
226
|
+
# * [[[ref1]]] Ref [must provide references as list]
|
227
|
+
# * [[[ref2]]] Ref
|
228
|
+
def section(node)
|
229
|
+
result = []
|
230
|
+
if node.attr("style") == "bibliography"
|
231
|
+
$xreftext = {}
|
232
|
+
$processing_reflist = true
|
233
|
+
|
234
|
+
# references_attributes = {
|
235
|
+
# anchor: node.id,
|
236
|
+
# }.reject { |_, value| value.nil? }
|
237
|
+
|
238
|
+
# result << noko do |xml|
|
239
|
+
# xml.references **references_attributes do |references_xml|
|
240
|
+
# references_xml.name node.title unless node.title.nil?
|
241
|
+
# node.blocks.each { |b| references_xml << reflist(b).join }
|
242
|
+
# end
|
243
|
+
# end
|
244
|
+
|
245
|
+
anchor_attribute = node.id.nil? ? nil : " anchor=\"#{node.id}\""
|
246
|
+
result << "<references#{anchor_attribute}>"
|
247
|
+
result << "<name>#{node.title}</name>" unless node.title.nil?
|
248
|
+
# require that references be a :pass xml block
|
249
|
+
# potentially with an initial block of display reference equivalences
|
250
|
+
node.blocks.each do |b|
|
251
|
+
if b.context == :pass
|
252
|
+
result << reflist(b)
|
253
|
+
elsif b.context == :ulist
|
254
|
+
b.items.each do |i|
|
255
|
+
i.text # we only process the item for its displayreferences
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
result << "</references>"
|
260
|
+
|
261
|
+
unless $xreftext.empty?
|
262
|
+
result.unshift($xreftext.keys.map { |k| %(<displayreference target="#{k}" to="#{$xreftext[k]}"/>) })
|
263
|
+
end
|
264
|
+
result = result.unshift("</middle><back>") unless $seen_back_matter
|
265
|
+
$processing_reflist = false
|
266
|
+
$seen_back_matter = true
|
267
|
+
else
|
268
|
+
if node.attr("style") == "appendix"
|
269
|
+
result << "</middle><back>" unless $seen_back_matter
|
270
|
+
$seen_back_matter = true
|
271
|
+
end
|
272
|
+
|
273
|
+
section_attributes = {
|
274
|
+
anchor: node.id,
|
275
|
+
removeInRFC: node.attr("remove-in-rfc"),
|
276
|
+
toc: node.attr("toc"),
|
277
|
+
numbered: node.attr?("sectnums"),
|
278
|
+
}
|
279
|
+
|
280
|
+
result << noko do |xml|
|
281
|
+
xml.section **attr_code(section_attributes) do |section_xml|
|
282
|
+
section_xml.name { |name| name << node.title } unless node.title.nil?
|
283
|
+
section_xml << node.content
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
result
|
288
|
+
end
|
289
|
+
|
290
|
+
# Syntax:
|
291
|
+
# [[id]]
|
292
|
+
# .Name
|
293
|
+
# [link=xxx,align=left|center|right,alt=alt_text,type]
|
294
|
+
# image::filename[alt,width,height]
|
295
|
+
# @note ignoring width, height attributes
|
296
|
+
def image(node)
|
297
|
+
uri = node.image_uri node.attr("target")
|
298
|
+
artwork_attributes = {
|
299
|
+
align: node.attr("align"),
|
300
|
+
alt: node.alt,
|
301
|
+
anchor: node.id,
|
302
|
+
height: node.attr("height"),
|
303
|
+
name: node.title,
|
304
|
+
src: uri,
|
305
|
+
type: (uri =~ /\.svg$/ ? "svg" : "binary-art"),
|
306
|
+
width: node.attr("width"),
|
307
|
+
}
|
308
|
+
|
309
|
+
noko do |xml|
|
310
|
+
if node.parent.context != :example
|
311
|
+
xml.figure do |xml_figure|
|
312
|
+
xml_figure.artwork **attr_code(artwork_attributes)
|
313
|
+
end
|
314
|
+
else
|
315
|
+
xml.artwork **attr_code(artwork_attributes)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
# clean up XML
|
321
|
+
def cleanup(doc)
|
322
|
+
xmldoc = Nokogiri::XML(doc)
|
323
|
+
crefs = xmldoc.xpath("//cref")
|
324
|
+
# any crefs that are direct children of section should become children of the preceding
|
325
|
+
# paragraph, if it exists; otherwise, they need to be wrapped in a paragraph
|
326
|
+
crefs.each do |cref|
|
327
|
+
if cref.parent.name == "section"
|
328
|
+
prev = cref.previous_element
|
329
|
+
if !prev.nil? && prev.name == "t"
|
330
|
+
cref.parent = prev
|
331
|
+
else
|
332
|
+
t = Nokogiri::XML::Element.new("t", xmldoc)
|
333
|
+
cref.before(t)
|
334
|
+
cref.parent = t
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
unless $smart_quotes
|
339
|
+
xmldoc.traverse do |node|
|
340
|
+
if node.text?
|
341
|
+
node.content = node.content.tr("\u2019", "'")
|
342
|
+
node.content = node.content.gsub(/\’/, "'")
|
343
|
+
node.content = node.content.gsub(/\’/, "'")
|
344
|
+
elsif node.element?
|
345
|
+
node.attributes.each do |k, v|
|
346
|
+
node.set_attribute(k, v.content.tr("\u2019", "'"))
|
347
|
+
node.set_attribute(k, v.content.gsub(/\’/, "'"))
|
348
|
+
node.set_attribute(k, v.content.gsub(/\’/, "'"))
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
xmldoc.to_xml(encoding: "US-ASCII")
|
355
|
+
end
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module RFC::V3
|
3
|
+
module Blocks
|
4
|
+
# Syntax:
|
5
|
+
# [discrete]
|
6
|
+
# == Section
|
7
|
+
def floating_title(node)
|
8
|
+
noko do |xml|
|
9
|
+
xml.t { |xml_t| xml_t.strong node.title }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Syntax:
|
14
|
+
# [[id]]
|
15
|
+
# .name
|
16
|
+
# [align=left|center|right,alt=alt_text] (optional)
|
17
|
+
# ....
|
18
|
+
# literal
|
19
|
+
# ....
|
20
|
+
def literal(node)
|
21
|
+
artwork_attributes = {
|
22
|
+
anchor: node.id,
|
23
|
+
align: node.attr("align"),
|
24
|
+
type: "ascii-art",
|
25
|
+
name: node.title,
|
26
|
+
alt: node.attr("alt"),
|
27
|
+
}
|
28
|
+
|
29
|
+
# NOTE: html escaping is performed by Nokogiri
|
30
|
+
artwork_content = node.lines.join("\n")
|
31
|
+
|
32
|
+
noko do |xml|
|
33
|
+
if node.parent.context != :example
|
34
|
+
xml.figure do |xml_figure|
|
35
|
+
xml_figure.artwork artwork_content, **attr_code(artwork_attributes)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
xml.artwork artwork_content, **attr_code(artwork_attributes)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Syntax:
|
44
|
+
# [[id]]
|
45
|
+
# [quote, attribution, citation info] # citation info limited to URL
|
46
|
+
# Text
|
47
|
+
def quote(node)
|
48
|
+
cite_value = node.attr("citetitle")
|
49
|
+
cite_value = nil unless cite_value.to_s =~ URI::DEFAULT_PARSER.make_regexp
|
50
|
+
|
51
|
+
blockquote_attributes = {
|
52
|
+
anchor: node.id,
|
53
|
+
quotedFrom: node.attr("attribution"),
|
54
|
+
cite: cite_value,
|
55
|
+
}
|
56
|
+
|
57
|
+
noko do |xml|
|
58
|
+
xml.blockquote **attr_code(blockquote_attributes) do |xml_blockquote|
|
59
|
+
xml_blockquote << node.content
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# realise as quote() ; <br/> in v3 does not have the applicability of <vspace/>,
|
65
|
+
# it is restricted to tables
|
66
|
+
def verse(node)
|
67
|
+
quote(node)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Syntax:
|
71
|
+
# = Title
|
72
|
+
# Author
|
73
|
+
# :HEADER
|
74
|
+
#
|
75
|
+
# ABSTRACT
|
76
|
+
#
|
77
|
+
# NOTE: note
|
78
|
+
#
|
79
|
+
# [NOTE]
|
80
|
+
# .Title (in preamble)
|
81
|
+
# ====
|
82
|
+
# Content
|
83
|
+
# ====
|
84
|
+
#
|
85
|
+
# [NOTE,removeInRFC=true] (in preamble)
|
86
|
+
# [NOTE,display=true|false,source=name] (in body)
|
87
|
+
# .Title
|
88
|
+
# ====
|
89
|
+
# Content
|
90
|
+
# ====
|
91
|
+
# @note admonitions within preamble are notes. Elsewhere, they are comments.
|
92
|
+
def admonition(node)
|
93
|
+
result = []
|
94
|
+
if node.parent.context == :preamble
|
95
|
+
if $seen_abstract
|
96
|
+
result << "</abstract>"
|
97
|
+
$seen_abstract = false
|
98
|
+
end
|
99
|
+
|
100
|
+
note_attributes = {
|
101
|
+
removeInRFC: node.attr("remove-in-rfc"),
|
102
|
+
}
|
103
|
+
|
104
|
+
result << noko do |xml|
|
105
|
+
xml.note **attr_code(note_attributes) do |xml_note|
|
106
|
+
xml_note.name node.title unless node.title.nil?
|
107
|
+
xml_note << [paragraph1(node)].flatten.join("\n")
|
108
|
+
end
|
109
|
+
end
|
110
|
+
else
|
111
|
+
cref_attributes = {
|
112
|
+
anchor: node.id,
|
113
|
+
display: node.attr("display"),
|
114
|
+
source: node.attr("source"),
|
115
|
+
}
|
116
|
+
|
117
|
+
cref_contents = node.blocks? ? flatten(node) : node.content
|
118
|
+
cref_contents = [cref_contents].flatten.join("\n")
|
119
|
+
warn <<~WARNING_MESSAGE if node.blocks?
|
120
|
+
asciidoctor: WARNING: comment can not contain blocks of text in XML RFC:\n #{node.content}
|
121
|
+
WARNING_MESSAGE
|
122
|
+
|
123
|
+
result << noko do |xml|
|
124
|
+
xml.cref **attr_code(cref_attributes) do |xml_cref|
|
125
|
+
xml_cref << cref_contents
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
result
|
130
|
+
end
|
131
|
+
|
132
|
+
# Syntax:
|
133
|
+
# [[id]]
|
134
|
+
# ****
|
135
|
+
# Sidebar
|
136
|
+
# ****
|
137
|
+
def sidebar(node)
|
138
|
+
noko do |xml|
|
139
|
+
xml.aside anchor: node.id do |xml_aside|
|
140
|
+
xml_aside << node.content
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Syntax:
|
146
|
+
# .Title
|
147
|
+
# ====
|
148
|
+
# Example
|
149
|
+
# ====
|
150
|
+
def example(node)
|
151
|
+
node.blocks.each do |b|
|
152
|
+
unless %i{listing image literal}.include? b.context
|
153
|
+
warn "asciidoctor: WARNING: examples (figures) should only contain listings (sourcecode), images (artwork), or literal (artwork):\n#{b.lines}"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
figure_attributes = {
|
158
|
+
anchor: node.id,
|
159
|
+
}
|
160
|
+
|
161
|
+
noko do |xml|
|
162
|
+
xml.figure **attr_code(figure_attributes) do |xml_figure|
|
163
|
+
xml_figure.name node.title if node.title?
|
164
|
+
# TODO iref
|
165
|
+
xml_figure << node.content
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Syntax:
|
171
|
+
# .name
|
172
|
+
# [source,type,src=uri] (src is mutually exclusive with listing content) (v3)
|
173
|
+
# [source,type,src=uri,align,alt] (src is mutually exclusive with listing content) (v2)
|
174
|
+
# ----
|
175
|
+
# code
|
176
|
+
# ----
|
177
|
+
def listing(node)
|
178
|
+
sourcecode_attributes = {
|
179
|
+
anchor: node.id,
|
180
|
+
align: nil,
|
181
|
+
alt: nil,
|
182
|
+
name: node.title,
|
183
|
+
type: node.attr("language"),
|
184
|
+
src: node.attr("src"),
|
185
|
+
}
|
186
|
+
|
187
|
+
# NOTE: html escaping is performed by Nokogiri
|
188
|
+
sourcecode_content =
|
189
|
+
sourcecode_attributes[:src].nil? ? node.lines.join("\n") : ""
|
190
|
+
|
191
|
+
noko do |xml|
|
192
|
+
if node.parent.context != :example
|
193
|
+
xml.figure do |xml_figure|
|
194
|
+
xml_figure.sourcecode sourcecode_content, **attr_code(sourcecode_attributes)
|
195
|
+
end
|
196
|
+
else
|
197
|
+
xml.sourcecode sourcecode_content, **attr_code(sourcecode_attributes)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|