From c38a5e228964fa9b0b3351a197cb3f0da10c9ec4 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Wed, 2 Nov 2011 19:37:24 +0100 Subject: inline diff highlighting for multi-line changes (#227) --- lib/coderay/scanners/diff.rb | 80 ++++++++++++++++++++++++++++---------------- lib/coderay/version.rb | 2 +- 2 files changed, 52 insertions(+), 30 deletions(-) (limited to 'lib/coderay') diff --git a/lib/coderay/scanners/diff.rb b/lib/coderay/scanners/diff.rb index 52e23d5..18ffa39 100644 --- a/lib/coderay/scanners/diff.rb +++ b/lib/coderay/scanners/diff.rb @@ -22,7 +22,7 @@ module Scanners line_kind = nil state = :initial - deleted_lines = 0 + deleted_lines_count = 0 scanners = Hash.new do |h, lang| h[lang] = Scanners[lang].new '', :keep_tokens => true, :keep_state => true end @@ -32,7 +32,7 @@ module Scanners until eos? if match = scan(/\n/) - deleted_lines = 0 unless line_kind == :delete + deleted_lines_count = 0 unless line_kind == :delete if line_kind encoder.end_line line_kind line_kind = nil @@ -101,37 +101,59 @@ module Scanners end next elsif match = scan(/-/) - deleted_lines += 1 - encoder.begin_line line_kind = :delete - encoder.text_token match, :delete - if options[:inline_diff] && deleted_lines == 1 && check(/(?>.*)\n\+(?>.*)$(?!\n\+)/) - content_scanner_entry_state = content_scanner.state - skip(/(.*)\n\+(.*)$/) - head, deletion, insertion, tail = diff self[1], self[2] - pre, deleted, post = content_scanner.tokenize [head, deletion, tail], :tokens => Tokens.new - encoder.tokens pre - unless deleted.empty? - encoder.begin_group :eyecatcher - encoder.tokens deleted - encoder.end_group :eyecatcher + deleted_lines_count += 1 + if options[:inline_diff] && deleted_lines_count == 1 && (changed_lines_count = 1 + check(/(?>.*(?:\n\-.*)*)/).count("\n")) && match?(/(?>.*(?:\n\-.*){#{changed_lines_count - 1}}(?:\n\+.*){#{changed_lines_count}})$(?!\n\+)/) + deleted_lines = Array.new(changed_lines_count) { |i| skip(/\n\-/) if i > 0; scan(/.*/) } + inserted_lines = Array.new(changed_lines_count) { |i| skip(/\n\+/) ; scan(/.*/) } + + deleted_lines_tokenized = [] + inserted_lines_tokenized = [] + for deleted_line, inserted_line in deleted_lines.zip(inserted_lines) + pre, deleted_part, inserted_part, post = diff deleted_line, inserted_line + content_scanner_entry_state = content_scanner.state + deleted_lines_tokenized << content_scanner.tokenize([pre, deleted_part, post], :tokens => Tokens.new) + content_scanner.state = content_scanner_entry_state || :initial + inserted_lines_tokenized << content_scanner.tokenize([pre, inserted_part, post], :tokens => Tokens.new) end - encoder.tokens post - encoder.end_line line_kind - encoder.text_token "\n", :space - encoder.begin_line line_kind = :insert - encoder.text_token '+', :insert - content_scanner.state = content_scanner_entry_state || :initial - pre, inserted, post = content_scanner.tokenize [head, insertion, tail], :tokens => Tokens.new - encoder.tokens pre - unless inserted.empty? - encoder.begin_group :eyecatcher - encoder.tokens inserted - encoder.end_group :eyecatcher + + for pre, deleted_part, post in deleted_lines_tokenized + encoder.begin_line :delete + encoder.text_token '-', :delete + encoder.tokens pre + unless deleted_part.empty? + encoder.begin_group :eyecatcher + encoder.tokens deleted_part + encoder.end_group :eyecatcher + end + encoder.tokens post + encoder.end_line :delete + encoder.text_token "\n", :space + end + + for pre, inserted_part, post in inserted_lines_tokenized + encoder.begin_line :insert + encoder.text_token '+', :insert + encoder.tokens pre + unless inserted_part.empty? + encoder.begin_group :eyecatcher + encoder.tokens inserted_part + encoder.end_group :eyecatcher + end + encoder.tokens post + changed_lines_count -= 1 + if changed_lines_count > 0 + encoder.end_line :insert + encoder.text_token "\n", :space + end end - encoder.tokens post + + line_kind = :insert + elsif match = scan(/.*/) + encoder.begin_line line_kind = :delete + encoder.text_token '-', :delete if options[:highlight_code] - if deleted_lines == 1 + if deleted_lines_count == 1 content_scanner_entry_state = content_scanner.state end content_scanner.tokenize match, :tokens => encoder unless match.empty? diff --git a/lib/coderay/version.rb b/lib/coderay/version.rb index 9ffb7a9..e2797b5 100644 --- a/lib/coderay/version.rb +++ b/lib/coderay/version.rb @@ -1,3 +1,3 @@ module CodeRay - VERSION = '1.0.4' + VERSION = '1.0.5' end -- cgit v1.2.1 From c044a7a6eaba9ba47b8fde2cd6bdd444d8f87062 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Mon, 12 Dec 2011 04:50:36 +0100 Subject: simplify multiline diff regexp --- lib/coderay/scanners/diff.rb | 2 +- lib/coderay/scanners/erb.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/coderay') diff --git a/lib/coderay/scanners/diff.rb b/lib/coderay/scanners/diff.rb index 18ffa39..b890ed5 100644 --- a/lib/coderay/scanners/diff.rb +++ b/lib/coderay/scanners/diff.rb @@ -102,7 +102,7 @@ module Scanners next elsif match = scan(/-/) deleted_lines_count += 1 - if options[:inline_diff] && deleted_lines_count == 1 && (changed_lines_count = 1 + check(/(?>.*(?:\n\-.*)*)/).count("\n")) && match?(/(?>.*(?:\n\-.*){#{changed_lines_count - 1}}(?:\n\+.*){#{changed_lines_count}})$(?!\n\+)/) + if options[:inline_diff] && deleted_lines_count == 1 && (changed_lines_count = 1 + check(/.*(?:\n\-.*)*/).count("\n")) && match?(/(?>.*(?:\n\-.*){#{changed_lines_count - 1}}(?:\n\+.*){#{changed_lines_count}})$(?!\n\+)/) deleted_lines = Array.new(changed_lines_count) { |i| skip(/\n\-/) if i > 0; scan(/.*/) } inserted_lines = Array.new(changed_lines_count) { |i| skip(/\n\+/) ; scan(/.*/) } diff --git a/lib/coderay/scanners/erb.rb b/lib/coderay/scanners/erb.rb index 727a993..4f39e58 100644 --- a/lib/coderay/scanners/erb.rb +++ b/lib/coderay/scanners/erb.rb @@ -41,7 +41,7 @@ module Scanners end def scan_tokens encoder, options - + # FIXME: keep_state until eos? if (match = scan_until(/(?=#{START_OF_ERB})/o) || scan_rest) and not match.empty? -- 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 --- lib/coderay/scanners/ruby.rb | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'lib/coderay') 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(-) (limited to 'lib/coderay') 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(-) (limited to 'lib/coderay') 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(-) (limited to 'lib/coderay') 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(-) (limited to 'lib/coderay') 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) --- lib/coderay/scanners/html.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/coderay') 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) --- lib/coderay/scanners/php.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/coderay') 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(-) (limited to 'lib/coderay') 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(-) (limited to 'lib/coderay') 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 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 --- lib/coderay/encoders/html/output.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/coderay') 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 -- 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. --- lib/coderay/encoders/html/numbering.rb | 39 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'lib/coderay') 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 -- cgit v1.2.1 From 9cff8a25df888cea7cd8fa42df8115045c01a2eb Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sun, 10 Mar 2013 21:46:50 +0100 Subject: cleanup --- lib/coderay/scanners/erb.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/coderay') diff --git a/lib/coderay/scanners/erb.rb b/lib/coderay/scanners/erb.rb index 4f39e58..727a993 100644 --- a/lib/coderay/scanners/erb.rb +++ b/lib/coderay/scanners/erb.rb @@ -41,7 +41,7 @@ module Scanners end def scan_tokens encoder, options - # FIXME: keep_state + until eos? if (match = scan_until(/(?=#{START_OF_ERB})/o) || scan_rest) and not match.empty? -- cgit v1.2.1