# encoding: UTF-8 require 'asciidoctor/converter/docbook5' module Asciidoctor # A built-in {Converter} implementation that generates DocBook 4.5 output # consistent with the docbook45 backend from AsciiDoc Python. class Converter::DocBook45Converter < Converter::DocBook5Converter def admonition node # address a bug in the DocBook 4.5 DTD if node.parent.context == :example %( #{super} ) else super end end def olist node result = [] num_attribute = node.style ? %( numeration="#{node.style}") : nil start_attribute = (node.attr? 'start') ? %( override="#{node.attr 'start'}") : nil result << %() result << %(#{node.title}) if node.title? node.items.each_with_index do |item, idx| result << (idx == 0 ? %() : '') result << %(#{item.text}) result << item.content if item.blocks? result << '' end result << %() result * EOL end def inline_anchor node case node.type when :ref %() when :xref if (path = node.attributes['path']) # QUESTION should we use refid as fallback text instead? (like the html5 backend?) %(#{node.text || path}) else linkend = node.attributes['fragment'] || node.target (text = node.text) ? %(#{text}) : %() end when :link %(#{node.text}) when :bibref target = node.target %([#{target}]) end end def author_element doc, index = nil firstname_key = index ? %(firstname_#{index}) : 'firstname' middlename_key = index ? %(middlename_#{index}) : 'middlename' lastname_key = index ? %(lastname_#{index}) : 'lastname' email_key = index ? %(email_#{index}) : 'email' result = [] result << '' result << %(#{doc.attr firstname_key}) if doc.attr? firstname_key result << %(#{doc.attr middlename_key}) if doc.attr? middlename_key result << %(#{doc.attr lastname_key}) if doc.attr? lastname_key result << %(#{doc.attr email_key}) if doc.attr? email_key result << '' result * EOL end def common_attributes id, role = nil, reftext = nil res = id ? %( id="#{id}") : '' res = %(#{res} role="#{role}") if role res = %(#{res} xreflabel="#{reftext}") if reftext res end def doctype_declaration root_tag_name %() end def document_info_element doc, info_tag_prefix super doc, info_tag_prefix, true end def lang_attribute_name 'lang' end def document_ns_attributes doc if (ns = doc.attr 'xmlns') ns.empty? ? ' xmlns="http://docbook.org/ns/docbook"' : %( xmlns="#{ns}") else nil end end end end