60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/review/htmlutils.rb', line 60
def highlight_pygments(ops)
body = ops[:body] || ''
format = ops[:format] || ''
lexer = if ops[:lexer].present?
ops[:lexer]
elsif @book.config['highlight'] && @book.config['highlight']['lang']
@book.config['highlight']['lang']
else
'text'
end
options = { nowrap: true, noclasses: true }
if ops[:linenum]
options[:nowrap] = false
options[:linenos] = 'inline'
end
if ops[:options] && ops[:options].is_a?(Hash)
options.merge!(ops[:options])
end
begin
require 'pygments'
begin
Pygments.highlight(body,
options: options,
formatter: format,
lexer: lexer)
rescue MentosError
body
end
rescue LoadError
body
end
end
|