Module: Thredded::MarkdownKatex::Kramdown::KatexConverter

Defined in:
lib/thredded/markdown_katex/kramdown/katex_converter.rb

Overview

The KaTeX converter engine for Kramdown.

Class Method Summary collapse

Class Method Details

.call(converter, el, opts) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/thredded/markdown_katex/kramdown/katex_converter.rb', line 12

def self.call(converter, el, opts)
  display_mode = el.options[:category] == :block
  result = ::Katex.render(
    el.value,
    display_mode: display_mode,
    throw_on_error: false,
    **converter.options[:math_engine_opts]
  )
  attr = el.attr.dup
  attr.delete('xmlns')
  attr.delete('display')
  result
    .insert(result =~ /[[:space:]>]/, converter.html_attributes(attr))
  result = "#{' ' * opts[:indent]}#{result}\n" if display_mode
  result
end