lib/kramdown/parser/base.rb in kramdown-1.5.0 vs lib/kramdown/parser/base.rb in kramdown-1.6.0

- old
+ new

@@ -1,15 +1,16 @@ # -*- coding: utf-8 -*- # #-- -# Copyright (C) 2009-2014 Thomas Leitner <t_leitner@gmx.at> +# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at> # # This file is part of kramdown which is licensed under the MIT. #++ # -require 'kramdown/utils/string_scanner' +require 'kramdown/utils' +require 'kramdown/parser' module Kramdown module Parser @@ -49,11 +50,12 @@ # 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 => (source.encoding rescue nil), :location => 1) + @root = Element.new(:root, nil, nil, :encoding => (source.encoding rescue nil), :location => 1, + :options => {}, :abbrev_defs => {}, :abbrev_attr => {}) @warnings = [] @text_type = :text end private_class_method(:new, :allocate) @@ -86,10 +88,12 @@ # 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) - raise "The encoding of the source text is not valid!" if !source.valid_encoding? + if !source.valid_encoding? + raise "The source text contains invalid characters for the used encoding #{source.encoding}" + end source = source.encode('UTF-8') end source.gsub(/\r\n?/, "\n").chomp + "\n" end