Class: Daimon::Markdown::Plugin::Math

Inherits:
Base
  • Object
show all
Defined in:
lib/daimon/markdown/plugin/math.rb

Instance Attribute Summary

Attributes inherited from Base

#context, #doc, #node, #result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Daimon::Markdown::Plugin::Base

Class Method Details

.script_tagObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/daimon/markdown/plugin/math.rb', line 7

def self.script_tag
  tag = <<~TAG
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {inlineMath: [['$','$']]},
      asciimath2jax: {delimiters: [['`', '`']]},
      TeX: {extensions: ["mhchem.js"]}
    });
  </script>
  <script type="text/javascript"
          async
          src="https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js?config=TeX-MML-AM_CHTML">
  </script>
  TAG
  if tag.respond_to?(:html_safe)
    tag.html_safe
  else
    tag
  end
end

Instance Method Details

#call(expression) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/daimon/markdown/plugin/math.rb', line 28

def call(expression)
  if expression.start_with?("$$")
    node.parent.replace(%Q(<div class="math">#{expression}</div>))
  else
    result[:plugins] << expression
  end
end