Sha256: efbc91806265fe980302d2530046e8e2a1b079a452e70aaeab275347b31eecbf

Contents?: true

Size: 1.53 KB

Versions: 6

Compression:

Stored size: 1.53 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2016 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-cli library for converting math formulas to MathML.
  module MathjaxNode

    # MathjaxNode is available if this constant is +true+.
    AVAILABLE = 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

    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

6 entries across 6 versions & 3 rubygems

Version Path
motion-kramdown-1.16.2 lib/kramdown/converter/math_engine/mathjaxnode.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/kramdown-1.17.0/lib/kramdown/converter/math_engine/mathjaxnode.rb
kramdown-1.17.0 lib/kramdown/converter/math_engine/mathjaxnode.rb
kramdown-1.16.2 lib/kramdown/converter/math_engine/mathjaxnode.rb
kramdown-1.16.1 lib/kramdown/converter/math_engine/mathjaxnode.rb
kramdown-1.16.0 lib/kramdown/converter/math_engine/mathjaxnode.rb