lib/rouge/lexers/javascript.rb in rouge-0.2.0 vs lib/rouge/lexers/javascript.rb in rouge-0.2.1

- old
+ new

@@ -1,8 +1,10 @@ module Rouge module Lexers class Javascript < RegexLexer + desc "JavaScript, the browser scripting language" + tag 'javascript' aliases 'js' filenames '*.js' mimetypes 'application/javascript', 'application/x-javascript', 'text/javascript', 'text/x-javascript' @@ -92,18 +94,19 @@ rule /'(\\\\|\\'|[^'])*'/, 'Literal.String.Single' end end class JSON < RegexLexer + desc "JavaScript Object Notation (json.org)" tag 'json' filenames '*.json' mimetypes 'application/json' # TODO: is this too much of a performance hit? JSON is quite simple, # so I'd think this wouldn't be too bad, but for large documents this # could mean doing two full lexes. def self.analyze_text(text) - text.lexes_cleanly?(self) ? 0.8 : 0 + return 0.8 if text =~ /\A\s*{/m && text.lexes_cleanly?(self) end state :root do mixin :whitespace # special case for empty objects