lib/review/htmlutils.rb in review-2.0.0.beta1 vs lib/review/htmlutils.rb in review-2.0.0

- old
+ new

@@ -6,10 +6,11 @@ # This program is free software. # You can distribute or modify this program under the terms of # the GNU LGPL, Lesser General Public License version 2.1. # +require 'cgi/util' module ReVIEW module HTMLUtils ESC = { '&' => '&amp;', @@ -22,10 +23,11 @@ t = ESC str.gsub(/[&"<>]/) {|c| t[c] } end alias_method :escape, :escape_html + alias_method :h, :escape_html def unescape_html(str) # FIXME better code str.gsub('&quot;', '"').gsub('&gt;', '>').gsub('&lt;', '<').gsub('&amp;', '&') end @@ -38,16 +40,20 @@ def escape_comment(str) str.gsub('-', '&#45;') end - def highlight_pygments? - @book.config["pygments"].present? || - @book.config["highlight"] && @book.config["highlight"]["html"] == "pygments" + def highlight? + @book.config["highlight"] && + @book.config["highlight"]["html"] == "pygments" end def highlight(ops) + if @book.config["pygments"].present? + raise ReVIEW::ConfigError, "'pygments:' in config.yml is obsoleted." + end + body = ops[:body] || '' if @book.config["highlight"] && @book.config["highlight"]["lang"] lexer = @book.config["highlight"]["lang"] # default setting else lexer = 'text' @@ -56,11 +62,11 @@ format = ops[:format] || '' options = {:nowrap => true, :noclasses => true} if ops[:options] && ops[:options].kind_of?(Hash) options.merge!(ops[:options]) end - return body if !highlight_pygments? + return body if !highlight? begin require 'pygments' begin Pygments.highlight( @@ -70,11 +76,11 @@ :lexer => lexer) rescue MentosError body end rescue LoadError - body + body end end def normalize_id(id) if id =~ /\A[a-z][a-z0-9_.-]*\Z/i @@ -85,6 +91,6 @@ return "id_#{CGI.escape(id.gsub("_", "__")).gsub("%", "_").gsub("+", "-")}" # escape all end end end -end # module ReVIEW +end # module ReVIEW