class Rouge::Lexers::Escape
def initialize(*)
def initialize(*) super @start = string_option(:start) { '<!' } @end = string_option(:end) { '!>' } @lang = lexer_option(:lang) { PlainText.new } end
def stream_tokens(str, &b)
def stream_tokens(str, &b) stream = StringScanner.new(str) loop do if stream.scan(to_start_regex) puts "pre-escape: #{stream[1].inspect}" if @debug @lang.continue_lex(stream[1], &b) else # no more start delimiters, scan til the end @lang.continue_lex(stream.rest, &b) return end if stream.scan(to_end_regex) yield Token::Tokens::Escape, stream[1] else yield Token::Tokens::Escape, stream.rest return end end end
def to_end_regex
def to_end_regex @to_end_regex ||= /(.*?)(#{Regexp.escape(@end)})/m end
def to_start_regex
def to_start_regex @to_start_regex ||= /(.*?)(#{Regexp.escape(@start)})/m end