Skip to content

Commit

Permalink
Switch to ruby 1.9 String#encode with backward 1.8 compatibility (Iconv)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleas committed Nov 29, 2011
1 parent 16e8e54 commit 0dd3591
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/maruku/input/parse_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#++


require 'iconv'


module MaRuKu; module In; module Markdown; module BlockLevelParser

def parse_doc(s)
Expand All @@ -39,21 +35,23 @@ def parse_doc(s)
If the `encoding` attribute is specified, then the content
will be converted from the specified encoding to UTF-8.
Conversion happens using the `iconv` library.
=end

enc = self.attributes[:encoding]
self.attributes.delete :encoding
if enc && enc.downcase != 'utf-8'
converted = Iconv.new('utf-8', enc).iconv(data)

# puts "Data: #{data.inspect}: #{data}"
# puts "Conv: #{converted.inspect}: #{converted}"

data = converted

# Switch to ruby 1.9 String#encode
# with backward 1.8 compatibility
if data.respond_to?(:encode!)
data.encode!('UTF-8', enc)
else
require 'iconv'
data = Iconv.new('utf-8', enc).iconv(data)
end

end

@children = parse_text_as_markdown(data)

if true #markdown_extra?
Expand Down

0 comments on commit 0dd3591

Please sign in to comment.