frank icon indicating copy to clipboard operation
frank copied to clipboard

Markdown text is not encoded

Open spoike opened this issue 14 years ago • 1 comments

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'}

spoike avatar Dec 16 '11 15:12 spoike

Will look into this for the next release.

trvsdnn avatar Jun 30 '12 15:06 trvsdnn