Class: HTML::Pipeline::SVGTeX::PostFilter
- Defined in:
- lib/html/pipeline/svgtex.rb
Instance Attribute Summary
Attributes inherited from Filter
Instance Method Summary collapse
Methods inherited from Filter
#base_url, call, #current_user, #doc, #has_ancestor?, #html, #initialize, #needs, #parse_html, #repository, to_document, to_html, #validate
Constructor Details
This class inherits a constructor from HTML::Pipeline::Filter
Instance Method Details
#call ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/html/pipeline/svgtex.rb', line 76 def call doc.search('code.mathjax').each do |node| eqn = node.inner_text rsp = session.post(context[:svgtex_url], :q => eqn) if rsp.status == 200 node.parent.replace rsp.body.gsub(/margin-(left|right): 0px; /, "") else node.remove_attribute 'class' end end doc.search('code:not([class])').each do |node| eqn = node.inner_text next unless eqn.sub!(/\A\{mathjax\} /, '') rsp = session.post(context[:svgtex_url], :q => eqn) if rsp.status == 200 node.replace "<img style='display: inline; max-height: 1em;' class='mathjax' src='data:image/svg+xml;base64,#{Base64.encode64 rsp.body}' alt='#{CGI.escape_html eqn}' />" else node.inner_text = eqn end end doc end |
#session ⇒ Object
99 100 101 |
# File 'lib/html/pipeline/svgtex.rb', line 99 def session @session ||= Patron::Session.new end |