Class: Sourcerer::PlainTextConverter

Inherits:
Asciidoctor::Converter::Base
  • Object
show all
Defined in:
lib/sourcerer/plaintext_converter.rb

Overview

A custom Asciidoctor converter that outputs plain text. It is registered for the "plaintext" backend and can be used to extract the raw text content or attributes from an AsciiDoc document.

Instance Method Summary collapse

Instance Method Details

#convert(node, _transform = nil, _opts = {}) ⇒ String

The main entry point for the converter. It is called by Asciidoctor to convert a node.

Parameters:

  • node (Asciidoctor::AbstractNode)
    The node to convert.
  • _transform (String) (defaults to: nil)
    The transform to apply (unused).
  • _opts (Hash) (defaults to: {})
    Options for the conversion (unused).

Returns:

  • (String)
    The converted plain text output.


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sourcerer/plaintext_converter.rb', line 22

def convert node, _transform = nil, _opts = {}
  if respond_to?("convert_#{node.node_name}", true)
    send("convert_#{node.node_name}", node)
  elsif node.respond_to?(:content)
    node.content.to_s
  elsif node.respond_to?(:text)
    node.text.to_s
  else
    ''
  end
end