Class: Jekyll::Spaceship::MathjaxProcessor
- Defined in:
- lib/jekyll-spaceship/processors/mathjax-processor.rb
Constant Summary
Constants inherited from Processor
Processor::DEFAULT_PRIORITY, Processor::PRIORITY_MAP
Instance Attribute Summary
Attributes inherited from Processor
#config, #exclusions, #handled, #logger, #page, #priority, #registers
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Processor
#after_exclude, #converter, #dispatch, escape_html, exclude, #ext, #filename, #initialize, #initialize_exclusions, #initialize_priority, #initialize_register, #name, #on_handle_html_block, #on_handled, #output_ext, #pre_exclude, priority, register
Constructor Details
This class inherits a constructor from Jekyll::Spaceship::Processor
Class Method Details
.config ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/jekyll-spaceship/processors/mathjax-processor.rb', line 7 def self.config { 'src' => '//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML', 'config' => { 'tex2jax' => { 'inlineMath' => [['$','$'], ['\\(','\\)']] } } } end |
Instance Method Details
#has_mathjax_expression?(doc) ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jekyll-spaceship/processors/mathjax-processor.rb', line 36 def has_mathjax_expression?(doc) doc.css('*').each do |node| if node.content.match(/(?<!\\)\$.+(?<!\\)\$/) return true end if node.content.match(/(?<!\\)\\\(.+(?<!\\)\\\)/) return true end end doc.css('script').each do |node| type = node['type'] if type and type.match(/math\/tex/) return true end end false end |
#on_handle_html(content) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jekyll-spaceship/processors/mathjax-processor.rb', line 20 def on_handle_html(content) # use nokogiri to parse html doc = Nokogiri::HTML(content) head = doc.at('head') return content if head.nil? return content if not self.has_mathjax_expression? doc self.handled = true cfg = "MathJax.Hub.Config(#{config['config'].to_json});" head.add_child("<script src=\"#{config['src']}\">#{cfg}</script>") doc.to_html end |