lib/kramdown/parser/base.rb in kramdown-0.13.8 vs lib/kramdown/parser/base.rb in kramdown-0.14.0
- old
+ new
@@ -60,11 +60,11 @@
# The @root element, the @warnings array and @text_type (specifies the default type for newly
# created text nodes) are automatically initialized.
def initialize(source, options)
@source = source
@options = Kramdown::Options.merge(options)
- @root = Element.new(:root, nil, nil, :encoding => (RUBY_VERSION >= '1.9' ? source.encoding : nil))
+ @root = Element.new(:root, nil, nil, :encoding => (source.encoding rescue nil))
@warnings = []
@text_type = :text
end
private_class_method(:new, :allocate)
@@ -113,10 +113,10 @@
# Extract the part of the StringScanner +strscan+ backed string specified by the +range+. This
# method works correctly under Ruby 1.8 and Ruby 1.9.
def extract_string(range, strscan)
result = nil
- if RUBY_VERSION >= '1.9'
+ 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