summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.travis.yml8
-rw-r--r--Changes.textile11
-rw-r--r--bench/bench.rb1
-rw-r--r--lib/coderay/encoders/html.rb27
-rw-r--r--lib/coderay/encoders/html/numbering.rb14
-rw-r--r--lib/coderay/helpers/file_type.rb6
-rw-r--r--lib/coderay/helpers/plugin.rb1
-rw-r--r--lib/coderay/scanners/php.rb1
-rw-r--r--lib/coderay/scanners/python.rb2
-rw-r--r--lib/coderay/version.rb2
-rw-r--r--test/unit/file_type.rb6
-rw-r--r--test/unit/html.rb103
13 files changed, 157 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
index 2bb9385..a000699 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.DS_Store
*.gem
*.rbc
.bundle
diff --git a/.travis.yml b/.travis.yml
index 7b1b91c..43e9f45 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,11 +2,13 @@ rvm:
- 1.8.7
- 1.9.2
- 1.9.3
+ - jruby-18mode
+ - jruby-19mode
+ - rbx-18mode
+ # - rbx-19mode # test again later
- ruby-head
- - rbx
- - rbx-2.0
+ - jruby-head
- ree
- - jruby
branches:
only:
- master
diff --git a/Changes.textile b/Changes.textile
index 60382f5..470ba33 100644
--- a/Changes.textile
+++ b/Changes.textile
@@ -4,6 +4,17 @@ p=. _This files lists all changes in the CodeRay library since the 0.9.8 release
{{toc}}
+h2. Changes in 1.0.7
+
+* Fix issue with plugin files not being loaded. [GH-20, thanks to Will Read]
+
+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:
diff --git a/bench/bench.rb b/bench/bench.rb
index 5663466..45dc5b0 100644
--- a/bench/bench.rb
+++ b/bench/bench.rb
@@ -79,6 +79,7 @@ N.times do
options = {
:tab_width => 2,
+ # :line_numbers => :inline,
:css => $style ? :style : :class,
}
$hl = CodeRay.encoder(format, options) unless $dump_output
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index c32dbd1..635a4d8 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -47,6 +47,13 @@ module Encoders
#
# Default: 'CodeRay output'
#
+ # === :break_lines
+ #
+ # Split multiline blocks at line breaks.
+ # Forced to true if :line_numbers option is set to :inline.
+ #
+ # Default: false
+ #
# === :line_numbers
# Include line numbers in :table, :inline, or nil (no line numbers)
#
@@ -100,6 +107,8 @@ module Encoders
:wrap => nil,
:title => 'CodeRay output',
+ :break_lines => false,
+
:line_numbers => nil,
:line_number_anchors => 'n',
:line_number_start => 1,
@@ -168,6 +177,10 @@ module Encoders
@out = ''
end
+ options[:break_lines] = true if options[:line_numbers] == :inline
+
+ @break_lines = (options[:break_lines] == true)
+
@HTML_ESCAPE = HTML_ESCAPE.dup
@HTML_ESCAPE["\t"] = ' ' * options[:tab_width]
@@ -245,7 +258,19 @@ module Encoders
if text =~ /#{HTML_ESCAPE_PATTERN}/o
text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] }
end
- if style = @span_for_kind[@last_opened ? [kind, *@opened] : kind]
+
+ style = @span_for_kind[@last_opened ? [kind, *@opened] : kind]
+
+ if @break_lines && (i = text.index("\n")) && (c = @opened.size + (style ? 1 : 0)) > 0
+ close = '</span>' * c
+ reopen = ''
+ @opened.each_with_index do |k, index|
+ reopen << (@span_for_kind[index > 0 ? [k, *@opened[0 ... index ]] : k] || '<span>')
+ end
+ text[i .. -1] = text[i .. -1].gsub("\n", "#{close}\n#{reopen}#{style}")
+ end
+
+ if style
@out << style << text << '</span>'
else
@out << text
diff --git a/lib/coderay/encoders/html/numbering.rb b/lib/coderay/encoders/html/numbering.rb
index 15ce11b..8bc6259 100644
--- a/lib/coderay/encoders/html/numbering.rb
+++ b/lib/coderay/encoders/html/numbering.rb
@@ -68,23 +68,11 @@ module Encoders
when :inline
max_width = (start + line_count).to_s.size
line_number = start
- nesting = []
output.gsub!(/^.*$\n?/) do |line|
- line.chomp!
- open = nesting.join
- line.scan(%r!<(/)?span[^>]*>?!) do |close,|
- if close
- nesting.pop
- else
- nesting << $&
- end
- end
- close = '</span>' * nesting.size
-
line_number_text = bolding.call line_number
indent = ' ' * (max_width - line_number.to_s.size) # TODO: Optimize (10^x)
line_number += 1
- "<span class=\"line-numbers\">#{indent}#{line_number_text}</span>#{open}#{line}#{close}\n"
+ "<span class=\"line-numbers\">#{indent}#{line_number_text}</span>#{line}"
end
when :table
diff --git a/lib/coderay/helpers/file_type.rb b/lib/coderay/helpers/file_type.rb
index 7b90918..637001b 100644
--- a/lib/coderay/helpers/file_type.rb
+++ b/lib/coderay/helpers/file_type.rb
@@ -90,8 +90,8 @@ module CodeRay
'gvy' => :groovy,
'h' => :c,
'haml' => :haml,
- 'htm' => :page,
- 'html' => :page,
+ 'htm' => :html,
+ 'html' => :html,
'html.erb' => :erb,
'java' => :java,
'js' => :java_script,
@@ -120,7 +120,7 @@ module CodeRay
'sql' => :sql,
# 'ss' => :scheme,
'tmproj' => :xml,
- 'xhtml' => :page,
+ 'xhtml' => :html,
'xml' => :xml,
'yaml' => :yaml,
'yml' => :yaml,
diff --git a/lib/coderay/helpers/plugin.rb b/lib/coderay/helpers/plugin.rb
index 06c1233..137c1ab 100644
--- a/lib/coderay/helpers/plugin.rb
+++ b/lib/coderay/helpers/plugin.rb
@@ -176,7 +176,6 @@ module CodeRay
id = validate_id(plugin_id)
path = path_to id
begin
- raise LoadError, "#{path} not found" unless File.exist? path
require path
rescue LoadError => boom
if @plugin_map_loaded
diff --git a/lib/coderay/scanners/php.rb b/lib/coderay/scanners/php.rb
index dadab00..8acfff5 100644
--- a/lib/coderay/scanners/php.rb
+++ b/lib/coderay/scanners/php.rb
@@ -1,3 +1,4 @@
+# encoding: ASCII-8BIT
module CodeRay
module Scanners
diff --git a/lib/coderay/scanners/python.rb b/lib/coderay/scanners/python.rb
index 5e38a2c..cbdbbdb 100644
--- a/lib/coderay/scanners/python.rb
+++ b/lib/coderay/scanners/python.rb
@@ -61,7 +61,7 @@ module Scanners
add(PREDEFINED_VARIABLES_AND_CONSTANTS, :predefined_constant).
add(PREDEFINED_EXCEPTIONS, :exception) # :nodoc:
- NAME = / [^\W\d] \w* /x # :nodoc:
+ NAME = / [[:alpha:]_] \w* /x # :nodoc:
ESCAPE = / [abfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x # :nodoc:
UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} | N\{[-\w ]+\} /x # :nodoc:
diff --git a/lib/coderay/version.rb b/lib/coderay/version.rb
index e2797b5..620e703 100644
--- a/lib/coderay/version.rb
+++ b/lib/coderay/version.rb
@@ -1,3 +1,3 @@
module CodeRay
- VERSION = '1.0.5'
+ VERSION = '1.0.7'
end
diff --git a/test/unit/file_type.rb b/test/unit/file_type.rb
index 607e30a..263517b 100644
--- a/test/unit/file_type.rb
+++ b/test/unit/file_type.rb
@@ -63,9 +63,9 @@ class FileTypeTests < Test::Unit::TestCase
end
def test_html
- assert_equal :page, FileType['test.htm']
- assert_equal :page, FileType['test.xhtml']
- assert_equal :page, FileType['test.html.xhtml']
+ assert_equal :html, FileType['test.htm']
+ assert_equal :html, FileType['test.xhtml']
+ assert_equal :html, FileType['test.html.xhtml']
assert_equal :erb, FileType['_form.rhtml']
assert_equal :erb, FileType['_form.html.erb']
end
diff --git a/test/unit/html.rb b/test/unit/html.rb
new file mode 100644
index 0000000..0072635
--- /dev/null
+++ b/test/unit/html.rb
@@ -0,0 +1,103 @@
+require 'test/unit'
+require 'coderay'
+
+class HtmlTest < Test::Unit::TestCase
+
+ def test_break_lines_option
+ snippets = {}
+
+ snippets[:ruby] = {}
+
+ snippets[:ruby][:in] = <<-RUBY
+ruby_inside = <<-RUBY_INSIDE
+This is tricky,
+isn't it?
+RUBY_INSIDE
+ RUBY
+
+ snippets[:ruby][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF
+ruby_inside = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\">
+This is tricky,
+isn't it?</span><span class=\"delimiter\">
+RUBY_INSIDE</span></span>
+ HTML_OPT_INDEPENDENT_LINES_OFF
+
+ snippets[:ruby][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
+ruby_inside = <span class=\"string\"><span class=\"delimiter\">&lt;&lt;-RUBY_INSIDE</span></span><span class=\"string\"><span class=\"content\"></span></span>
+<span class=\"string\"><span class=\"content\">This is tricky,</span></span>
+<span class=\"string\"><span class=\"content\">isn't it?</span><span class=\"delimiter\"></span></span>
+<span class=\"string\"><span class=\"delimiter\">RUBY_INSIDE</span></span>
+ HTML_OPT_INDEPENDENT_LINES_ON
+
+ snippets[:java] = {}
+
+ snippets[:java][:in] = <<-JAVA
+import java.lang.*;
+
+/**
+ * This is some multiline javadoc
+ * used to test the
+ */
+public class Test {
+ public static final String MESSAGE = "My message\
+ To the world";
+
+ static void main() {
+ /*
+ * Another multiline
+ * comment
+ */
+ System.out.println(MESSAGE);
+ }
+}
+ JAVA
+
+ snippets[:java][:expected_with_option_off] = <<-HTML_OPT_INDEPENDENT_LINES_OFF
+<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;
+
+<span class=\"comment\">/**
+ * This is some multiline javadoc
+ * used to test the
+ */</span>
+<span class=\"directive\">public</span> <span class=\"type\">class</span> <span class=\"class\">Test</span> {
+ <span class=\"directive\">public</span> <span class=\"directive\">static</span> <span class=\"directive\">final</span> <span class=\"predefined-type\">String</span> MESSAGE = <span class=\"string\"><span class=\"delimiter\">&quot;</span><span class=\"content\">My message To the world</span><span class=\"delimiter\">&quot;</span></span>;
+
+ <span class=\"directive\">static</span> <span class=\"type\">void</span> main() {
+ <span class=\"comment\">/*
+ * Another multiline
+ * comment
+ */</span>
+ <span class=\"predefined-type\">System</span>.out.println(MESSAGE);
+ }
+}
+ HTML_OPT_INDEPENDENT_LINES_OFF
+
+ snippets[:java][:expected_with_option_on] = <<-HTML_OPT_INDEPENDENT_LINES_ON
+<span class=\"keyword\">import</span> <span class=\"include\">java.lang</span>.*;
+
+<span class=\"comment\">/**</span>
+<span class=\"comment\"> * This is some multiline javadoc</span>
+<span class=\"comment\"> * used to test the</span>
+<span class=\"comment\"> */</span>
+<span class=\"directive\">public</span> <span class=\"type\">class</span> <span class=\"class\">Test</span> {
+ <span class=\"directive\">public</span> <span class=\"directive\">static</span> <span class=\"directive\">final</span> <span class=\"predefined-type\">String</span> MESSAGE = <span class=\"string\"><span class=\"delimiter\">&quot;</span><span class=\"content\">My message To the world</span><span class=\"delimiter\">&quot;</span></span>;
+
+ <span class=\"directive\">static</span> <span class=\"type\">void</span> main() {
+ <span class=\"comment\">/*</span>
+<span class=\"comment\"> * Another multiline</span>
+<span class=\"comment\"> * comment</span>
+<span class=\"comment\"> */</span>
+ <span class=\"predefined-type\">System</span>.out.println(MESSAGE);
+ }
+}
+ HTML_OPT_INDEPENDENT_LINES_ON
+
+ for lang, code in snippets
+ tokens = CodeRay.scan code[:in], lang
+
+ assert_equal code[:expected_with_option_off], tokens.html
+ assert_equal code[:expected_with_option_off], tokens.html(:break_lines => false)
+ assert_equal code[:expected_with_option_on], tokens.html(:break_lines => true)
+ end
+ end
+end