Module: Asciidoctor::Rfc::V3::Blocks
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/rfc/v3/blocks.rb
Instance Method Summary collapse
-
#admonition(node) ⇒ Object
Syntax: = Title Author :HEADER.
-
#example(node) ⇒ Object
Syntax: .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] (optional) .…
-
#quote(node) ⇒ Object
Syntax: [[id]] [quote, attribution, citation info] # citation info limited to URL Text.
-
#sidebar(node) ⇒ Object
Syntax: [[id]] **** Sidebar ****.
-
#stem(node) ⇒ Object
stem is treated as literal, but with center alignment.
-
#verse(node) ⇒ Object
realise as quote() ; <br/> in v3 does not have the applicability of <vspace/>, it is restricted to tables.
Instance Method Details
#admonition(node) ⇒ Object
admonitions within preamble are notes. Elsewhere, they are comments.
Syntax:
= Title
Author
:HEADER
ABSTRACT
NOTE: note
[NOTE]
.Title (in preamble)
====
Content
====
[NOTE,removeInRFC=true] (in preamble)
[NOTE,display=true|false,source=name] (in body)
.Title
====
Content
====
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 156 157 158 159 160 161 162 163 164 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 131 def admonition(node) result = [] if node.parent.context == :preamble note_attributes = { removeInRFC: node.attr("remove-in-rfc"), } result << noko do |xml| xml.note **attr_code(note_attributes) do |xml_note| xml_note.name node.title unless node.title.nil? xml_note << HTMLEntities.new.decode([paragraph1(node)].flatten.join("\n")) end end else cref_attributes = { anchor: node.id, display: node.attr("display"), source: node.attr("source"), } cref_contents = node.blocks? ? flatten(node) : node.content cref_contents = [cref_contents].flatten.join("\n") warn <<~WARNING_MESSAGE if node.blocks? asciidoctor: WARNING (#{current_location(node)}): comment can not contain blocks of text in XML RFC:\n #{node.content} WARNING_MESSAGE result << noko do |xml| xml.cref **attr_code(cref_attributes) do |xml_cref| xml_cref << cref_contents end end end result end |
#example(node) ⇒ Object
Syntax:
.Title
====
Example
====
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 187 def example(node) node.blocks.each do |b| unless %i{listing image literal stem}.include? b.context warn "asciidoctor: WARNING (#{current_location(b)}): examples (figures) should only contain listings (sourcecode), images (artwork), or literal (artwork):\n#{b.lines}" end end figure_attributes = { anchor: node.id, } noko do |xml| xml.figure **attr_code(figure_attributes) do |xml_figure| xml_figure.name node.title if node.title? # TODO iref xml_figure << node.content end end end |
#floating_title(node) ⇒ Object
Syntax:
- discrete
-
Section
10 11 12 13 14 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 10 def floating_title(node) noko do |xml| xml.t { |xml_t| xml_t.strong node.title } 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
----
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 239 240 241 242 243 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 214 def listing(node) sourcecode_attributes = { anchor: node.id, align: nil, alt: nil, 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 xml.figure do |xml_figure| # xml_figure.sourcecode sourcecode_content, **attr_code(sourcecode_attributes) xml_figure.sourcecode **attr_code(sourcecode_attributes) do |a| a.cdata sourcecode_content end end else # xml.sourcecode sourcecode_content, **attr_code(sourcecode_attributes) xml.sourcecode **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] (optional)
....
literal
....
23 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 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 23 def literal(node) artwork_attributes = { anchor: node.id, align: node.attr("align"), type: "ascii-art", name: node.title, alt: node.attr("alt"), } # NOTE: html escaping is performed by Nokogiri artwork_content = "\n" + node.lines.join("\n") + "\n" noko do |xml| if node.parent.context != :example xml.figure 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 end |
#quote(node) ⇒ Object
Syntax:
[[id]]
[quote, attribution, citation info] # citation info limited to URL
Text
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 86 def quote(node) cite_value = node.attr("citetitle") cite_value = nil unless cite_value.to_s =~ URI::DEFAULT_PARSER.make_regexp blockquote_attributes = { anchor: node.id, quotedFrom: node.attr("attribution"), cite: cite_value, } noko do |xml| xml.blockquote **attr_code(blockquote_attributes) do |xml_blockquote| xml_blockquote << node.content end end end |
#sidebar(node) ⇒ Object
Syntax:
[[id]]
****
Sidebar
****
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 171 def (node) aside_attributes = { anchor: node.id, } noko do |xml| xml.aside **attr_code(aside_attributes) do |xml_aside| xml_aside << node.content end end end |
#stem(node) ⇒ Object
stem is treated as literal, but with center alignment
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 53 def stem(node) artwork_attributes = { anchor: node.id, align: node.attr("align") || "center", type: "ascii-art", name: node.title, alt: node.attr("alt"), } # NOTE: html escaping is performed by Nokogiri artwork_content = "\n" + node.lines.join("\n") + "\n" noko do |xml| if node.parent.context != :example xml.figure 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 end |
#verse(node) ⇒ Object
realise as quote() ; <br/> in v3 does not have the applicability of <vspace/>, it is restricted to tables
105 106 107 |
# File 'lib/asciidoctor/rfc/v3/blocks.rb', line 105 def verse(node) quote(node) end |