Class: Asciidoctor::Converter::DocBook5Converter

Inherits:
Base
  • Object
show all
Defined in:
lib/asciidoctor/converter/docbook5.rb

Overview

by the docbook45 backend from AsciiDoc.py, except it has been migrated to the DocBook 5 specification.

Constant Summary collapse

MANPAGE_SECTION_TAGS =
{ 'section' => 'refsection', 'synopsis' => 'refsynopsisdiv' }
TABLE_PI_NAMES =
['dbhtml', 'dbfo', 'dblatex']
CopyrightRx =
/^(#{CC_ANY}+?)(?: ((?:\d{4}-)?\d{4}))?$/
ImageMacroRx =
/^image::?(\S|\S#{CC_ANY}*?\S)\[(#{CC_ANY}+)?\]$/

Constants included from DefaultFactory

Asciidoctor::Converter::DefaultFactory::PROVIDED

Instance Attribute Summary

Attributes included from Asciidoctor::Converter

#backend

Instance Method Summary collapse

Methods inherited from Base

#content_only, #convert, #handles?, #skip

Methods included from Asciidoctor::Converter

#convert, derive_backend_traits, #handles?

Methods included from DefaultFactory

#for, #register, #unregister_all

Methods included from Factory

#converters, #create, create, default, #for, new, #register

Methods included from Logging

#logger, #message_with_context

Constructor Details

#initialize(backend, opts = {}) ⇒ DocBook5Converter

Returns a new instance of DocBook5Converter.



31
32
33
34
# File 'lib/asciidoctor/converter/docbook5.rb', line 31

def initialize backend, opts = {}
  @backend = backend
  init_backend_traits basebackend: 'docbook', filetype: 'xml', outfilesuffix: '.xml', supports_templates: true
end

Instance Method Details

#convert_admonition(node) ⇒ Object



90
91
92
93
94
# File 'lib/asciidoctor/converter/docbook5.rb', line 90

def convert_admonition node
  %(<#{tag_name = node.attr 'name'}#{common_attributes node.id, node.role, node.reftext}>
#{title_tag node}#{enclose_content node}
</#{tag_name}>)
end

#convert_colist(node) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/asciidoctor/converter/docbook5.rb', line 98

def convert_colist node
  result = []
  result << %(<calloutlist#{common_attributes node.id, node.role, node.reftext}>)
  result << %(<title>#{node.title}</title>) if node.title?
  node.items.each do |item|
    result << %(<callout arearefs="#{item.attr 'coids'}">)
    result << %(<para>#{item.text}</para>)
    result << item.content if item.blocks?
    result << '</callout>'
  end
  result << %(</calloutlist>)
  result.join LF
end

#convert_dlist(node) ⇒ Object



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
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/asciidoctor/converter/docbook5.rb', line 112

def convert_dlist node
  result = []
  if node.style == 'horizontal'
    result << %(<#{tag_name = node.title? ? 'table' : 'informaltable'}#{common_attributes node.id, node.role, node.reftext} tabstyle="horizontal" frame="none" colsep="0" rowsep="0">
#{title_tag node}<tgroup cols="2">
<colspec colwidth="#{node.attr 'labelwidth', 15}*"/>
<colspec colwidth="#{node.attr 'itemwidth', 85}*"/>
<tbody valign="top">)
    node.items.each do |terms, dd|
      result << %(<row>
<entry>)
      terms.each {|dt| result << %(<simpara>#{dt.text}</simpara>) }
      result << %(</entry>
<entry>)
      if dd
        result << %(<simpara>#{dd.text}</simpara>) if dd.text?
        result << dd.content if dd.blocks?
      end
      result << %(</entry>
</row>)
    end
    result << %(</tbody>
</tgroup>
</#{tag_name}>)
  else
    tags = DLIST_TAGS[node.style]
    list_tag = tags[:list]
     = tags[:entry]
    label_tag = tags[:label]
    term_tag = tags[:term]
    item_tag = tags[:item]
    if list_tag
      result << %(<#{list_tag}#{common_attributes node.id, node.role, node.reftext}>)
      result << %(<title>#{node.title}</title>) if node.title?
    end

    node.items.each do |terms, dd|
      result << %(<#{}>)
      result << %(<#{label_tag}>) if label_tag
      terms.each {|dt| result << %(<#{term_tag}>#{dt.text}</#{term_tag}>) }
      result << %(</#{label_tag}>) if label_tag
      result << %(<#{item_tag}>)
      if dd
        result << %(<simpara>#{dd.text}</simpara>) if dd.text?
        result << dd.content if dd.blocks?
      end
      result << %(</#{item_tag}>)
      result << %(</#{}>)
    end

    result << %(</#{list_tag}>) if list_tag
  end

  result.join LF
end

#convert_document(node) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/asciidoctor/converter/docbook5.rb', line 36

def convert_document node
  result = ['<?xml version="1.0" encoding="UTF-8"?>']
  result << ((node.attr? 'toclevels') ? %(<?asciidoc-toc maxdepth="#{node.attr 'toclevels'}"?>) : '<?asciidoc-toc?>') if node.attr? 'toc'
  result << ((node.attr? 'sectnumlevels') ? %(<?asciidoc-numbered maxdepth="#{node.attr 'sectnumlevels'}"?>) : '<?asciidoc-numbered?>') if node.attr? 'sectnums'
  lang_attribute = (node.attr? 'nolang') ? '' : %( xml:lang="#{node.attr 'lang', 'en'}")
  if (root_tag_name = node.doctype) == 'manpage'
    manpage = true
    root_tag_name = 'article'
  end
  root_tag_idx = result.size
  id = node.id
  result << (document_info_tag node) unless node.noheader
  if manpage
    result << '<refentry>'
    result << '<refmeta>'
    result << %(<refentrytitle>#{node.apply_reftext_subs node.attr 'mantitle'}</refentrytitle>) if node.attr? 'mantitle'
    result << %(<manvolnum>#{node.attr 'manvolnum'}</manvolnum>) if node.attr? 'manvolnum'
    result << %(<refmiscinfo class="source">#{node.attr 'mansource', '&#160;'}</refmiscinfo>)
    result << %(<refmiscinfo class="manual">#{node.attr 'manmanual', '&#160;'}</refmiscinfo>)
    result << '</refmeta>'
    result << '<refnamediv>'
    result += (node.attr 'mannames').map {|n| %(<refname>#{n}</refname>) } if node.attr? 'mannames'
    result << %(<refpurpose>#{node.attr 'manpurpose'}</refpurpose>) if node.attr? 'manpurpose'
    result << '</refnamediv>'
  end
  unless (docinfo_content = node.docinfo :header).empty?
    result << docinfo_content
  end
  result << node.content if node.blocks?
  unless (docinfo_content = node.docinfo :footer).empty?
    result << docinfo_content
  end
  result << '</refentry>' if manpage
  id, node.id = node.id, nil unless id
  # defer adding root tag in case document ID is auto-generated on demand
  result.insert root_tag_idx, %(<#{root_tag_name} xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0"#{lang_attribute}#{common_attributes id}>)
  result << %(</#{root_tag_name}>)
  result.join LF
end

#convert_example(node) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/asciidoctor/converter/docbook5.rb', line 168

def convert_example node
  if node.title?
    %(<example#{common_attributes node.id, node.role, node.reftext}>
<title>#{node.title}</title>
#{enclose_content node}
</example>)
  else
    %(<informalexample#{common_attributes node.id, node.role, node.reftext}>
#{enclose_content node}
</informalexample>)
  end
end

#convert_floating_title(node) ⇒ Object



181
182
183
# File 'lib/asciidoctor/converter/docbook5.rb', line 181

def convert_floating_title node
  %(<bridgehead#{common_attributes node.id, node.role, node.reftext} renderas="sect#{node.level}">#{node.title}</bridgehead>)
end

#convert_image(node) ⇒ Object



185
186
187
188
189
190
191
192
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
# File 'lib/asciidoctor/converter/docbook5.rb', line 185

def convert_image node
  # NOTE according to the DocBook spec, content area, scaling, and scaling to fit are mutually exclusive
  # See http://tdg.docbook.org/tdg/4.5/imagedata-x.html#d0e79635
  if node.attr? 'scaledwidth'
    width_attribute = %( width="#{node.attr 'scaledwidth'}")
    depth_attribute = ''
    scale_attribute = ''
  elsif node.attr? 'scale'
    # QUESTION should we set the viewport using width and depth? (the scaled image would be contained within this box)
    #width_attribute = (node.attr? 'width') ? %( width="#{node.attr 'width'}") : ''
    #depth_attribute = (node.attr? 'height') ? %( depth="#{node.attr 'height'}") : ''
    scale_attribute = %( scale="#{node.attr 'scale'}")
  else
    width_attribute = (node.attr? 'width') ? %( contentwidth="#{node.attr 'width'}") : ''
    depth_attribute = (node.attr? 'height') ? %( contentdepth="#{node.attr 'height'}") : ''
    scale_attribute = ''
  end
  align_attribute = (node.attr? 'align') ? %( align="#{node.attr 'align'}") : ''

  mediaobject = %(<mediaobject>
<imageobject>
<imagedata fileref="#{node.image_uri(node.attr 'target')}"#{width_attribute}#{depth_attribute}#{scale_attribute}#{align_attribute}/>
</imageobject>
<textobject><phrase>#{node.alt}</phrase></textobject>
</mediaobject>)

  if node.title?
    %(<figure#{common_attributes node.id, node.role, node.reftext}>
<title>#{node.title}</title>
#{mediaobject}
</figure>)
  else
    %(<informalfigure#{common_attributes node.id, node.role, node.reftext}>
#{mediaobject}
</informalfigure>)
  end
end

#convert_inline_anchor(node) ⇒ Object



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/asciidoctor/converter/docbook5.rb', line 490

def convert_inline_anchor node
  case node.type
  when :ref
    %(<anchor#{common_attributes((id = node.id), nil, node.reftext || %([#{id}]))}/>)
  when :xref
    if (path = node.attributes['path'])
      %(<link xl:href="#{node.target}">#{node.text || path}</link>)
    else
      if (linkend = node.attributes['refid']).nil_or_empty?
        root_doc = get_root_document node
        # Q: should we warn instead of generating a document ID on demand?
        linkend = (root_doc.id ||= generate_document_id root_doc)
      end
      # NOTE the xref tag in DocBook does not support explicit link text, so the link tag must be used instead
      # The section at http://www.sagehill.net/docbookxsl/CrossRefs.html#IdrefLinks gives an explanation for this choice
      # "link - a cross reference where you supply the text of the reference as the content of the link element."
      (text = node.text) ? %(<link linkend="#{linkend}">#{text}</link>) : %(<xref linkend="#{linkend}"/>)
    end
  when :link
    %(<link xl:href="#{node.target}">#{node.text}</link>)
  when :bibref
    %(<anchor#{common_attributes node.id, nil, (text = "[#{node.reftext || node.id}]")}/>#{text})
  else
    logger.warn %(unknown anchor type: #{node.type.inspect})
    nil
  end
end

#convert_inline_break(node) ⇒ Object



518
519
520
# File 'lib/asciidoctor/converter/docbook5.rb', line 518

def convert_inline_break node
  %(#{node.text}<?asciidoc-br?>)
end

#convert_inline_button(node) ⇒ Object



522
523
524
# File 'lib/asciidoctor/converter/docbook5.rb', line 522

def convert_inline_button node
  %(<guibutton>#{node.text}</guibutton>)
end

#convert_inline_callout(node) ⇒ Object



526
527
528
# File 'lib/asciidoctor/converter/docbook5.rb', line 526

def convert_inline_callout node
  %(<co#{common_attributes node.id}/>)
end

#convert_inline_footnote(node) ⇒ Object



530
531
532
533
534
535
536
# File 'lib/asciidoctor/converter/docbook5.rb', line 530

def convert_inline_footnote node
  if node.type == :xref
    %(<footnoteref linkend="#{node.target}"/>)
  else
    %(<footnote#{common_attributes node.id}><simpara>#{node.text}</simpara></footnote>)
  end
end

#convert_inline_image(node) ⇒ Object



538
539
540
541
542
543
544
545
546
547
# File 'lib/asciidoctor/converter/docbook5.rb', line 538

def convert_inline_image node
  width_attribute = (node.attr? 'width') ? %( contentwidth="#{node.attr 'width'}") : ''
  depth_attribute = (node.attr? 'height') ? %( contentdepth="#{node.attr 'height'}") : ''
  %(<inlinemediaobject#{common_attributes nil, node.role}>
<imageobject>
<imagedata fileref="#{node.type == 'icon' ? (node.icon_uri node.target) : (node.image_uri node.target)}"#{width_attribute}#{depth_attribute}/>
</imageobject>
<textobject><phrase>#{node.alt}</phrase></textobject>
</inlinemediaobject>)
end

#convert_inline_indexterm(node) ⇒ Object



549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/asciidoctor/converter/docbook5.rb', line 549

def convert_inline_indexterm node
  if (see = node.attr 'see')
    rel = %(\n<see>#{see}</see>)
  elsif (see_also_list = node.attr 'see-also')
    rel = see_also_list.map {|see_also| %(\n<seealso>#{see_also}</seealso>) }.join
  else
    rel = ''
  end
  if node.type == :visible
    %(<indexterm>
<primary>#{node.text}</primary>#{rel}
</indexterm>#{node.text})
  elsif (numterms = (terms = node.attr 'terms').size) > 2
    %(<indexterm>
<primary>#{terms[0]}</primary><secondary>#{terms[1]}</secondary><tertiary>#{terms[2]}</tertiary>#{rel}
</indexterm>#{(node.document.option? 'indexterm-promotion') ? %[
<indexterm>
<primary>#{terms[1]}</primary><secondary>#{terms[2]}</secondary>
</indexterm>
<indexterm>
<primary>#{terms[2]}</primary>
</indexterm>] : ''})
  elsif numterms > 1
    %(<indexterm>
<primary>#{terms[0]}</primary><secondary>#{terms[1]}</secondary>#{rel}
</indexterm>#{(node.document.option? 'indexterm-promotion') ? %[
<indexterm>
<primary>#{terms[1]}</primary>
</indexterm>] : ''})
  else
    %(<indexterm>
<primary>#{terms[0]}</primary>#{rel}
</indexterm>)
  end
end

#convert_inline_kbd(node) ⇒ Object



585
586
587
588
589
590
591
# File 'lib/asciidoctor/converter/docbook5.rb', line 585

def convert_inline_kbd node
  if (keys = node.attr 'keys').size == 1
    %(<keycap>#{keys[0]}</keycap>)
  else
    %(<keycombo><keycap>#{keys.join '</keycap><keycap>'}</keycap></keycombo>)
  end
end

#convert_inline_menu(node) ⇒ Object



593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/asciidoctor/converter/docbook5.rb', line 593

def convert_inline_menu node
  menu = node.attr 'menu'
  if (submenus = node.attr 'submenus').empty?
    if (menuitem = node.attr 'menuitem')
      %(<menuchoice><guimenu>#{menu}</guimenu> <guimenuitem>#{menuitem}</guimenuitem></menuchoice>)
    else
      %(<guimenu>#{menu}</guimenu>)
    end
  else
    %(<menuchoice><guimenu>#{menu}</guimenu> <guisubmenu>#{submenus.join '</guisubmenu> <guisubmenu>'}</guisubmenu> <guimenuitem>#{node.attr 'menuitem'}</guimenuitem></menuchoice>)
  end
end

#convert_inline_quoted(node) ⇒ Object



606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File 'lib/asciidoctor/converter/docbook5.rb', line 606

def convert_inline_quoted node
  if (type = node.type) == :asciimath
    # NOTE fop requires jeuclid to process mathml markup
    asciimath_available? ? %(<inlineequation>#{(::AsciiMath.parse node.text).to_mathml 'mml:', 'xmlns:mml' => 'http://www.w3.org/1998/Math/MathML'}</inlineequation>) : %(<inlineequation><mathphrase><![CDATA[#{node.text}]]></mathphrase></inlineequation>)
  elsif type == :latexmath
    # unhandled math; pass source to alt and required mathphrase element; dblatex will process alt as LaTeX math
    %(<inlineequation><alt><![CDATA[#{equation = node.text}]]></alt><mathphrase><![CDATA[#{equation}]]></mathphrase></inlineequation>)
  else
    open, close, supports_phrase = QUOTE_TAGS[type]
    text = node.text
    if node.role
      if supports_phrase
        quoted_text = %(#{open}<phrase role="#{node.role}">#{text}</phrase>#{close})
      else
        quoted_text = %(#{open.chop} role="#{node.role}">#{text}#{close})
      end
    else
      quoted_text = %(#{open}#{text}#{close})
    end

    node.id ? %(<anchor#{common_attributes node.id, nil, text}/>#{quoted_text}) : quoted_text
  end
end

#convert_listing(node) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/asciidoctor/converter/docbook5.rb', line 223

def convert_listing node
  informal = !node.title?
  common_attrs = common_attributes node.id, node.role, node.reftext
  if node.style == 'source'
    if (attrs = node.attributes).key? 'linenums'
      numbering_attrs = (attrs.key? 'start') ? %( linenumbering="numbered" startinglinenumber="#{attrs['start'].to_i}") : ' linenumbering="numbered"'
    else
      numbering_attrs = ' linenumbering="unnumbered"'
    end
    if attrs.key? 'language'
      wrapped_content = %(<programlisting#{informal ? common_attrs : ''} language="#{attrs['language']}"#{numbering_attrs}>#{node.content}</programlisting>)
    else
      wrapped_content = %(<screen#{informal ? common_attrs : ''}#{numbering_attrs}>#{node.content}</screen>)
    end
  else
    wrapped_content = %(<screen#{informal ? common_attrs : ''}>#{node.content}</screen>)
  end
  informal ? wrapped_content : %(<formalpara#{common_attrs}>
<title>#{node.title}</title>
<para>
#{wrapped_content}
</para>
</formalpara>)
end

#convert_literal(node) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/asciidoctor/converter/docbook5.rb', line 248

def convert_literal node
  if node.title?
    %(<formalpara#{common_attributes node.id, node.role, node.reftext}>
<title>#{node.title}</title>
<para>
<literallayout class="monospaced">#{node.content}</literallayout>
</para>
</formalpara>)
  else
    %(<literallayout#{common_attributes node.id, node.role, node.reftext} class="monospaced">#{node.content}</literallayout>)
  end
end

#convert_olist(node) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/asciidoctor/converter/docbook5.rb', line 292

def convert_olist node
  result = []
  num_attribute = node.style ? %( numeration="#{node.style}") : ''
  start_attribute = (node.attr? 'start') ? %( startingnumber="#{node.attr 'start'}") : ''
  result << %(<orderedlist#{common_attributes node.id, node.role, node.reftext}#{num_attribute}#{start_attribute}>)
  result << %(<title>#{node.title}</title>) if node.title?
  node.items.each do |item|
    result << %(<listitem#{common_attributes item.id, item.role}>)
    result << %(<simpara>#{item.text}</simpara>)
    result << item.content if item.blocks?
    result << '</listitem>'
  end
  result << %(</orderedlist>)
  result.join LF
end

#convert_open(node) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/asciidoctor/converter/docbook5.rb', line 308

def convert_open node
  case node.style
  when 'abstract'
    if node.parent == node.document && node.document.doctype == 'book'
      logger.warn 'abstract block cannot be used in a document without a title when doctype is book. Excluding block content.'
      ''
    else
      %(<abstract>
#{title_tag node}#{enclose_content node}
</abstract>)
    end
  when 'partintro'
    if node.level == 0 && node.parent.context == :section && node.document.doctype == 'book'
      %(<partintro#{common_attributes node.id, node.role, node.reftext}>
#{title_tag node}#{enclose_content node}
</partintro>)
    else
      logger.error 'partintro block can only be used when doctype is book and must be a child of a book part. Excluding block content.'
      ''
    end
  else
    reftext = node.reftext if (id = node.id)
    role = node.role
    if node.title?
      %(<formalpara#{common_attributes id, role, reftext}>
<title>#{node.title}</title>
<para>#{content_spacer = node.content_model == :compound ? LF : ''}#{node.content}#{content_spacer}</para>
</formalpara>)
    elsif id || role
      if node.content_model == :compound
        %(<para#{common_attributes id, role, reftext}>
#{node.content}
</para>)
      else
        %(<simpara#{common_attributes id, role, reftext}>#{node.content}</simpara>)
      end
    else
      enclose_content node
    end
  end
end

#convert_page_break(node) ⇒ Object



350
351
352
# File 'lib/asciidoctor/converter/docbook5.rb', line 350

def convert_page_break node
  '<simpara><?asciidoc-pagebreak?></simpara>'
end

#convert_paragraph(node) ⇒ Object



354
355
356
357
358
359
360
361
362
363
# File 'lib/asciidoctor/converter/docbook5.rb', line 354

def convert_paragraph node
  if node.title?
    %(<formalpara#{common_attributes node.id, node.role, node.reftext}>
<title>#{node.title}</title>
<para>#{node.content}</para>
</formalpara>)
  else
    %(<simpara#{common_attributes node.id, node.role, node.reftext}>#{node.content}</simpara>)
  end
end

#convert_preamble(node) ⇒ Object



365
366
367
368
369
370
371
372
373
# File 'lib/asciidoctor/converter/docbook5.rb', line 365

def convert_preamble node
  if node.document.doctype == 'book'
    %(<preface#{common_attributes node.id, node.role, node.reftext}>
#{title_tag node, false}#{node.content}
</preface>)
  else
    node.content
  end
end

#convert_quote(node) ⇒ Object



375
376
377
# File 'lib/asciidoctor/converter/docbook5.rb', line 375

def convert_quote node
  blockquote_tag(node, (node.has_role? 'epigraph') && 'epigraph') { enclose_content node }
end

#convert_section(node) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/asciidoctor/converter/docbook5.rb', line 78

def convert_section node
  if node.document.doctype == 'manpage'
    tag_name = MANPAGE_SECTION_TAGS[tag_name = node.sectname] || tag_name
  else
    tag_name = node.sectname
  end
  title_el = node.special && ((node.option? 'notitle') || (node.option? 'untitled')) ? '' : %(<title>#{node.title}</title>\n)
  %(<#{tag_name}#{common_attributes node.id, node.role, node.reftext}>
#{title_el}#{node.content}
</#{tag_name}>)
end

#convert_sidebar(node) ⇒ Object



383
384
385
386
387
# File 'lib/asciidoctor/converter/docbook5.rb', line 383

def convert_sidebar node
  %(<sidebar#{common_attributes node.id, node.role, node.reftext}>
#{title_tag node}#{enclose_content node}
</sidebar>)
end

#convert_stem(node) ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/asciidoctor/converter/docbook5.rb', line 263

def convert_stem node
  if (idx = node.subs.index :specialcharacters)
    node.subs.delete_at idx
    equation = node.content
    idx > 0 ? (node.subs.insert idx, :specialcharacters) : (node.subs.unshift :specialcharacters)
  else
    equation = node.content
  end
  if node.style == 'asciimath'
    # NOTE fop requires jeuclid to process mathml markup
    equation_data = asciimath_available? ? ((::AsciiMath.parse equation).to_mathml 'mml:', 'xmlns:mml' => 'http://www.w3.org/1998/Math/MathML') : %(<mathphrase><![CDATA[#{equation}]]></mathphrase>)
  else
    # unhandled math; pass source to alt and required mathphrase element; dblatex will process alt as LaTeX math
    equation_data = %(<alt><![CDATA[#{equation}]]></alt>
<mathphrase><![CDATA[#{equation}]]></mathphrase>)
  end
  if node.title?
    %(<equation#{common_attributes node.id, node.role, node.reftext}>
<title>#{node.title}</title>
#{equation_data}
</equation>)
  else
    # WARNING dblatex displays the <informalequation> element inline instead of block as documented (except w/ mathml)
    %(<informalequation#{common_attributes node.id, node.role, node.reftext}>
#{equation_data}
</informalequation>)
  end
end

#convert_table(node) ⇒ Object



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/asciidoctor/converter/docbook5.rb', line 389

def convert_table node
  has_body = false
  result = []
  pgwide_attribute = (node.option? 'pgwide') ? ' pgwide="1"' : ''
  frame = 'topbot' if (frame = node.attr 'frame', 'all', 'table-frame') == 'ends'
  grid = node.attr 'grid', nil, 'table-grid'
  result << %(<#{tag_name = node.title? ? 'table' : 'informaltable'}#{common_attributes node.id, node.role, node.reftext}#{pgwide_attribute} frame="#{frame}" rowsep="#{['none', 'cols'].include?(grid) ? 0 : 1}" colsep="#{['none', 'rows'].include?(grid) ? 0 : 1}"#{(node.attr? 'orientation', 'landscape', 'table-orientation') ? ' orient="land"' : ''}>)
  if node.option? 'unbreakable'
    result << '<?dbfo keep-together="always"?>'
  elsif node.option? 'breakable'
    result << '<?dbfo keep-together="auto"?>'
  end
  result << %(<title>#{node.title}</title>) if tag_name == 'table'
  if (width = (node.attr? 'width') ? (node.attr 'width') : nil)
    TABLE_PI_NAMES.each do |pi_name|
      result << %(<?#{pi_name} table-width="#{width}"?>)
    end
    col_width_key = 'colabswidth'
  else
    col_width_key = 'colpcwidth'
  end
  result << %(<tgroup cols="#{node.attr 'colcount'}">)
  node.columns.each do |col|
    result << %(<colspec colname="col_#{col.attr 'colnumber'}" colwidth="#{col.attr col_width_key}*"/>)
  end
  node.rows.to_h.each do |tsec, rows|
    next if rows.empty?
    has_body = true if tsec == :body
    result << %(<t#{tsec}>)
    rows.each do |row|
      result << '<row>'
      row.each do |cell|
        colspan_attribute = cell.colspan ? %( namest="col_#{colnum = cell.column.attr 'colnumber'}" nameend="col_#{colnum + cell.colspan - 1}") : ''
        rowspan_attribute = cell.rowspan ? %( morerows="#{cell.rowspan - 1}") : ''
        # NOTE <entry> may not have whitespace (e.g., line breaks) as a direct descendant according to DocBook rules
        entry_start = %(<entry align="#{cell.attr 'halign'}" valign="#{cell.attr 'valign'}"#{colspan_attribute}#{rowspan_attribute}>)
        if tsec == :head
          cell_content = cell.text
        else
          case cell.style
          when :asciidoc
            cell_content = cell.content
          when :literal
            cell_content = %(<literallayout class="monospaced">#{cell.text}</literallayout>)
          when :header
            cell_content = (cell_content = cell.content).empty? ? '' : %(<simpara><emphasis role="strong">#{cell_content.join '</emphasis></simpara><simpara><emphasis role="strong">'}</emphasis></simpara>)
          else
            cell_content = (cell_content = cell.content).empty? ? '' : %(<simpara>#{cell_content.join '</simpara><simpara>'}</simpara>)
          end
        end
        entry_end = (node.document.attr? 'cellbgcolor') ? %(<?dbfo bgcolor="#{node.document.attr 'cellbgcolor'}"?></entry>) : '</entry>'
        result << %(#{entry_start}#{cell_content}#{entry_end})
      end
      result << '</row>'
    end
    result << %(</t#{tsec}>)
  end
  result << '</tgroup>'
  result << %(</#{tag_name}>)

  logger.warn 'tables must have at least one body row' unless has_body
  result.join LF
end

#convert_thematic_break(node) ⇒ Object



379
380
381
# File 'lib/asciidoctor/converter/docbook5.rb', line 379

def convert_thematic_break node
  '<simpara><?asciidoc-hr?></simpara>'
end

#convert_ulist(node) ⇒ Object



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/asciidoctor/converter/docbook5.rb', line 455

def convert_ulist node
  result = []
  if node.style == 'bibliography'
    result << %(<bibliodiv#{common_attributes node.id, node.role, node.reftext}>)
    result << %(<title>#{node.title}</title>) if node.title?
    node.items.each do |item|
      result << '<bibliomixed>'
      result << %(<bibliomisc>#{item.text}</bibliomisc>)
      result << item.content if item.blocks?
      result << '</bibliomixed>'
    end
    result << '</bibliodiv>'
  else
    mark_type = (checklist = node.option? 'checklist') ? 'none' : node.style
    mark_attribute = mark_type ? %( mark="#{mark_type}") : ''
    result << %(<itemizedlist#{common_attributes node.id, node.role, node.reftext}#{mark_attribute}>)
    result << %(<title>#{node.title}</title>) if node.title?
    node.items.each do |item|
      text_marker = (item.attr? 'checked') ? '&#10003; ' : '&#10063; ' if checklist && (item.attr? 'checkbox')
      result << %(<listitem#{common_attributes item.id, item.role}>)
      result << %(<simpara>#{text_marker || ''}#{item.text}</simpara>)
      result << item.content if item.blocks?
      result << '</listitem>'
    end
    result << '</itemizedlist>'
  end
  result.join LF
end

#convert_verse(node) ⇒ Object



484
485
486
# File 'lib/asciidoctor/converter/docbook5.rb', line 484

def convert_verse node
  blockquote_tag(node, (node.has_role? 'epigraph') && 'epigraph') { %(<literallayout>#{node.content}</literallayout>) }
end