Module: Asciidoctor::RFC::V2::Blocks
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/rfc/v2/blocks.rb
Instance Method Summary collapse
-
#admonition(node) ⇒ Object
Syntax: = Title Author :HEADER.
-
#example(node) ⇒ Object
Syntax: [[id]] .Title [align,alt,suppress-title] ==== Example ====.
-
#floating_title(node) ⇒ Object
Syntax: [discrete] == Section.
-
#listing(node) ⇒ Object
Syntax: .name [source,type,src=uri] (src is mutually exclusive with listing content) (v3) [source,type,src=uri,align,alt] (src is mutually exclusive with listing content) (v2) —- code —-.
-
#literal(node) ⇒ Object
Syntax: [[id]] .Name [align=left|center|right,alt=alt_text,type] (optional) .…
- #quote(node) ⇒ Object
-
#stem(node) ⇒ Object
stem is treated as literal, but with center alignment.
Instance Method Details
#admonition(node) ⇒ Object
Note:
admonitions within preamble are notes. Elsewhere, they are comments.
Syntax:
= Title
Author
:HEADER
ABSTRACT
NOTE: note
[NOTE]
.Title (in preamble)
====
Content
====
[NOTE] (in preamble)
[NOTE,source=name] (in body)
.Title
====
Content
====
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 112 def admonition(node) result = [] if node.parent.context == :preamble note_attributes = { # default title provided: title is mandatory title: (node.title.nil? ? "NOTE" : node.title), } note_contents = HTMLEntities.new.decode([paragraph1(node)].flatten.join("\n")) result << noko do |xml| xml.note **attr_code(note_attributes) do |xml_note| xml_note << note_contents end end else cref_attributes = { anchor: node.id, source: node.attr("source"), } # remove all formatting: cref content is pure text cref_contents = flatten_rawtext(node) cref_contents = [cref_contents].flatten.join("\n") warn <<~WARNING_MESSAGE if node.blocks? asciidoctor: WARNING (#{node.lineno}): comment can not contain blocks of text in XML RFC:\n #{node.content} WARNING_MESSAGE result << noko do |xml| if node.parent.context !~ /table|example|paragraph|section/ xml.t do |xml_t| xml_t.cref **attr_code(cref_attributes) do |xml_cref| xml_cref << cref_contents end end else xml.cref **attr_code(cref_attributes) do |xml_cref| xml_cref << cref_contents end end end end result end |
#example(node) ⇒ Object
Syntax:
[[id]]
.Title
[align,alt,suppress-title]
====
Example
====
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 164 def example(node) figure_attributes = { anchor: node.id, align: node.attr("align"), alt: node.alt, title: node.title, 'suppress-title': node.attr("suppress-title"), # TODO: is 'suppress-title' the correct attribute name? } # TODO iref seen_artwork = false noko do |xml| xml.figure **attr_code(figure_attributes) do |xml_figure| node.blocks.each do |b| case b.context when :listing, :image, :literal, :stem xml_figure << send(b.context, b).join("\n") seen_artwork = true else # we want to see the para text, not its <t> container if seen_artwork xml_figure.postamble do |postamble| postamble << b.content end else xml_figure.preamble do |preamble| preamble << b.content end end end end end end end |
#floating_title(node) ⇒ Object
Syntax:
- discrete
-
Section
9 10 11 12 13 14 15 |
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 9 def floating_title(node) noko do |xml| xml.t do |xml_t| xml_t.spanx node.title, style: "strong" end end end |
#listing(node) ⇒ Object
Syntax:
.name
[source,type,src=uri] (src is mutually exclusive with listing content) (v3)
[source,type,src=uri,align,alt] (src is mutually exclusive with listing content) (v2)
----
code
----
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 206 def listing(node) sourcecode_attributes = { align: node.attr("align"), alt: node.alt, name: node.title, type: node.attr("language"), src: node.attr("src"), } # NOTE: html escaping is performed by Nokogiri sourcecode_content = sourcecode_attributes[:src].nil? ? "\n" + node.lines.join("\n") + "\n" : "" noko do |xml| if node.parent.context != :example figure_attributes = { anchor: node.id, } xml.figure **attr_code(figure_attributes) do |xml_figure| # xml_figure.artwork sourcecode_content, **attr_code(sourcecode_attributes) xml_figure.artwork **attr_code(sourcecode_attributes) do |a| a.cdata sourcecode_content end end else # xml.artwork sourcecode_content, **attr_code(sourcecode_attributes) xml.artwork **attr_code(sourcecode_attributes) do |a| a.cdata sourcecode_content end end end end |
#literal(node) ⇒ Object
Syntax:
[[id]]
.Name
[align=left|center|right,alt=alt_text,type] (optional)
....
literal
....
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 24 def literal(node) artwork_attributes = { align: node.attr("align"), type: node.attr("type"), name: node.title, alt: node.attr("alt"), } # NOTE: html escaping is performed by Nokogiri artwork_content = "\n" + node.lines.join("\n") + "\n" ret = noko do |xml| if node.parent.context != :example figure_attributes = { anchor: node.id, } xml.figure **attr_code(figure_attributes) do |xml_figure| # xml_figure.artwork artwork_content, **attr_code(artwork_attributes) xml_figure.artwork **attr_code(artwork_attributes) do |a| a.cdata artwork_content end end else # xml.artwork artwork_content, **attr_code(artwork_attributes) xml.artwork **attr_code(artwork_attributes) do |a| a.cdata artwork_content end end end ret end |
#quote(node) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 240 def quote(node) result = [] if node.blocks? node.blocks.each do |b| result << send(b.context, b) end else result = paragraph(node) end if node.attr("citetitle") || node.attr("attribution") cite = node.attr("attribution") || "" cite += ", " if node.attr("citetitle") && node.attr("attribution") cite += (node.attr("citetitle") || "") cite = "-- " + cite result << "<t>#{cite}</t>" end result end |
#stem(node) ⇒ Object
stem is treated as literal, but with center alignment
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 57 def stem(node) artwork_attributes = { align: node.attr("align") || "center", type: node.attr("type"), name: node.title, alt: node.attr("alt"), } # NOTE: html escaping is performed by Nokogiri artwork_content = "\n" + node.lines.join("\n") + "\n" ret = noko do |xml| if node.parent.context != :example figure_attributes = { anchor: node.id, } xml.figure **attr_code(figure_attributes) do |xml_figure| # xml_figure.artwork artwork_content, **attr_code(artwork_attributes) xml_figure.artwork **attr_code(artwork_attributes) do |a| a.cdata artwork_content end end else # xml.artwork artwork_content, **attr_code(artwork_attributes) xml.artwork **attr_code(artwork_attributes) do |a| a.cdata artwork_content end end end ret end |