Class: Asciidoctor::Katex::StemConverterDecorator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/asciidoctor/katex/stem_converter_decorator.rb

Overview

The converter decorator that renders delimited math expressions in block and inline latexmath stem nodes after.

Instance Method Summary collapse

Constructor Details

#initialize(converter, math_renderer) ⇒ StemConverterDecorator

Returns a new instance of StemConverterDecorator.

Parameters:

  • converter (Asciidoctor::Converter)

    the decorated converter to delegate all method calls to.

  • math_renderer (#call)

    callable that accepts a math expression

    String

    and options [Hash], and returns a rendered expression [String].



14
15
16
17
18
19
# File 'lib/asciidoctor/katex/stem_converter_decorator.rb', line 14

def initialize(converter, math_renderer)
  super(converter)
  @math_renderer = math_renderer
  @block_re = regexp_from_delimiters(::Asciidoctor::BLOCK_MATH_DELIMITERS[:latexmath])
  @inline_re = regexp_from_delimiters(::Asciidoctor::INLINE_MATH_DELIMITERS[:latexmath])
end

Instance Method Details

#convert(node, transform = node.node_name, opts = {}) ⇒ String

Returns output of the converter.

Parameters:

  • node (Asciidoctor::AbstractNode)

    the node to convert.

  • transform (String, nil) (defaults to: node.node_name)

    the conversion method to call.

  • opts (Hash) (defaults to: {})

    options to pass to the converter.

Returns:

  • (String)

    output of the converter.



25
26
27
28
29
30
31
32
33
34
# File 'lib/asciidoctor/katex/stem_converter_decorator.rb', line 25

def convert(node, transform = node.node_name, opts = {})
  # Call the underlying converter.
  output = __getobj__.convert(node, transform, opts)

  if latexmath? node
    render_latexmath(output, node)
  else
    output
  end
end