1

I ran into a problem while I was working with Earmark, an Elixir library for rendering markdown, on Windows 10. Whenever the text contained single or double quotes, the rendered markup appeared as gibberish on the console or in the rendered html file.

What makes no sense is that I can use single and double quotes and they render correctly on the console. It only becomes gibberish once Earmark processes the text.

Hugo Estrada
  • 607
  • 1
  • 8
  • 18

1 Answers1

1

With the help of a number of people in the Elixir community, I was able to find two solutions to the problem.

The problem stems from Elixir's default use of utf-8 as the basic encoding for strings. This in itself is not a problem. It becomes a problem because Windows' console subsystem has a poor handling of utf-8.

Earmark uses smartypants to transform single and double quotes into curly single and double quotes. This is where Windows' console gets confused and prints gibberish.

Solutions:

  1. For the html rendering

The best solution here is to add utf-8 encoding in the template for the final html page.

<meta charset="utf-8" /> 

If you don't care about smart quotes, then you can also call Earmark with the smartypants option set to false to avoid using it

Earmark.as_html(markdown, %Earmark.Options{smartypants: false}) 
  1. For the console

Here you need to set the the console font to Lucida and run the command below , according to this question on stackoverflow

chcp 65001

I used it and it worked on my Windows 10 machine.

Notes: Thanks for Iinspectable for correcting a statement on Windows and utf-8 :)

Community
  • 1
  • 1
Hugo Estrada
  • 607
  • 1
  • 8
  • 18
  • Thanks to the DC Elixir community who helped me a lot to find the solution :) – Hugo Estrada May 15 '17 at 14:27
  • 3
    *"Windows has a poor handling of utf-8"* - That's not correct. Windows has no problems with UTF-8 at all. It's really only the console subsystem, that doesn't cope well with UTF-8 (or Unicode in general, for that matter). – IInspectable May 15 '17 at 17:14
  • Thanks for the correction. Let me update the text then :) – Hugo Estrada May 18 '17 at 14:59