lib/review/htmlutils.rb in review-5.3.0 vs lib/review/htmlutils.rb in review-5.4.0
- old
+ new
@@ -7,11 +7,11 @@
# the GNU LGPL, Lesser General Public License version 2.1.
#
begin
require 'cgi/escape'
-rescue
+rescue StandardError
require 'cgi/util'
end
module ReVIEW
module HTMLUtils
@@ -58,17 +58,17 @@
end
def highlight_pygments(ops)
body = ops[:body] || ''
format = ops[:format] || ''
- if ops[:lexer].present?
- lexer = ops[:lexer]
- elsif @book.config['highlight'] && @book.config['highlight']['lang']
- lexer = @book.config['highlight']['lang'] # default setting
- else
- lexer = 'text'
- end
+ lexer = if ops[:lexer].present?
+ ops[:lexer]
+ elsif @book.config['highlight'] && @book.config['highlight']['lang']
+ @book.config['highlight']['lang'] # default setting
+ else
+ 'text'
+ end
options = { nowrap: true, noclasses: true }
if ops[:linenum]
options[:nowrap] = false
options[:linenos] = 'inline'
end
@@ -91,17 +91,17 @@
end
end
def highlight_rouge(ops)
body = ops[:body] || ''
- if ops[:lexer].present?
- lexer = ops[:lexer]
- elsif @book.config['highlight'] && @book.config['highlight']['lang']
- lexer = @book.config['highlight']['lang'] # default setting
- else
- lexer = 'text'
- end
+ lexer = if ops[:lexer].present?
+ ops[:lexer]
+ elsif @book.config['highlight'] && @book.config['highlight']['lang']
+ @book.config['highlight']['lang'] # default setting
+ else
+ 'text'
+ end
# format = ops[:format] || ''
first_line_num = 1 ## default
if ops[:options] && ops[:options][:linenostart]
first_line_num = ops[:options][:linenostart]
@@ -127,12 +127,12 @@
formatter.format(lexer.lex(body))
end
def normalize_id(id)
- if id =~ /\A[a-z][a-z0-9_.-]*\Z/i
+ if /\A[a-z][a-z0-9_.-]*\Z/i.match?(id)
id
- elsif id =~ /\A[0-9_.-][a-z0-9_.-]*\Z/i
+ elsif /\A[0-9_.-][a-z0-9_.-]*\Z/i.match?(id)
"id_#{id}" # dummy prefix
else
"id_#{CGI.escape(id.gsub('_', '__')).tr('%', '_').tr('+', '-')}" # escape all
end
end