4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/minisyntax/highlighter/javascript.rb', line 4
def self.highlight(code)
keywords = %w(break continue do for import new this void case default else function in return typeof while comment delete export if label switch var with)
keywords += %w(catch enum throw class extends try const finally debugger super)
code.gsub! /\b(#{keywords.join('|')})\b/, "<em>\\1</em>"
code.gsub! /\b([A-Z_][a-zA-Z0-9_]+)\b/, "<b>\\1</b>"
code.gsub! /("(.*?)"|'.*?')/, "<q>\\1</q>"
code.gsub! %r((//.*?)$) do ||
if .gsub(%r(<q>(.*?)</q>), "\\1") =~ %r(</q>)
else
.gsub! %r(</?(b|i|em|var|code)>), ""
%Q(<i>#{}</i>)
end
end
code
end
|