# File ../../../../../lib/review/htmlutils.rb, line 41 def escape_comment(str) str.gsub('-', '-') end
# File ../../../../../lib/review/htmlutils.rb, line 22 def escape_html(str) t = ESC str.gsub(/[&"<>]/) {|c| t[c] } end
# File ../../../../../lib/review/htmlutils.rb, line 50 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' end lexer = ops[:lexer] if ops[:lexer].present? 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? begin require 'pygments' begin Pygments.highlight(unescape_html(body), :options => options, :formatter => format, :lexer => lexer) rescue MentosError body end rescue LoadError body end end
# File ../../../../../lib/review/htmlutils.rb, line 45 def highlight? @book.config["highlight"] && @book.config["highlight"]["html"] == "pygments" end
# File ../../../../../lib/review/htmlutils.rb, line 84 def normalize_id(id) if id =~ /\A[a-z][a-z0-9_.-]*\Z/ return id elsif id =~ /\A[0-9_.-][a-z0-9_.-]*\Z/ return "id_#{id}" # dummy prefix else return "id_#{CGI.escape(id.gsub("_", "__")).gsub("%", "_").gsub("+", "-")}" # escape all end end
# File ../../../../../lib/review/htmlutils.rb, line 37 def strip_html(str) str.gsub(/<\/?[^>]*>/, "") end
# File ../../../../../lib/review/htmlutils.rb, line 30 def unescape_html(str) # FIXME better code str.gsub('"', '"').gsub('>', '>').gsub('<', '<').gsub('&', '&') end