module Asciidoctor::Converter

A module for defining converters that are used to convert {AbstractNode} objects in a parsed AsciiDoc document to an output (aka backend) format such as HTML or DocBook.

A {Converter} is typically instantiated each time an AsciiDoc document is processed (i.e., parsed and converted). Implementing a custom converter entails:

Examples

class TextConverter
  include Asciidoctor::Converter
  register_for 'text'
  def initialize *args
    super
    outfilesuffix '.txt'
  end
  def convert node, transform = node.node_name, opts = nil
    case transform
    when 'document', 'section'
      [node.title, node.content].join %(\n\n)
    when 'paragraph'
      (node.content.tr ?\n, ' ') << ?\n
    else
      (transform.start_with? 'inline_') ? node.text : node.content
    end
  end
end
puts Asciidoctor.convert_file 'sample.adoc', backend: :text, safe: :safe

class Html5Converter < (Asciidoctor::Converter.for 'html5')
  register_for 'html5'
  def convert_paragraph node
    %(<p>#{node.content}</p>)
  end
end
puts Asciidoctor.convert_file 'sample.adoc', safe: :safe