From 746ca8a4518c67690d3a39267153aeea4e4da589 Mon Sep 17 00:00:00 2001 From: Jordi Massaguer Pla Date: Thu, 17 Jan 2013 17:04:00 +0100 Subject: fix license file name into gemspec --- coderay.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderay.gemspec b/coderay.gemspec index e686035..bebfd60 100644 --- a/coderay.gemspec +++ b/coderay.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| readme_file = 'README_INDEX.rdoc' - s.files = `git ls-files -- lib/* test/functional/* Rakefile #{readme_file} LICENSE`.split("\n") + s.files = `git ls-files -- lib/* test/functional/* Rakefile #{readme_file} MIT-LICENSE`.split("\n") s.test_files = `git ls-files -- test/functional/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } s.require_paths = ['lib'] -- cgit v1.2.1 From e7ca33a69aefc44a0b100eeeaffc77f6376dbf5a Mon Sep 17 00:00:00 2001 From: Joey Geiger Date: Fri, 8 Feb 2013 14:43:37 -0600 Subject: Add License to gemspec --- coderay.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/coderay.gemspec b/coderay.gemspec index bebfd60..328b94c 100644 --- a/coderay.gemspec +++ b/coderay.gemspec @@ -17,6 +17,8 @@ Gem::Specification.new do |s| s.summary = 'Fast syntax highlighting for selected languages.' s.description = 'Fast and easy syntax highlighting for selected languages, written in Ruby. Comes with RedCloth integration and LOC counter.' + s.license = 'MIT' + s.platform = Gem::Platform::RUBY s.required_ruby_version = '>= 1.8.6' -- cgit v1.2.1 From b922d1d976674fca878025ccae482ac2a20b664e Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Wed, 13 Feb 2013 08:37:00 +0100 Subject: Update Changes.textile --- Changes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changes.textile b/Changes.textile index 42af2c8..1c927ce 100644 --- a/Changes.textile +++ b/Changes.textile @@ -4,7 +4,7 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release {{toc}} -h2. Next Version +h2. Changes in 1.0.8 * add @:string/:char@, remove @:regexp/:function@ color from Terminal encoder [GH #29, thanks to Kyrylo Silin] * allow @-@ in line number anchor prefix for HTML encoder [GH #32, thanks to shurizzle] -- cgit v1.2.1 From b71ff6a0f0c0e82e32c8fdbcf9247def8e76f6ec Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 14:54:43 +0100 Subject: do not write to disk in benchmarking --- bench/bench.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/bench.rb b/bench/bench.rb index 45dc5b0..1889eed 100644 --- a/bench/bench.rb +++ b/bench/bench.rb @@ -108,7 +108,7 @@ N.times do $file_created = here('test.' + ($dump_output ? 'dump' : $hl.file_extension)) File.open($file_created, 'wb') do |f| - f.write $o + # f.write $o end Dir.chdir(here) do FileUtils.copy 'test.dump', 'example.dump' if $dump_output -- cgit v1.2.1 From 15c314d8c67272aa3385e21d38db7bf08358c1eb Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 16:11:03 +0100 Subject: fix #106: re-introduce highlightinging of { key: value } in Ruby 1.9 hashes --- Changes.textile | 4 ++++ lib/coderay/scanners/ruby.rb | 31 ++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Changes.textile b/Changes.textile index 1c927ce..02c7b10 100644 --- a/Changes.textile +++ b/Changes.textile @@ -4,6 +4,10 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release {{toc}} +h2. Changes in 1.0.9 + +* Fix Ruby scanner: Ruby 1.9 hash syntax @{ key: value }@ is highlighted correctly. [GH #106, thanks to Seth Vargo] + h2. Changes in 1.0.8 * add @:string/:char@, remove @:regexp/:function@ color from Terminal encoder [GH #29, thanks to Kyrylo Silin] diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 2be98a6..b26c387 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -94,18 +94,27 @@ module Scanners if !method_call_expected && match = scan(unicode ? /#{patterns::METHOD_NAME}/uo : /#{patterns::METHOD_NAME}/o) - value_expected = false - kind = patterns::IDENT_KIND[match] - if kind == :ident - if match[/\A[A-Z]/] && !(match[/[!?]$/] || match?(/\(/)) - kind = :constant + + if value_expected != :colon_expected && scan(/:(?= )/) + value_expected = true + encoder.text_token match, :key + encoder.text_token ':', :operator + else + value_expected = false + kind = patterns::IDENT_KIND[match] + if kind == :ident + if match[/\A[A-Z]/] && !(match[/[!?]$/] || match?(/\(/)) + kind = :constant + end + elsif kind == :keyword + state = patterns::KEYWORD_NEW_STATE[match] + if patterns::KEYWORDS_EXPECTING_VALUE[match] + value_expected = match == 'when' ? :colon_expected : true + end end - elsif kind == :keyword - state = patterns::KEYWORD_NEW_STATE[match] - value_expected = true if patterns::KEYWORDS_EXPECTING_VALUE[match] + value_expected = true if !value_expected && check(/#{patterns::VALUE_FOLLOWS}/o) + encoder.text_token match, kind end - value_expected = true if !value_expected && check(/#{patterns::VALUE_FOLLOWS}/o) - encoder.text_token match, kind elsif method_call_expected && match = scan(unicode ? /#{patterns::METHOD_AFTER_DOT}/uo : @@ -213,7 +222,7 @@ module Scanners encoder.text_token match, :integer elsif match = scan(/ %=? | <(?:<|=>?)? | \? /x) - value_expected = true + value_expected = match == '?' ? :colon_expected : true encoder.text_token match, :operator elsif match = scan(/`/) -- cgit v1.2.1 From aa01f05af6cc59f9b23a717c730326841e335d9f Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 17:33:09 +0100 Subject: improve support for Unicode non-alphanumeric characters in Ruby names --- lib/coderay/scanners/ruby/patterns.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb index a52198e..6a9eebe 100644 --- a/lib/coderay/scanners/ruby/patterns.rb +++ b/lib/coderay/scanners/ruby/patterns.rb @@ -34,9 +34,9 @@ module Scanners add(%w[ undef ], :undef_expected). add(%w[ alias ], :alias_expected). add(%w[ class module ], :module_expected) - - IDENT = 'ä'[/[[:alpha:]]/] == 'ä' ? /[[:alpha:]_][[:alnum:]_]*/ : /[^\W\d]\w*/ - + + IDENT = 'ä'[/[[:alpha:]]/] == 'ä' ? Regexp.new('[[:alpha:]_[^\0-\177]][[:alnum:]_[^\0-\177]]*') : /[^\W\d]\w*/ + METHOD_NAME = / #{IDENT} [?!]? /ox METHOD_NAME_OPERATOR = / \*\*? # multiplication and power -- cgit v1.2.1 From 81c968848625bb79687ff75e1d7796aae858e99f Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 17:36:33 +0100 Subject: whitespace --- lib/coderay/scanners/ruby/patterns.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/coderay/scanners/ruby/patterns.rb b/lib/coderay/scanners/ruby/patterns.rb index a52198e..2069e36 100644 --- a/lib/coderay/scanners/ruby/patterns.rb +++ b/lib/coderay/scanners/ruby/patterns.rb @@ -1,9 +1,9 @@ # encoding: utf-8 module CodeRay module Scanners - + module Ruby::Patterns # :nodoc: all - + KEYWORDS = %w[ and def end in or unless begin defined? ensure module redo super until @@ -12,7 +12,7 @@ module Scanners while alias class elsif if not return undef yield ] - + # See http://murfy.de/ruby-constants. PREDEFINED_CONSTANTS = %w[ nil true false self @@ -24,11 +24,11 @@ module Scanners RUBY_PLATFORM RUBY_RELEASE_DATE RUBY_REVISION RUBY_VERSION __FILE__ __LINE__ __ENCODING__ ] - + IDENT_KIND = WordList.new(:ident). add(KEYWORDS, :keyword). add(PREDEFINED_CONSTANTS, :predefined_constant) - + KEYWORD_NEW_STATE = WordList.new(:initial). add(%w[ def ], :def_expected). add(%w[ undef ], :undef_expected). @@ -57,25 +57,25 @@ module Scanners GLOBAL_VARIABLE = / \$ (?: #{IDENT} | [1-9]\d* | 0\w* | [~&+`'=\/,;_.<>!@$?*":\\] | -[a-zA-Z_0-9] ) /ox PREFIX_VARIABLE = / #{GLOBAL_VARIABLE} | #{OBJECT_VARIABLE} /ox VARIABLE = / @?@? #{IDENT} | #{GLOBAL_VARIABLE} /ox - + QUOTE_TO_TYPE = { '`' => :shell, '/'=> :regexp, } QUOTE_TO_TYPE.default = :string - + REGEXP_MODIFIERS = /[mousenix]*/ - + DECIMAL = /\d+(?:_\d+)*/ OCTAL = /0_?[0-7]+(?:_[0-7]+)*/ HEXADECIMAL = /0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*/ BINARY = /0b[01]+(?:_[01]+)*/ - + EXPONENT = / [eE] [+-]? #{DECIMAL} /ox FLOAT_SUFFIX = / #{EXPONENT} | \. #{DECIMAL} #{EXPONENT}? /ox FLOAT_OR_INT = / #{DECIMAL} (?: #{FLOAT_SUFFIX} () )? /ox NUMERIC = / (?: (?=0) (?: #{OCTAL} | #{HEXADECIMAL} | #{BINARY} ) | #{FLOAT_OR_INT} ) /ox - + SYMBOL = / : (?: @@ -85,7 +85,7 @@ module Scanners ) /ox METHOD_NAME_OR_SYMBOL = / #{METHOD_NAME_EX} | #{SYMBOL} /ox - + SIMPLE_ESCAPE = / [abefnrstv] | [0-7]{1,3} @@ -110,7 +110,7 @@ module Scanners | \\ #{ESCAPE} ) /mox - + # NOTE: This is not completely correct, but # nobody needs heredoc delimiters ending with \n. HEREDOC_OPEN = / @@ -122,13 +122,13 @@ module Scanners ( [^\n]*? ) \3 # $4 = delim ) /mx - + RUBYDOC = / =begin (?!\S) .*? (?: \Z | ^=end (?!\S) [^\n]* ) /mx - + DATA = / __END__$ .*? @@ -136,7 +136,7 @@ module Scanners /mx RUBYDOC_OR_DATA = / #{RUBYDOC} | #{DATA} /xo - + # Checks for a valid value to follow. This enables # value_expected in method calls without parentheses. VALUE_FOLLOWS = / -- cgit v1.2.1 From 7f664a608f902a2e1623b9e066386599c741e202 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 17:51:03 +0100 Subject: cleanup: value_expected should be boolean --- lib/coderay/scanners/ruby.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index b26c387..8cd89f0 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -128,9 +128,9 @@ module Scanners value_expected = check(/#{patterns::VALUE_FOLLOWS}/o) # OPERATORS # - elsif !method_call_expected && match = scan(/ (\.(?!\.)|::) | (?: \.\.\.? | ==?=? | [,\(\[\{] )() | [\)\]\}] /x) + elsif !method_call_expected && match = scan(/ (\.(?!\.)|::) | ( \.\.\.? | ==?=? | [,\(\[\{] ) | [\)\]\}] /x) method_call_expected = self[1] - value_expected = !method_call_expected && self[2] + value_expected = !method_call_expected && !!self[2] if inline_block_stack case match when '{' -- cgit v1.2.1 From cbbd74f318ee762d5bd7dec2b86e1c00523de9dd Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 20:47:48 +0100 Subject: match Ruby 1.9 hash syntax even without space after colon --- lib/coderay/scanners/ruby.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/coderay/scanners/ruby.rb b/lib/coderay/scanners/ruby.rb index 8cd89f0..c5cf1e2 100644 --- a/lib/coderay/scanners/ruby.rb +++ b/lib/coderay/scanners/ruby.rb @@ -95,13 +95,13 @@ module Scanners match = scan(unicode ? /#{patterns::METHOD_NAME}/uo : /#{patterns::METHOD_NAME}/o) - if value_expected != :colon_expected && scan(/:(?= )/) + kind = patterns::IDENT_KIND[match] + if kind == :ident && value_expected != :colon_expected && scan(/:(?!:)/) value_expected = true encoder.text_token match, :key encoder.text_token ':', :operator else value_expected = false - kind = patterns::IDENT_KIND[match] if kind == :ident if match[/\A[A-Z]/] && !(match[/[!?]$/] || match?(/\(/)) kind = :constant -- cgit v1.2.1 From d0b9a7cc6f78758a35b574f149c2fc3e9a2a8455 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 21:40:48 +0100 Subject: fix #83 (XML DTD) --- Changes.textile | 1 + lib/coderay/scanners/html.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changes.textile b/Changes.textile index 02c7b10..877103a 100644 --- a/Changes.textile +++ b/Changes.textile @@ -7,6 +7,7 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release h2. Changes in 1.0.9 * Fix Ruby scanner: Ruby 1.9 hash syntax @{ key: value }@ is highlighted correctly. [GH #106, thanks to Seth Vargo] +* Fix HTML scanner: Accept DTDs. [GH #83] h2. Changes in 1.0.8 diff --git a/lib/coderay/scanners/html.rb b/lib/coderay/scanners/html.rb index 49c346d..3ba3b79 100644 --- a/lib/coderay/scanners/html.rb +++ b/lib/coderay/scanners/html.rb @@ -101,7 +101,7 @@ module Scanners when :initial if match = scan(/|.*)/m) encoder.text_token match, :comment - elsif match = scan(/|.*)/m) + elsif match = scan(/|.*)|\]>/m) encoder.text_token match, :doctype elsif match = scan(/<\?xml(?:.*?\?>|.*)/m) encoder.text_token match, :preprocessor -- cgit v1.2.1 From d666db48604418eed5aaf76669375e2c9b2bd101 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 21:49:50 +0100 Subject: fix #40 (PHP unicode) --- Changes.textile | 1 + lib/coderay/scanners/php.rb | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Changes.textile b/Changes.textile index 877103a..dc64792 100644 --- a/Changes.textile +++ b/Changes.textile @@ -8,6 +8,7 @@ h2. Changes in 1.0.9 * Fix Ruby scanner: Ruby 1.9 hash syntax @{ key: value }@ is highlighted correctly. [GH #106, thanks to Seth Vargo] * Fix HTML scanner: Accept DTDs. [GH #83] +* Fix PHP scanner: Accept Unicode. [GH #40] h2. Changes in 1.0.8 diff --git a/lib/coderay/scanners/php.rb b/lib/coderay/scanners/php.rb index 8acfff5..3f7ff6a 100644 --- a/lib/coderay/scanners/php.rb +++ b/lib/coderay/scanners/php.rb @@ -1,4 +1,4 @@ -# encoding: ASCII-8BIT +# encoding: utf-8 module CodeRay module Scanners @@ -11,7 +11,6 @@ module Scanners register_for :php file_extension 'php' - encoding 'BINARY' KINDS_NOT_LOC = HTML::KINDS_NOT_LOC @@ -211,7 +210,7 @@ module Scanners HTML_INDICATOR = / ]/i - IDENTIFIER = /[a-z_\x7f-\xFF][a-z0-9_\x7f-\xFF]*/i + IDENTIFIER = 'ä'[/[[:alpha:]]/] == 'ä' ? Regexp.new('[[:alpha:]_[^\0-\177]][[:alnum:]_[^\0-\177]]*') : Regexp.new('[a-z_\17f-\xFF][a-z0-9_\x7f-\xFF]*/', true) VARIABLE = /\$#{IDENTIFIER}/ OPERATOR = / -- cgit v1.2.1 From ed9ed685aa695f0f5601df573b05f1bdc03320f5 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 21:55:33 +0100 Subject: fix PHP scanner for Ruby 1.8 --- lib/coderay/scanners/php.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/coderay/scanners/php.rb b/lib/coderay/scanners/php.rb index 3f7ff6a..6c68834 100644 --- a/lib/coderay/scanners/php.rb +++ b/lib/coderay/scanners/php.rb @@ -210,7 +210,7 @@ module Scanners HTML_INDICATOR = / ]/i - IDENTIFIER = 'ä'[/[[:alpha:]]/] == 'ä' ? Regexp.new('[[:alpha:]_[^\0-\177]][[:alnum:]_[^\0-\177]]*') : Regexp.new('[a-z_\17f-\xFF][a-z0-9_\x7f-\xFF]*/', true) + IDENTIFIER = 'ä'[/[[:alpha:]]/] == 'ä' ? Regexp.new('[[:alpha:]_[^\0-\177]][[:alnum:]_[^\0-\177]]*') : Regexp.new('[a-z_\x7f-\xFF][a-z0-9_\x7f-\xFF]*', true) VARIABLE = /\$#{IDENTIFIER}/ OPERATOR = / -- cgit v1.2.1 From b9b837e302bf8d6c9602e9a6b1a23021f051b0e1 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 21:56:35 +0100 Subject: bump version to 1.0.9 --- lib/coderay/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/coderay/version.rb b/lib/coderay/version.rb index 87d1cff..bfb5f24 100644 --- a/lib/coderay/version.rb +++ b/lib/coderay/version.rb @@ -1,3 +1,3 @@ module CodeRay - VERSION = '1.0.8' + VERSION = '1.0.9' end -- cgit v1.2.1 From afd056744d5ccb0749e0d295a67eaae5ce6a3859 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 22:10:06 +0100 Subject: properly credit Lance Li for reporting the PHP unicode issue ;) --- Changes.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changes.textile b/Changes.textile index dc64792..261349d 100644 --- a/Changes.textile +++ b/Changes.textile @@ -8,7 +8,7 @@ h2. Changes in 1.0.9 * Fix Ruby scanner: Ruby 1.9 hash syntax @{ key: value }@ is highlighted correctly. [GH #106, thanks to Seth Vargo] * Fix HTML scanner: Accept DTDs. [GH #83] -* Fix PHP scanner: Accept Unicode. [GH #40] +* Fix PHP scanner: Accept Unicode. [GH #40, thanks to Lance Li] h2. Changes in 1.0.8 -- cgit v1.2.1 From 972527dca2476e034526f946f7d71a04a51f6eab Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 17 Feb 2013 22:15:23 +0100 Subject: Fix Travis badge URLs --- README.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.textile b/README.textile index 543dc47..0bd2842 100644 --- a/README.textile +++ b/README.textile @@ -1,4 +1,4 @@ -h1. CodeRay !https://secure.travis-ci.org/rubychan/coderay.png!:https://secure.travis-ci.org/rubychan/coderay +h1. CodeRay !https://api.travis-ci.org/rubychan/coderay.png!:https://travis-ci.org/rubychan/coderay h2. About -- cgit v1.2.1 From 9e6364cd659cc26f32fc3732ed091653176ac987 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Wed, 20 Feb 2013 21:15:00 +0100 Subject: trying to enable ruby-head tests in Travis --- .travis.yml | 2 +- test/executable/suite.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 63a9b0b..7c29c56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ rvm: - jruby-19mode - rbx-18mode - rbx-19mode - # - ruby-head # test again later: RedCloth not compiling + - ruby-head # test again later: RedCloth not compiling - jruby-head - ree branches: diff --git a/test/executable/suite.rb b/test/executable/suite.rb index f3495d6..d386f4b 100644 --- a/test/executable/suite.rb +++ b/test/executable/suite.rb @@ -14,12 +14,13 @@ class TestCodeRayExecutable < Test::Unit::TestCase ROOT_DIR = Pathname.new(File.dirname(__FILE__)) + '..' + '..' EXECUTABLE = ROOT_DIR + 'bin' + 'coderay' + RUBY_COMMAND = RUBY_VERSION < '2.0.0' ? 'ruby -w' : 'ruby' # Ruby 2 currently throws warnings for bundler EXE_COMMAND = if RUBY_PLATFORM === 'java' && `ruby --ng -e '' 2> /dev/null` && $?.success? # use Nailgun - 'ruby --ng -wI%s %s' + "#{RUBY_COMMAND}--ng -I%s %s" else - 'ruby -wI%s %s' + "#{RUBY_COMMAND} -I%s %s" end % [ROOT_DIR + 'lib', EXECUTABLE] def coderay args, options = {} -- cgit v1.2.1 From d6546ed69515aed6d0771b75d4b3e38438aad7d1 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 10 Mar 2013 20:44:42 +0100 Subject: remove ondblclick handler from HTML output --- Changes.textile | 172 ++++++++++++++++++------------------ lib/coderay/encoders/html/output.rb | 2 +- test/functional/examples.rb | 4 +- 3 files changed, 90 insertions(+), 88 deletions(-) diff --git a/Changes.textile b/Changes.textile index 261349d..8143b0e 100644 --- a/Changes.textile +++ b/Changes.textile @@ -1,89 +1,91 @@ h1=. CodeRay Version History - + p=. _This files lists all changes in the CodeRay library since the 0.9.8 release._ - -{{toc}} - + +h2. Changes in 1.1 + +* Remove double-click toggle handler from HTML table output + h2. Changes in 1.0.9 - + * Fix Ruby scanner: Ruby 1.9 hash syntax @{ key: value }@ is highlighted correctly. [GH #106, thanks to Seth Vargo] * Fix HTML scanner: Accept DTDs. [GH #83] * Fix PHP scanner: Accept Unicode. [GH #40, thanks to Lance Li] - + h2. Changes in 1.0.8 - + * add @:string/:char@, remove @:regexp/:function@ color from Terminal encoder [GH #29, thanks to Kyrylo Silin] * allow @-@ in line number anchor prefix for HTML encoder [GH #32, thanks to shurizzle] * Fix HTML scanner: Don't crash if HTML in a diff contains a JavaScript tag. h2. Changes in 1.0.7 - + * Changed license from LGPL to MIT. [GH-25, thanks to jessehu] * Fix issue with plugin files not being loaded. [GH-20, thanks to Will Read] * Fix HTML scanner bug: Don't choke on boolean attributes. [GH-26, thanks to jugglinmike] h2. Changes in 1.0.6 - + * New option @:break_lines@ for the HTML encoder (splits tokens at line breaks). [GH-15, thanks to Etienne Massip] * Improved speed of @:line_numbers => :inline@ option for the HTML encoder. * Fixed wrong HTML file type. (was @:page@) [GH-16, thanks to Doug Hammond] * The CSS Scanner now highlights tokens like @url(...)@ as @:function@ instead of @:string@. [GH-13, thanks to Joel Holdbrooks] h2. Changes in 1.0.5 - + Fixes: - + * @autoload@ calls do not depend on @coderay/lib@ being in the load path (GitHub issue #6; thanks to tvon, banister, envygeeks, and ConradIrwin) * avoid dark blue as terminal color (GitHub issue #9; thanks to shevegen) h2. Changes in 1.0.4 - + Fixes in the CSS scanner: - + * understands the unit "s" (seconds) * ignores unexpected curly braces * code inside of diffs is highlighted correctly h2. Changes in 1.0.3 - + New: - + * .tmproj files are recognized as XML. - + Fixes: - + * Removed files are highlighted inside diffs generated by git. h2. Changes in 1.0.2 - + Fixes: - + * .erb files are recognized as ERB. h2. Changes in 1.0.1 - + New: - + * YAML scanner allows "-" and "/" in key names - + Changes: - + * HTML page output has no white border anymore (alpha style) - + Fixes: - + * fixed warning in the output of "coderay stylesheet" * fixed additional scrollbar in code when last line contains an eyecatcher * minor fixes in the tests (issue github-#4) h2. Changes in 1.0 - + CodeRay 1.0 is a major rewrite of the library, and incompatible to earlier versions. - + The command line and programmer interfaces are similar to 0.9, but the internals have completely changed. h3. General changes - + * *NEW*: The new Diff scanner colorizes code inside of the diff, and highlights inline changes. * *NEW*: Extended support and usage of HTML5 and CSS 3 features. * *NEW*: Direct Streaming @@ -95,18 +97,18 @@ h3. General changes * *IMPROVED* Tests: There are more of them now! h3. Direct Streaming - + CodeRay 1.0 introduces _Direct Streaming_ as a faster and simpler alternative to Tokens. It means that all Scanners, Encoders and Filters had to be rewritten, and that older scanners using the Tokens API are no longer compatible with this version. - + The main benefits of this change are: - + * more speed (benchmarks show 10% to 50% more tokens per second compared to CodeRay 0.9) * the ability to stream output into a pipe on the command line * a simpler API * less code - + Changes related to the new tokens handling include: * *CHANGED*: The Scanners now call Encoders directly; tokens are not added to a Tokens array, but are send to the Encoder as a method call. The Tokens representation (which can be seen as a cache now) is still present, but as a @@ -123,16 +125,16 @@ Changes related to the new tokens handling include: and have been removed. h3. Command Line - + The @coderay@ executable was rewritten and has a few new features: - + * *NEW* Ability to stream into a pipe; try @coderay file | more -r@ * *NEW* help * *IMPROVED*: more consistent parameter handling * *REMOVED* @coderay_stylesheet@ executable; use @coderay stylesheet [name]@. h3. @Tokens@ - + * *NEW* methods @count@, @begin_group@, @end_group@, @begin_line@, and @end_line@. * *REMOVED* methods @#stream?@, @#each_text_token@. * *REMOVED* methods @#optimize@, @#fix@, @#split_into_lines@ along with their bang! variants. @@ -140,11 +142,11 @@ h3. @Tokens@ * *REMOVED* special implementation of @#each@ taking a filter parameter. Use @TokenKindFilter@ instead. h3. *RENAMED*: @TokenKinds@ - + Renamed from @Tokens::ClassOfKind@ (was also @Tokens::AbbreviationForKind@ for a while). The term "token class" is no longer used in CodeRay. Instead, tokens have _kinds_. See "#122":http://odd-eyed-code.org/issues/122. - + * *CHANGED* all token CSS classes to readable names. * *ADDED* token kinds @:filename@, @:namespace@, and @:eyecatcher@. * *RENAMED* @:pre_constant@ and @:pre_type@ to @:predefined_constant@ and @predefined_type@. @@ -156,23 +158,23 @@ See "#122":http://odd-eyed-code.org/issues/122. @:NO_HIGHLIGHT@ to @false@. h3. @Duo@ - + * *NEW* method @call@ for allowing code like @CodeRay::Duo[:python => :yaml].(code)@ in Ruby 1.9. h3. @Encoders::CommentFilter@ - + * *NEW* alias @:remove_comments@ h3. @Encoders::Filter@ - + * *NEW* option @tokens@. * *CHANGED*: Now it simply delegates to the output. * *REMOVED* @include_text_token?@ and @include_block_token?@ methods. h3. @Encoders::HTML@ - + The HTML encoder was cleaned up and simplified. - + * *NEW*: HTML5 and CSS 3 compatible. See "#215":http://odd-eyed-code.org/issues/215. * *ADDED* support for @:line_number_anchors@. @@ -186,11 +188,11 @@ The HTML encoder was cleaned up and simplified. * *RENAMED* @Output#numerize@ to @#number@, which is an actual English word. h3. @Encoders::LinesOfCode@ - + * *CHANGED*: @compile@ and @finish@ methods are now protected. h3. *Renamed*: @Encoders::Terminal@ (was @Encoders::Term@) - + * *RENAMED* from @Encoders::Term@, added @:term@ alias. * *CLEANUP*: Use @#setup@'s @super@, don't use @:procedure@ token class. * *CHANGED*: @#token@'s second parameter is no longer optional. @@ -198,21 +200,21 @@ h3. *Renamed*: @Encoders::Terminal@ (was @Encoders::Term@) * *FIXED* handling of line tokens. h3. @Encoders::Text@ - + * *FIXED* default behavior of stripping the trailing newline. h3. *RENAMED*: @Encoders::TokenKindFilter@ (was @Encoders::TokenClassFilter@) - + * *NEW*: Handles token groups. See "#223":http://odd-eyed-code.org/issues/223. * *RENAMED* @include_block_token?@ to @include_group?@. h3. @Encoders::Statistic@ - + * *CHANGED*: Tokens actions are counted separately. h3. @Scanners::Scanner@ - + * *NEW* methods @#file_extension@ and @#encoding@. * *NEW*: The @#tokenize@ method also takes an Array of Strings as source. The code is highlighted as one and split into parts of the input lengths @@ -225,11 +227,11 @@ h3. @Scanners::Scanner@ * *CHANGED*: @#column@ starts counting with 1 instead of 0 h3. *NEW*: @Scanners::Clojure@ - + Thanks to Licenser, CodeRay now supports the Clojure language. h3. @Scanners::CSS@ - + * *NEW*: Rudimentary support for the @attr@, @counter@, and @counters@ functions. See "#224":http://odd-eyed-code.org/issues/224. * *NEW*: Rudimentary support for CSS 3 colors. @@ -237,7 +239,7 @@ h3. @Scanners::CSS@ * *CHANGED*: Comments are scanned as one token instead of three. h3. @Scanners::Debug@ - + * *NEW*: Support for line tokens (@begin_line@ and @end_line@ represented by @[@ and @]@.) * *FIXED*: Don't send @:error@ and @nil@ tokens for buggy input any more. * *FIXED*: Closes unclosed tokens at the end of @scan_tokens@. @@ -245,32 +247,32 @@ h3. @Scanners::Debug@ * *CHANGED*: Raises an error when trying to end an invalid token group. h3. @Scanners::Delphi@ - + * *FIXED*: Closes open string groups. h3. @Scanners::Diff@ - + * *NEW*: Highlighting of code based on file names. See ticket "#52":http://odd-eyed-code.org/issues/52. - + Use the @:highlight_code@ option to turn this feature off. It's enabled by default. - + This is a very original feature. It enables multi-language highlighting for diff files, which is especially helpful for CodeRay development itself. The updated version of the scanner test suite generated .debug.diff.html files using this. - + Note: This is still experimental. Tokens spanning more than one line may get highlighted incorrectly. CodeRay tries to keep scanner states between the lines and changes, but the quality of the results depend on the scanner. * *NEW*: Inline change highlighting, as suggested by Eric Thomas. See ticket "#227":http://odd-eyed-code.org/issues/227 for details. - + Use the @:inline_diff@ option to turn this feature off. It's enabled by default. - + For single-line changes (that is, a single deleted line followed by a single inserted line), this feature surrounds the changed parts with an @:eyecatcher@ group which appears in a more saturated background color. @@ -287,38 +289,38 @@ h3. @Scanners::Diff@ h3. *RENAMED*: @Scanners::ERB@ (was @Scanners::RHTML@) h3. *NEW*: @Scanners::HAML@ - + It uses the new :state options of the HTML and Ruby scanners. - + Some rare cases are not considered (like @#{...}@ snippets inside of :javascript blocks), but it highlights pretty well. h3. @Scanners::HTML@ - + * *FIXED*: Closes open string groups. h3. @Scanners::JavaScript@ - + * *IMPROVED*: Added @NaN@ and @Infinity@ to list of predefined constants. * *IMPROVED* recognition of RegExp literals with leading spaces. h3. @Scanners::Java@ - + * *NEW*: Package names are highlighted as @:namespace@. See "#210":http://odd-eyed-code.org/issues/210. h3. *REMOVED*: @Scanners::NitroXHTML@ - + Nitro is "dead":http://www.nitrohq.com/. h3. *RENAMED*: @Scanners::Text@ (was @Scanners::Plaintext@) - + * *IMPROVED*: Just returns the string without scanning (faster). - + This is much faster than scanning until @/\z/@ in Ruby 1.8. h3. @Scanners::Python@ - + * *CHANGED*: Docstrings are highlighted as @:comment@. See "#190":http://odd-eyed-code.org/issues/190. @@ -328,7 +330,7 @@ Copied from @Scanners::Debug@, highlights the token dump instead of importing it name suffix now. h3. @Scanners::Ruby@ - + * *ADDED* more predefined keywords (see http://murfy.de/ruby-constants). * *IMPROVED* support for singleton method definitions. See "#147":http://odd-eyed-code.org/issues/147. @@ -336,44 +338,44 @@ h3. @Scanners::Ruby@ (eg. @GL.PushMatrix@). * *NEW*: Highlight buggy floats (like .5) as @:error@. * *CLEANUP* of documentation, names of constants and variables, state handling. - + Moved @StringState@ class from @patterns.rb@ into a separate file. * *NEW*: Complicated rule for recognition of @foo=@ style method names. * *NEW*: Handles @:keep_state@ option (a bit; experimental). - + Actually, Ruby checks if there is @[~>=]@, but not @=>@ following the name. - + * *REMOVED* @EncodingError@ h3. *REMOVED* @Scanners::Scheme@ - + * It is too buggy, and nobody was using it. To be added again when it's fixed. See "#59":http://odd-eyed-code.org/issues/59. h3. @Scanners::SQL@ - + * *IMPROVED*: Extended list of keywords and functions (thanks to Joshua Galvez, Etienne Massip, and others). - + See "#221":http://odd-eyed-code.org/issues/221. * *FIXED*: Closes open string groups. * *FIXED*: Words after @.@ are always recognized as @:ident@. h3. @Scanners::YAML@ - + * *FIXED*: Allow spaces before colon in mappings. - + See "#231":http://odd-eyed-code.org/issues/231. h3. *NEW*: @Styles::Alpha@ A style that uses transparent HSLA colors as defined in CSS 3. See "#199":http://odd-eyed-code.org/issues/199. - + It also uses the CSS 3 property @user-select: none@ to keep the user from selecting the line numbers. This is especially nice for @:inline@ line numbers. See "#226":http://odd-eyed-code.org/issues/226. h3. @WordList@ - + Stripped down to 19 LOC. * *RENAMED* @CaseIgnoringWordList@ to @WordList::CaseIgnoring@. @@ -381,14 +383,14 @@ Stripped down to 19 LOC. * *REMOVED* block option. h3. @FileType@ - + * *NEW*: Recognizes @.gemspec@, @.rjs@, @.rpdf@ extensions, @Gemfile@, and @Capfile@ as Ruby. - + Thanks to the authors of the TextMate Ruby bundle! * *REMOVED* @FileType#shebang@ is a protected method now. h3. @Plugin@ - + * *IMPROVED*: @register_for@ sets the @plugin_id@; it can now be a @Symbol@. * *ADDED* @PluginHost#const_missing@ method: Plugins are loaded automatically. Using @Scanners::JavaScript@ in your code loads @scanners/java_script.rb@. @@ -397,19 +399,19 @@ h3. @Plugin@ * *CHANGED* the default plugin key from @nil@ to @:default@. h3. @GZip@ - + * *MOVED* into @CodeRay@ namespace. * *MOVED* file from @gzip_simple.rb@ to @gzip.rb@. * *REMOVED* @String@ extensions. h3. More API changes - + * *FIXED* @Encoders::HTML#token@'s second parameter is no longer optional. * *CHANGED* @Encoders::HTML::Output@'s API. * *REMOVED* lots of unused methods. - + The helper classes were cleaned up; see above for details. - + * *CHANGED* @Plugin@ API was simplified and stripped of all unnecessary features. * *CHANGED* Moved @GZip@ and @FileType@ libraries into @CodeRay@; cleaned them up. diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 9132d94..de6f6ea 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -124,7 +124,7 @@ module Encoders TABLE = Template.new <<-TABLE - +
<%LINE_NUMBERS%>
<%LINE_NUMBERS%>
<%CONTENT%>
TABLE diff --git a/test/functional/examples.rb b/test/functional/examples.rb index ff64af3..b8e0a2a 100755 --- a/test/functional/examples.rb +++ b/test/functional/examples.rb @@ -22,7 +22,7 @@ end CODE assert_equal <<-DIV, div - @@ -38,7 +38,7 @@ end
1
+  
1
 2
 3
 
-
+  
 
puts "Hello, world!"
-- cgit v1.2.1 From 61d1a15a5be9ecd546e3252691349136e04d86ac Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 10 Mar 2013 20:48:07 +0100 Subject: move credits into CREDITS.textile --- CREDITS.textile | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ README.textile | 63 --------------------------------------------------------- 2 files changed, 61 insertions(+), 63 deletions(-) create mode 100644 CREDITS.textile diff --git a/CREDITS.textile b/CREDITS.textile new file mode 100644 index 0000000..4c58c54 --- /dev/null +++ b/CREDITS.textile @@ -0,0 +1,61 @@ +h1. Credits + +h3. Special Thanks to + +* licenser (Heinz N. Gies) for ending my QBasic career, inventing the Coder project and the input/output plugin system. CodeRay would not exist without him. +* bovi (Daniel Bovensiepen) for helping me out on various occasions. + +h3. Thanks to + +* Caleb Clausen for writing "RubyLexer":http://rubyforge.org/projects/rubylexer and lots of very interesting mail traffic +* birkenfeld (Georg Brandl) and mitsuhiku (Arnim Ronacher) for PyKleur, now Pygments. You guys rock! +* Jamis Buck for writing "Syntax":http://rubyforge.org/projects/syntax — I got some useful ideas from it. +* Doug Kearns and everyone else who worked on ruby.vim - it not only helped me coding CodeRay, but also gave me a wonderful target to reach for the Ruby scanner. +* everyone who uses CodeBB on "http://www.rubyforen.de":http://www.rubyforen.de and "http://www.python-forum.de":http://www.python-forum.de +* iGEL, magichisoka, manveru, WoNáDo and everyone I forgot from rubyforen.de +* Dethix from ruby-mine.de +* zickzackw +* Dookie (who is no longer with us...) and Leonidas from "http://www.python-forum.de":http://www.python-forum.de +* Andreas Schwarz for finding out that CaseIgnoringWordList was not case ignoring! Such things really make you write tests. +* closure for the first version of the Scheme scanner. +* Stefan Walk for the first version of the JavaScript and PHP scanners. +* Josh Goebel for another version of the JavaScript scanner, a SQL and a Diff scanner. +* Jonathan Younger for pointing out the licence confusion caused by wrong LICENSE file. +* Jeremy Hinegardner for finding the shebang-on-empty-file bug in FileType. +* Charles Oliver Nutter and Yehuda Katz for helping me benchmark CodeRay on JRuby. +* Andreas Neuhaus for pointing out a markup bug in coderay/for_redcloth. +* 0xf30fc7 for the FileType patch concerning Delphi file extensions. +* The folks at redmine.org - thank you for using and fixing CodeRay! +* Keith Pitt for his SQL scanners +* Rob Aldred for the terminal encoder +* Trans for pointing out $DEBUG dependencies +* Flameeyes for finding that Term::ANSIColor was obsolete +* matz and all Ruby gods and gurus +* The inventors of: the computer, the internet, the true color display, HTML & CSS, VIM, Ruby, pizza, microwaves, guitars, scouting, programming, anime, manga, coke and green ice tea. + +Where would we be without all those people? + +h3. Created using + +* "Ruby":http://ruby-lang.org/ +* Chihiro (my Sony VAIO laptop); Henrietta (my old MacBook); Triella, born Rico (my new MacBook); as well as Seras and Hikari (my PCs) +* "RDE":http://homepage2.nifty.com/sakazuki/rde_e.html, "VIM":http://vim.org and "TextMate":http://macromates.com +* "Subversion":http://subversion.tigris.org/ +* "Redmine":http://redmine.org/ +* "Firefox":http://www.mozilla.org/products/firefox/, "Firebug":http://getfirebug.com/, "Safari":http://www.apple.com/safari/, and "Thunderbird":http://www.mozilla.org/products/thunderbird/ +* "RubyGems":http://docs.rubygems.org/ and "Rake":http://rake.rubyforge.org/ +* "TortoiseSVN":http://tortoisesvn.tigris.org/ using Apache via "XAMPP":http://www.apachefriends.org/en/xampp.html +* RDoc (though I'm quite unsatisfied with it) +* Microsoft Windows (yes, I confess!) and MacOS X +* GNUWin32, MinGW and some other tools to make the shell under windows a bit less useless +* Term::"ANSIColor":http://term-ansicolor.rubyforge.org/ +* "PLEAC":http://pleac.sourceforge.net/ code examples +* Github +* "Travis CI":http://travis-ci.org/rubychan/github + +h3. Free + +* As you can see, CodeRay was created under heavy use of *free* software. +* So CodeRay is also *free*. +* If you use CodeRay to create software, think about making this software *free*, too. +* Thanks :) diff --git a/README.textile b/README.textile index 0bd2842..b44899c 100644 --- a/README.textile +++ b/README.textile @@ -35,66 +35,3 @@ p. h2. Documentation See "http://coderay.rubychan.de/doc/":http://coderay.rubychan.de/doc/. - - -h2. Credits - -h3. Special Thanks to - -* licenser (Heinz N. Gies) for ending my QBasic career, inventing the Coder project and the input/output plugin system. CodeRay would not exist without him. -* bovi (Daniel Bovensiepen) for helping me out on various occasions. - -h3. Thanks to - -* Caleb Clausen for writing "RubyLexer":http://rubyforge.org/projects/rubylexer and lots of very interesting mail traffic -* birkenfeld (Georg Brandl) and mitsuhiku (Arnim Ronacher) for PyKleur, now Pygments. You guys rock! -* Jamis Buck for writing "Syntax":http://rubyforge.org/projects/syntax — I got some useful ideas from it. -* Doug Kearns and everyone else who worked on ruby.vim - it not only helped me coding CodeRay, but also gave me a wonderful target to reach for the Ruby scanner. -* everyone who uses CodeBB on "http://www.rubyforen.de":http://www.rubyforen.de and "http://www.python-forum.de":http://www.python-forum.de -* iGEL, magichisoka, manveru, WoNáDo and everyone I forgot from rubyforen.de -* Dethix from ruby-mine.de -* zickzackw -* Dookie (who is no longer with us...) and Leonidas from "http://www.python-forum.de":http://www.python-forum.de -* Andreas Schwarz for finding out that CaseIgnoringWordList was not case ignoring! Such things really make you write tests. -* closure for the first version of the Scheme scanner. -* Stefan Walk for the first version of the JavaScript and PHP scanners. -* Josh Goebel for another version of the JavaScript scanner, a SQL and a Diff scanner. -* Jonathan Younger for pointing out the licence confusion caused by wrong LICENSE file. -* Jeremy Hinegardner for finding the shebang-on-empty-file bug in FileType. -* Charles Oliver Nutter and Yehuda Katz for helping me benchmark CodeRay on JRuby. -* Andreas Neuhaus for pointing out a markup bug in coderay/for_redcloth. -* 0xf30fc7 for the FileType patch concerning Delphi file extensions. -* The folks at redmine.org - thank you for using and fixing CodeRay! -* Keith Pitt for his SQL scanners -* Rob Aldred for the terminal encoder -* Trans for pointing out $DEBUG dependencies -* Flameeyes for finding that Term::ANSIColor was obsolete -* matz and all Ruby gods and gurus -* The inventors of: the computer, the internet, the true color display, HTML & CSS, VIM, Ruby, pizza, microwaves, guitars, scouting, programming, anime, manga, coke and green ice tea. - -Where would we be without all those people? - -h3. Created using - -* "Ruby":http://ruby-lang.org/ -* Chihiro (my Sony VAIO laptop); Henrietta (my old MacBook); Triella, born Rico (my new MacBook); as well as Seras and Hikari (my PCs) -* "RDE":http://homepage2.nifty.com/sakazuki/rde_e.html, "VIM":http://vim.org and "TextMate":http://macromates.com -* "Subversion":http://subversion.tigris.org/ -* "Redmine":http://redmine.org/ -* "Firefox":http://www.mozilla.org/products/firefox/, "Firebug":http://getfirebug.com/, "Safari":http://www.apple.com/safari/, and "Thunderbird":http://www.mozilla.org/products/thunderbird/ -* "RubyGems":http://docs.rubygems.org/ and "Rake":http://rake.rubyforge.org/ -* "TortoiseSVN":http://tortoisesvn.tigris.org/ using Apache via "XAMPP":http://www.apachefriends.org/en/xampp.html -* RDoc (though I'm quite unsatisfied with it) -* Microsoft Windows (yes, I confess!) and MacOS X -* GNUWin32, MinGW and some other tools to make the shell under windows a bit less useless -* Term::"ANSIColor":http://term-ansicolor.rubyforge.org/ -* "PLEAC":http://pleac.sourceforge.net/ code examples -* Github -* "Travis CI":http://travis-ci.org/rubychan/github - -h3. Free - -* As you can see, CodeRay was created under heavy use of *free* software. -* So CodeRay is also *free*. -* If you use CodeRay to create software, think about making this software *free*, too. -* Thanks :) -- cgit v1.2.1 From 0d2d0bef962d27abb0b6d7423bce6010bb71976c Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 10 Mar 2013 20:55:13 +0100 Subject: convert README to markdown, use syntax highlighting, cleanup --- README.markdown | 27 +++++++++++++++++++++++++++ README.textile | 37 ------------------------------------- 2 files changed, 27 insertions(+), 37 deletions(-) create mode 100644 README.markdown delete mode 100644 README.textile diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..42bdab6 --- /dev/null +++ b/README.markdown @@ -0,0 +1,27 @@ +# CodeRay [![Build Status](https://travis-ci.org/rubychan/coderay.png)](https://travis-ci.org/rubychan/coderay) + +## About + +CodeRay is a Ruby library for syntax highlighting. + +You put your code in, and you get it back colored; Keywords, strings, floats, comments - all in different colors. And with line numbers. + +## Installation + +`gem install coderay` + +### Dependencies + +CodeRay needs Ruby 1.8.7+ or 1.9.2+. It also runs on Rubinius and JRuby. + +## Example Usage + +```ruby +require 'coderay' + +html = CodeRay.scan("puts 'Hello, world!'", :ruby).div(:line_numbers => :table) +```` + +## Documentation + +See [http://coderay.rubychan.de/doc/](http://coderay.rubychan.de/doc/). diff --git a/README.textile b/README.textile deleted file mode 100644 index b44899c..0000000 --- a/README.textile +++ /dev/null @@ -1,37 +0,0 @@ -h1. CodeRay !https://api.travis-ci.org/rubychan/coderay.png!:https://travis-ci.org/rubychan/coderay - -h2. About - -CodeRay is a Ruby library for syntax highlighting. - -You put your code in, and you get it back colored; Keywords, strings, floats, comments - all in different colors. And with line numbers. - -*Syntax Highlighting*… - -* makes code easier to read and maintain -* lets you detect syntax errors faster -* helps you to understand the syntax of a language -* looks nice -* is what everybody wants to have on their website -* solves all your problems and makes the girls run after you - - -h2. Installation - -bc. gem install coderay - -h3. Dependencies - -CodeRay needs Ruby 1.8.7+ or 1.9.2+. It also runs on Rubinius and JRuby. - -h2. Example Usage - -bc.. require 'coderay' - -html = CodeRay.scan("puts 'Hello, world!'", :ruby).div(:line_numbers => :table) - -p. - -h2. Documentation - -See "http://coderay.rubychan.de/doc/":http://coderay.rubychan.de/doc/. -- cgit v1.2.1 From 3d7f34571a0b2e58ee90498bc54f160bda2bed45 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 10 Mar 2013 21:12:53 +0100 Subject: fix #41 by removing special case Also, clean up some code. --- Changes.textile | 1 + lib/coderay/encoders/html/numbering.rb | 39 +++++++++++++++++++--------------- test/functional/examples.rb | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Changes.textile b/Changes.textile index 8143b0e..be05e9d 100644 --- a/Changes.textile +++ b/Changes.textile @@ -5,6 +5,7 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release h2. Changes in 1.1 * Remove double-click toggle handler from HTML table output +* Display line numbers in HTML @:table@ mode even for single-line code (remove special case) [#41, thanks to Ariejan de Vroom] h2. Changes in 1.0.9 diff --git a/lib/coderay/encoders/html/numbering.rb b/lib/coderay/encoders/html/numbering.rb index e717429..332145b 100644 --- a/lib/coderay/encoders/html/numbering.rb +++ b/lib/coderay/encoders/html/numbering.rb @@ -1,15 +1,15 @@ module CodeRay module Encoders - + class HTML - + module Numbering # :nodoc: - + def self.number! output, mode = :table, options = {} return self unless mode - + options = DEFAULT_OPTIONS.merge options - + start = options[:line_number_start] unless start.is_a? Integer raise ArgumentError, "Invalid value %p for :line_number_start; Integer expected." % start @@ -56,12 +56,17 @@ module Encoders raise ArgumentError, 'Invalid value %p for :bolding; false or Integer expected.' % bold_every end - line_count = output.count("\n") - position_of_last_newline = output.rindex(RUBY_VERSION >= '1.9' ? /\n/ : ?\n) - if position_of_last_newline + if position_of_last_newline = output.rindex(RUBY_VERSION >= '1.9' ? /\n/ : ?\n) after_last_newline = output[position_of_last_newline + 1 .. -1] ends_with_newline = after_last_newline[/\A(?:<\/span>)*\z/] - line_count += 1 if not ends_with_newline + + if ends_with_newline + line_count = output.count("\n") + else + line_count = output.count("\n") + 1 + end + else + line_count = 1 end case mode @@ -74,30 +79,30 @@ module Encoders line_number += 1 "#{indent}#{line_number_text}#{line}" end - + when :table line_numbers = (start ... start + line_count).map(&bolding).join("\n") line_numbers << "\n" line_numbers_table_template = Output::TABLE.apply('LINE_NUMBERS', line_numbers) - + output.gsub!(/<\/div>\n/, '') output.wrap_in! line_numbers_table_template output.wrapped_in = :div - + when :list raise NotImplementedError, 'The :list option is no longer available. Use :table.' - + else raise ArgumentError, 'Unknown value %p for mode: expected one of %p' % [mode, [:table, :inline]] end - + output end - + end - + end - + end end diff --git a/test/functional/examples.rb b/test/functional/examples.rb index b8e0a2a..15f9ca3 100755 --- a/test/functional/examples.rb +++ b/test/functional/examples.rb @@ -38,7 +38,7 @@ end -
+  
1
 
puts "Hello, world!"
-- cgit v1.2.1