Module: Kramdown::Converter::MathEngine::MathjaxNode
- Defined in:
- lib/kramdown/converter/math_engine/mathjaxnode.rb
Overview
Uses the mathjax-node-cli library for converting math formulas to MathML.
Constant Summary collapse
- VERSION =
'1.0.0'- AVAILABLE =
MathjaxNode is available if this constant is
true. begin %x{node --version}[1..-2] >= '4.5' rescue begin %x{nodejs --version}[1..-2] >= '4.5' rescue false end end && begin npm = %x{npm --global --depth=1 list mathjax-node-cli 2>&1} unless /mathjax-node-cli@/ === npm.lines.drop(1).join("\n") npm = %x{npm --depth=1 list mathjax-node-cli 2>&1} end T2MPATH = File.join(npm.lines.first.strip, "node_modules/mathjax-node-cli/bin/tex2mml") /mathjax-node-cli@/ === npm.lines.drop(1).join("\n") && File.exist?(T2MPATH) rescue false end
Class Method Summary collapse
Class Method Details
.call(converter, el, opts) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kramdown/converter/math_engine/mathjaxnode.rb', line 46 def self.call(converter, el, opts) type = el.[:category] cmd = [T2MPATH] cmd << "--inline" unless type == :block cmd << "--semantics" if converter.[:math_engine_opts][:semantics] == true cmd << "--notexhints" if converter.[:math_engine_opts][:texhints] == false result = IO.popen(cmd << el.value).read.strip attr = el.attr.dup attr.delete('xmlns') attr.delete('display') result.insert("<math".length, converter.html_attributes(attr)) (type == :block ? "#{' '*opts[:indent]}#{result}\n" : result) end |