middleman / middleman-syntax

Code syntax highlighting plugin via Rouge for Middleman
https://middlemanapp.com
MIT License
179 stars 57 forks source link

Force encoding to UTF8 before passing content to highlighter #31

Closed unity closed 10 years ago

unity commented 10 years ago

Rouge expects content to be a valid UTF8 string. If the string does not contain UTF-8 Characters, it is casted to ASCII-8BIT, Triggerring an error:

To reproduce: index.slim

- code('html') do
  == "BOB".force_encoding(Encoding::UTF_8)

=>

Bad encoding: ASCII-8BIT,BINARY. Please convert your string to UTF-8.

index.slim

- code('html') do
  == "BOBé".force_encoding(Encoding::UTF_8)

=> Works.

We make sure "content" passed to highlighter a valid UTF8 string.

bpainter commented 10 years ago

+1 on this fix. Just ran into the exact error running Slim.

bhollis commented 10 years ago

Thanks!