blahed/frank — Issue #63: Markdown text is not encoded
Author: spoike
Created: 2011-12-16 15:59:32+00:00
State: open

The rendered text from a markdown sample does not encode the text. E.g. providing the following text:

```
Entré
```

It should escape the accented characters like this:

```
Entre´
```

I've installed the rdiscount gem for markdown support in Frank. So I don't know if Frank or Tilt is providing the wrong setting.

## Workarounds

I've found two workarounds. One is to encode the rendering your self, adding a function to do that in the `FrankHelpers` module. The other is to add a meta tag with correct encoding. So, I don't know if there should be an option in render that encodes the characters or if it should be documented that you should use meta-tag to avoid this problem.

### Add a function in `FrankHelpers` to encode the rendering

```
require 'cgi'
require 'htmlentities'

module FrankHelpers
def render_partial_encoded(path, *locals)
coder = HTMLEntities.new
encoded_text = coder.encode(render_partial(path), :named) # encode the text
CGI.unescapeHTML(encoded_text) # get back the HTML tags
end
end
```

However this requires you to install the cgi and htmlentities gems.

### Add the meta tag to use UTF-8 in your layout

`%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=UTF-8'}`