Sha256: 717f390d79b410b974b4f5dd26d9cad8adac2d8dd56a0585ebe814112a80929c

Contents?: true

Size: 1.37 KB

Versions: 12

Compression:

Stored size: 1.37 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown which is licensed under the MIT.
#++
#

module Kramdown::Converter::MathEngine

  # Uses the MathJax-node library for converting math formulas to MathML.
  module MathjaxNode

    # MathjaxNode is available if this constant is +true+.
    AVAILABLE = RUBY_VERSION >= '1.9' && begin
      npm = %x{npm --global --depth=1 list MathJax-node}

      unless /MathJax-node@/ === npm.lines.drop(1).join("\n")
        npm = %x{npm --depth=1 list MathJax-node}
      end

      T2MPATH = File.join(npm.lines.first.strip, "node_modules/MathJax-node/bin/tex2mml")
      /MathJax-node@/ === npm.lines.drop(1).join("\n") && File.exist?(T2MPATH)
    rescue
      false
    end

    def self.call(converter, el, opts)
      type = el.options[:category]

      cmd = [T2MPATH]
      cmd << "--inline" unless type == :block
      cmd << "--semantics" if converter.options[:math_engine_opts][:semantics] == true
      cmd << "--notexhints" if converter.options[: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

  end

end

Version data entries

12 entries across 11 versions & 5 rubygems

Version Path
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
logstash-codec-json-2.0.3 vendor/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
kramdown-1.9.0 lib/kramdown/converter/math_engine/mathjaxnode.rb
kramdown-1.8.0 lib/kramdown/converter/math_engine/mathjaxnode.rb
kramdown-1.7.0 lib/kramdown/converter/math_engine/mathjaxnode.rb