Module: Kramdown::Converter::MathEngine::Mathjax
- Defined in:
- lib/kramdown/converter/math_engine/mathjax.rb
Overview
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.
Class Method Summary collapse
Class Method Details
.call(converter, el, opts) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kramdown/converter/math_engine/mathjax.rb', line 18 def self.call(converter, el, opts) type = el.[: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 |
.preview_string(converter, el, opts) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kramdown/converter/math_engine/mathjax.rb', line 33 def self.preview_string(converter, el, opts) preview = converter.[:math_engine_opts][:preview] return '' unless preview preview = (preview == true ? converter.escape_html(el.value) : preview.to_s) preview_as_code = converter.[:math_engine_opts][:preview_as_code] if el.[: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 |