Module: Asciidoctor::Rfc::V2::Blocks

Included in:
Converter
Defined in:
lib/asciidoctor/rfc/v2/blocks.rb

Instance Method Summary collapse

Instance Method Details

#admonition(node) ⇒ Object

Note:

admonitions within preamble are notes. Elsewhere, they are comments.

Note:

admonitions within preamble are notes. Elsewhere, they are LABEL followed by text

Syntax:

= Title
Author
:HEADER

ABSTRACT

NOTE: note

[NOTE]
.Title (in preamble)
====
  Content
====

  [NOTE] (in preamble)
  [NOTE,source=name] (in body)
.Title
====
  Content
====

UPDATE 20190517



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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 118

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
=begin
    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
=end
    result << "<t>#{node.attr("name").upcase}</t>"
    if node.blocks?
      node.blocks.each do |b|
        result << send(b.context, b)
      end
    else
      result << paragraph(node)
    end
  end
  result
end

#example(node) ⇒ Object

Syntax:

[[id]]
.Title
[align,alt,suppress-title]
====
Example
====


193
194
195
196
197
198
199
200
201
202
203
204
205
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
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 193

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

  if text_only_example(node)
    noko do |xml|
      node.blocks.each do |b|
        xml << node.content
      end
    end
  else
    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
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
----


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 244

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
....


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
55
56
57
58
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 28

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

#pass(node) ⇒ Object



17
18
19
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 17

def pass(node)
  node.content
end

#quote(node) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 278

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



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
88
89
90
91
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 61

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

#text_only_example(node) ⇒ Object

is this a text-only example? if so, mark it up as paragraphs



175
176
177
178
179
180
181
182
183
184
# File 'lib/asciidoctor/rfc/v2/blocks.rb', line 175

def text_only_example(node)
  seen_artwork = false
  node.blocks.each do |b|
    case b.context
    when :listing, :image, :literal, :stem
      seen_artwork = true
    end
  end
  !seen_artwork
end