Module Asciidoctor::Converter
In: lib/asciidoctor/converter.rb
lib/asciidoctor/converter/base.rb
lib/asciidoctor/converter/factory.rb

A base module for defining converters that can be used to convert {AbstractNode} objects in a parsed AsciiDoc document to a backend format such as HTML or DocBook.

Implementing a converter involves:

  • including this module in a {Converter} implementation class
  • overriding the {Converter#convert} method
  • optionally associating the converter with one or more backends using the {register_for} DSL method imported by the {Config Converter::Config} module

Examples

  class TextConverter
    include Asciidoctor::Converter
    register_for 'text'
    def initialize backend, opts
      super
      outfilesuffix '.txt'
    end
    def convert node, transform = nil
      case (transform ||= node.node_name)
      when 'document'
        node.content
      when 'section'
        [node.title, node.content] * "\n\n"
      when 'paragraph'
        node.content.tr("\n", ' ') << "\n"
      else
        if transform.start_with? 'inline_'
          node.text
        else
          %(<#{transform}>\n)
        end
      end
    end
  end

  puts Asciidoctor.convert_file 'sample.adoc', backend: :text

Methods

Included Modules

Config BackendInfo

Classes and Modules

Module Asciidoctor::Converter::BackendInfo
Module Asciidoctor::Converter::Config
Class Asciidoctor::Converter::Base
Class Asciidoctor::Converter::BuiltIn
Class Asciidoctor::Converter::CompositeConverter
Class Asciidoctor::Converter::DocBook45Converter
Class Asciidoctor::Converter::DocBook5Converter
Class Asciidoctor::Converter::Factory
Class Asciidoctor::Converter::Html5Converter
Class Asciidoctor::Converter::ManPageConverter
Class Asciidoctor::Converter::TemplateConverter

Public Class methods

Mixes the {Config Converter::Config} module into any class that includes the {Converter} module.

converter - The Class that includes the {Converter} module

Returns nothing

Public: Creates a new instance of Converter

backend - The String backend format to which this converter converts. opts - An options Hash (optional, default: {})

Returns a new instance of [Converter]

Public Instance methods

Public: Converts an {AbstractNode} using the specified transform along with additional options. If a transform is not specified, implementations typically derive one from the {AbstractNode#node_name} property.

Implementations are free to decide how to carry out the conversion. In the case of the built-in converters, the tranform value is used to dispatch to a handler method. The {TemplateConverter} uses the value of the transform to select a template to render.

node - The concrete instance of AbstractNode to convert transform - An optional String transform that hints at which transformation

            should be applied to this node. If a transform is not specified,
            the transform is typically derived from the value of the
            node's node_name property. (optional, default: nil)

opts - An optional Hash of options that provide additional hints about

            how to convert the node. (optional, default: {})

Returns the [String] result

convert_with_options(node, transform = nil, opts = {})

Alias for convert

[Validate]