class Kramdown::Parser::Base

def extract_string(range, strscan)

method works correctly under Ruby 1.8 and Ruby 1.9.
Extract the part of the StringScanner +strscan+ backed string specified by the +range+. This
def extract_string(range, strscan)
  result = nil
  if strscan.string.respond_to?(:encoding)
    begin
      enc = strscan.string.encoding
      strscan.string.force_encoding('ASCII-8BIT')
      result = strscan.string[range].force_encoding(enc)
    ensure
      strscan.string.force_encoding(enc)
    end
  else
    result = strscan.string[range]
  end
  result
end