From 996de449cd5130ca3f073ad241464359c4d6d4fa Mon Sep 17 00:00:00 2001 From: murphy Date: Sat, 22 Oct 2005 01:16:34 +0000 Subject: demo/demo_server.rb: Debug mode. tokens.rb: orig_each alias deleted; using super now. scanners/ruby.rb: experimental Regexp/Fancy string recognition for "method /.../" cases. --- demo/demo_server.rb | 34 ++++++++++++++++++++++++++-------- lib/coderay/scanners/ruby.rb | 3 ++- lib/coderay/tokens.rb | 7 +++---- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/demo/demo_server.rb b/demo/demo_server.rb index cc3db2b..0972de9 100644 --- a/demo/demo_server.rb +++ b/demo/demo_server.rb @@ -1,10 +1,24 @@ # CodeRay dynamic highlighter -# -# Usage: start this and your browser. -# -# Go to http://localhost:49374/? -# (mnemonic: 49374 = Four-Nine-Three-Seven-Four = For No Token Shall Fall) -# and you should get the highlighted version. + +unless ARGV.grep(/-[hv]|--(help|version)/).empty? + puts <<-USAGE +CodeRay Server 0.5 +$Id$ + +Usage: + 1) Start this and your browser. + 2) Go to http://localhost:2468/? + and you should get the highlighted version. + +Parameters: + -d Debug mode; reload CodeRay engine for every file. + (prepare for MANY "already initialized" and "method redefined" + messages - ingore it.) + + ... More to come. + USAGE + exit +end require 'webrick' require 'pathname' @@ -29,7 +43,7 @@ require 'coderay' class CodeRayServlet < WEBrick::HTTPServlet::AbstractServlet STYLE = 'style="font-family: sans-serif; color: navy;"' - BANNER = '

HIghlighted by CodeRay

' + BANNER = '

Highlighted by CodeRay

' def do_GET req, res q = req.query_string || '' @@ -59,6 +73,10 @@ class CodeRayServlet < WEBrick::HTTPServlet::AbstractServlet page << "#{BANNER}" elsif File.exist? path + if $DEBUG + $".delete_if { |f| f =~ /coderay/ } + require 'coderay' + end div = CodeRay.scan_file(path).html :tab_width => 8, :wrap => :div div.replace <<-DIV
@@ -74,7 +92,7 @@ class CodeRayServlet < WEBrick::HTTPServlet::AbstractServlet end end -# this is taken by "qip_msgd" - I don't know that. +# This port is taken by "qip_msgd" - I don't know that. Do you? module CodeRay PORT = 0xC0DE / 20 end diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 1ceb3d5..4cb1e58 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -213,7 +213,8 @@ module CodeRay module Scanners state = DEF_NEW_STATE[match] end end - fancy_allowed = regexp_allowed = REGEXP_ALLOWED[match] + ## experimental! + fancy_allowed = regexp_allowed = :set if REGEXP_ALLOWED[match] or check(/\s+(?:%\S|\/\S)/) elsif match = scan(/ ['"] /mx) tokens << [:open, :string] diff --git a/lib/coderay/tokens.rb b/lib/coderay/tokens.rb index 9318844..9342897 100644 --- a/lib/coderay/tokens.rb +++ b/lib/coderay/tokens.rb @@ -94,15 +94,14 @@ module CodeRay false end - alias :orig_each :each # Iterates over all tokens. # # If a filter is given, only tokens of that kind are yielded. def each kind_filter = nil, &block unless kind_filter - orig_each(&block) + super(&block) else - orig_each do |text, kind| + super do |text, kind| next unless kind == kind_filter yield text, kind end @@ -115,7 +114,7 @@ module CodeRay # Example: # tokens.each_text_token { |text, kind| text.replace html_escape(text) } def each_text_token - orig_each do |text, kind| + each do |text, kind| next unless text.respond_to? :to_str yield text, kind end -- cgit v1.2.1