module Kramdown::Converter::MathEngine::Mathjax

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.

Public Class Methods

call(converter, el, opts) click to toggle source
   # File lib/kramdown/converter/math_engine/mathjax.rb
17 def self.call(converter, el, opts)
18   type = el.options[:category]
19   text = (el.value =~ /<|&/ ? "% <![CDATA[\n#{el.value} %]]>" : el.value)
20   text.gsub!(/<\/?script>?/, '')
21 
22   preview = preview_string(converter, el, opts)
23 
24   attr = {:type => "math/tex#{type == :block ? '; mode=display' : ''}"}
25   if type == :block
26     preview << converter.format_as_block_html('script', attr, text, opts[:indent])
27   else
28     preview << converter.format_as_span_html('script', attr, text)
29   end
30 end
preview_string(converter, el, opts) click to toggle source
   # File lib/kramdown/converter/math_engine/mathjax.rb
32 def self.preview_string(converter, el, opts)
33   preview = converter.options[:math_engine_opts][:preview]
34   return '' unless preview
35 
36   preview = (preview == true ? converter.escape_html(el.value) : preview.to_s)
37 
38   preview_as_code = converter.options[:math_engine_opts][:preview_as_code]
39 
40   if el.options[:category] == :block
41     if preview_as_code
42       converter.format_as_block_html('pre', {'class' => 'MathJax_Preview'},
43                                      converter.format_as_span_html('code', {}, preview),
44                                      opts[:indent])
45     else
46       converter.format_as_block_html('div', {'class' => 'MathJax_Preview'}, preview,
47                                      opts[:indent])
48     end
49   else
50     converter.format_as_span_html(preview_as_code ? 'code' : 'span',
51                                   {'class' => 'MathJax_Preview'}, preview)
52   end
53 end