Class: Asciidoctor::Katex::OpalKatexAdapter
- Inherits:
-
Object
- Object
- Asciidoctor::Katex::OpalKatexAdapter
- Includes:
- Utils
- Defined in:
- lib/asciidoctor/katex/opal_katex_adapter.rb
Overview
Adapter for the KaTeX library for Opal/JS environment.
Instance Method Summary collapse
-
#initialize(default_options = {}, katex_object = nil) ⇒ OpalKatexAdapter
constructor
A new instance of OpalKatexAdapter.
-
#render(math, opts = {}) ⇒ String
(also: #call)
Renders the given math expression to HTML using KaTeX.
Methods included from Utils
Constructor Details
#initialize(default_options = {}, katex_object = nil) ⇒ OpalKatexAdapter
Returns a new instance of OpalKatexAdapter.
14 15 16 17 |
# File 'lib/asciidoctor/katex/opal_katex_adapter.rb', line 14 def initialize( = {}, katex_object = nil) @default_options = hash_camelize() @katex_object = katex_object || `katex` end |
Instance Method Details
#render(math, opts = {}) ⇒ String Also known as: call
Renders the given math expression to HTML using KaTeX.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/asciidoctor/katex/opal_katex_adapter.rb', line 26 def render(math, opts = {}) opts = @default_options.merge(hash_camelize(opts)) begin `#{@katex_object}.renderToString(#{math}, #{opts}.$$smap)` rescue ::JS::Error => err # "#{err}" is really needed for Opal/JS, #to_s returns a different string. # rubocop:disable UnneededInterpolation raise ParseError.new(err, math) if "#{err}".start_with?('ParseError:') raise KatexError.new(err, math) end end |