Class: Asciidoctor::Katex::RubyKatexAdapter
- Inherits:
-
Object
- Object
- Asciidoctor::Katex::RubyKatexAdapter
- Includes:
- Utils
- Defined in:
- lib/asciidoctor/katex/ruby_katex_adapter.rb
Overview
Adapter for the KaTeX library for Ruby environment.
Instance Method Summary collapse
-
#initialize(default_options = {}) ⇒ RubyKatexAdapter
constructor
A new instance of RubyKatexAdapter.
-
#render(math, opts = {}) ⇒ String
(also: #call)
Renders the given math expression to HTML using KaTeX.
Methods included from Utils
Constructor Details
#initialize(default_options = {}) ⇒ RubyKatexAdapter
Returns a new instance of RubyKatexAdapter.
13 14 15 |
# File 'lib/asciidoctor/katex/ruby_katex_adapter.rb', line 13 def initialize( = {}) @default_options = hash_camelize() end |
Instance Method Details
#render(math, opts = {}) ⇒ String Also known as: call
Renders the given math expression to HTML using KaTeX.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/asciidoctor/katex/ruby_katex_adapter.rb', line 24 def render(math, opts = {}) opts = @default_options.merge(hash_camelize(opts)) opts[:throw_on_error] = opts[:throwOnError] opts[:error_color] = opts[:errorColor] || '#cc0000' begin ::Katex.render(math, **opts) rescue ::ExecJS::ProgramError => err raise ParseError.new(err, math) if err.to_s.start_with?('ParseError:') raise KatexError.new(err, math) end end |