lib/kramdown/parser/base.rb in kramdown-1.14.0 vs lib/kramdown/parser/base.rb in kramdown-1.15.0

- old
+ new

@@ -87,16 +87,14 @@ end # Modify the string +source+ to be usable by the parser (unifies line ending characters to # +\n+ and makes sure +source+ ends with a new line character). def adapt_source(source) - if source.respond_to?(:encode) - if !source.valid_encoding? - raise "The source text contains invalid characters for the used encoding #{source.encoding}" - end - source = source.encode('UTF-8') + unless source.valid_encoding? + raise "The source text contains invalid characters for the used encoding #{source.encoding}" end + source = source.encode('UTF-8') source.gsub(/\r\n?/, "\n").chomp + "\n" end # This helper method adds the given +text+ either to the last element in the +tree+ if it is a # +type+ element or creates a new text element with the given +type+. @@ -111,19 +109,15 @@ # 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 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] + 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 result end end