summaryrefslogtreecommitdiff
path: root/lib/coderay
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2012-04-13 15:41:29 +0200
committerKornelius Kalnbach <murphy@rubychan.de>2012-04-13 15:41:29 +0200
commit5598df049e8823f9838b348e76227ef836c4e39b (patch)
treeff0ae7c93edde90a65f556d894e2c894bdc15487 /lib/coderay
parent6f3922f4938184d524ba990f0fa3d81531fd9b1e (diff)
parent359db4594e7fc874cf8087f599dc4e96b22e586b (diff)
downloadcoderay-5598df049e8823f9838b348e76227ef836c4e39b.tar.gz
Merge branch 'master' into multiline-inline-diff
Diffstat (limited to 'lib/coderay')
-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
7 files changed, 33 insertions, 20 deletions
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