From 562da3b96f5cdb97eaf16ee87a2b142064b31110 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 1 Mar 2012 23:07:06 +0000 Subject: [PATCH] google charts math tag fallback --- lib/wikicloth/extensions/math.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/wikicloth/extensions/math.rb b/lib/wikicloth/extensions/math.rb index 6355808..20a18df 100644 --- a/lib/wikicloth/extensions/math.rb +++ b/lib/wikicloth/extensions/math.rb @@ -7,25 +7,30 @@ class MathExtension < Extension blahtex_png_path = @options[:blahtex_png_path] || '/tmp' blahtex_options = @options[:blahtex_options] || '--texvc-compatible-commands --mathml-version-1-fonts --disallow-plane-1 --spacing strict' - if File.exists?(blahtex_path) + if File.exists?(blahtex_path) && @options[:math_formatter] != :google begin + # pass tex markup to blahtex response = `echo '#{buffer.element_content}' | #{blahtex_path} #{blahtex_options} --png --mathml --png-directory #{blahtex_png_path}` xml_response = REXML::Document.new(response).root if @options[:blahtex_html_prefix] + # render as embedded image file_md5 = xml_response.elements["png/md5"].text return "" else + # render as mathml html = xml_response.elements["mathml/markup"].text return "#{xml_response.elements["mathml/markup"].children.to_s}" end rescue => err + # blahtex error return "#{I18n.t("unable to parse mathml", :error => err)}" end else - return "#{I18n.t("blahtex binary not found", :path => blahtex_path)}" + # if blahtex does not exist fallback to google charts api + encoded_string = URI.escape(buffer.element_content, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) + return "" end - end end