Sha256: 3e1d431cea3e0eb3b92087d846b9e419ba20af8039e1964796295ae7d9920a01

Contents?: true

Size: 1.89 KB

Versions: 64

Compression:

Stored size: 1.89 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 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)

      preview_as_code = converter.options[:math_engine_opts][:preview_as_code]

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

  end

end

Version data entries

64 entries across 61 versions & 16 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/math_engine/mathjax.rb