Sha256: f20c42751ce238a8b93e19da7daeab9c73b1c88d82ef396be76ecee13d384138
Contents?: true
Size: 890 Bytes
Versions: 8
Compression:
Stored size: 890 Bytes
Contents
module MiniSyntax module Highlighter module JavaScript 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 |comment| if comment.gsub(%r(<q>(.*?)</q>), "\\1") =~ %r(</q>) comment else comment.gsub! %r(</?(b|i|em|var|code)>), "" %Q(<i>#{comment}</i>) end end code end end end end MiniSyntax.register(:javascript, MiniSyntax::Highlighter::JavaScript)
Version data entries
8 entries across 8 versions & 1 rubygems