From 9a2edcce88880766825f46ae3725c90e9f6be3a8 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Fri, 9 Sep 2011 00:50:43 +0200 Subject: refactor erb scanner open tag matching to fix a minor bug --- lib/coderay/scanners/erb.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'lib/coderay/scanners') diff --git a/lib/coderay/scanners/erb.rb b/lib/coderay/scanners/erb.rb index eaf3bba..727a993 100644 --- a/lib/coderay/scanners/erb.rb +++ b/lib/coderay/scanners/erb.rb @@ -13,15 +13,15 @@ module Scanners KINDS_NOT_LOC = HTML::KINDS_NOT_LOC ERB_RUBY_BLOCK = / - <%(?!%)[=-]? - (?> + (<%(?!%)[-=\#]?) + ((?> [^\-%]* # normal* (?> # special (?: %(?!>) | -(?!%>) ) [^\-%]* # normal* )* - ) - (?: -?%> )? + )) + ((?: -?%> )?) /x # :nodoc: START_OF_ERB = / @@ -48,21 +48,25 @@ module Scanners @html_scanner.tokenize match, :tokens => encoder elsif match = scan(/#{ERB_RUBY_BLOCK}/o) - start_tag = match[/\A<%[-=#]?/] - end_tag = match[/-?%?>?\z/] + start_tag = self[1] + code = self[2] + end_tag = self[3] + encoder.begin_group :inline encoder.text_token start_tag, :inline_delimiter - code = match[start_tag.size .. -1 - end_tag.size] - if start_tag[/\A<%#/] + + if start_tag == '<%#' encoder.text_token code, :comment else @ruby_scanner.tokenize code, :tokens => encoder end unless code.empty? + encoder.text_token end_tag, :inline_delimiter unless end_tag.empty? encoder.end_group :inline else raise_inspect 'else-case reached!', encoder + end end -- cgit v1.2.1