lib/dq-readability.rb in dq-readability-1.0.5 vs lib/dq-readability.rb in dq-readability-1.0.6

- old
+ new

@@ -16,11 +16,12 @@ :clean_conditionally => true, :remove_empty_nodes => true, :min_image_width => 130, :min_image_height => 80, :ignore_image_format => [], - :bypass => false + :bypass => false, + :math => false }.freeze REGEXES = { :unlikelyCandidatesRe => /combx|comment|community|disqus|extra|foot|header|menu|remark|rss|shoutbox|sidebar|sponsor|ad-break|agegate|pagination|pager|popup/i, :okMaybeItsACandidateRe => /and|article|body|column|main|shadow/i, @@ -51,10 +52,11 @@ @remove_unlikely_candidates = @options[:remove_unlikely_candidates] @weight_classes = @options[:weight_classes] @clean_conditionally = @options[:clean_conditionally] @best_candidate_has_image = true @bypass = @options[:bypass] + @math = @options[:math] make_html end def prepare_candidates @html.css("script, style").each { |i| i.remove } @@ -552,11 +554,25 @@ s = Nokogiri::XML::Node::SaveOptions save_opts = s::NO_DECLARATION | s::NO_EMPTY_TAGS | s::AS_XHTML html = node.serialize(:save_with => save_opts) # Get rid of duplicate whitespace - html = "<head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>" + "\n" + html.gsub(/[\r\n\f]+/, "\n" ) - + if @math == false + html = "<head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>" + "\n" + html.gsub(/[\r\n\f]+/, "\n" ) + else + head = <<HTML +<head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'> + <script type='text/x-mathjax-config'> + MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]}}); + </script> + <script type='text/javascript' + src='http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'> + </script> +</head> +HTML + + html = head + "\n" + html.gsub(/[\r\n\f]+/, "\n" ) + end # get rid of incompitable characters if html.encode('utf-8').include?('Â') html = html.encode('utf-8').gsub('Â',' ') end