Sha256: 9431ca28abcbf1b4ee7110b662b206a4b45cc2aac962c1bc26019b4820eb746e

Contents?: true

Size: 1.43 KB

Versions: 15

Compression:

Stored size: 1.43 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 javascript library for displaying math.
  #
  # Note that the javascript library itself is not include or linked, this has to be done
  # separately. Only the math content is marked up correctly.
  module Mathjax

    def self.call(converter, el, opts)
      type = el.options[:category]
      text = (el.value =~ /<|&/ ? "% <![CDATA[\n#{el.value} %]]>" : el.value)
      text.gsub!(/<\/?script>?/, '')

      preview = preview_string(converter, el, opts)

      attr = {:type => "math/tex#{type == :block ? '; mode=display' : ''}"}
      if type == :block
        preview << converter.format_as_block_html('script', attr, text, opts[:indent])
      else
        preview << converter.format_as_span_html('script', attr, text)
      end
    end

    def self.preview_string(converter, el, opts)
      preview = converter.options[:math_engine_opts][:preview]
      return '' unless preview

      preview = (preview == true ? converter.escape_html(el.value) : preview.to_s)

      if el.options[:category] == :block
        converter.format_as_block_html('div', {'class' => 'MathJax_Preview'}, preview, opts[:indent])
      else
        converter.format_as_span_html('span', {'class' => 'MathJax_Preview'}, preview)
      end
    end

  end

end

Version data entries

15 entries across 14 versions & 6 rubygems

Version Path
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjax.rb
kramdown-1.10.0 lib/kramdown/converter/math_engine/mathjax.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjax.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjax.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjax.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/mathjax.rb
logstash-codec-json-2.0.3 vendor/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/math_engine/mathjax.rb
kramdown-1.9.0 lib/kramdown/converter/math_engine/mathjax.rb
kramdown-1.8.0 lib/kramdown/converter/math_engine/mathjax.rb
kramdown-1.7.0 lib/kramdown/converter/math_engine/mathjax.rb
motion-kramdown-0.6.0 lib/kramdown/converter/math_engine/mathjax.rb
kramdown-1.6.0 lib/kramdown/converter/math_engine/mathjax.rb