Skip to content

Markdown text is not encoded #63

Description

@spoike

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions