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