2

I have a Markdown text file, utf-8-encoded, that has some non-ASCII characters such as . I couldn't get the reference Perl implementation to handle these characters correctly, but I can get it work with Pandoc. I'd like to be able to render my Markdown file straight from Emacs, using C-c C-c p from Markdown mode, and that's still not working for me. I get what looks like a blank space instead of the non-ASCII character. For example,

I love apostrophe’s.

turns into

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>
  <style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<p>I love apostrophe s.</p>
</body>
</html>

Note that the HTML contains charset=utf-8. It's nearly identical to what I get running Pandoc from the command line, except for the missing apostrophe. I'm invoking Pandoc, whether from Emacs or the command prompt, using pandoc -f markdown -t html -s --mathjax --highlight-style pygments, which I got from here.

Can I get the apostrophe and other unicode characters to render properly from Emacs?

EDIT: using the C-u C-x = command that @db48x suggested, I verified that the blank character is a regular space (#x20)

kuzzooroo
  • 6,788
  • 11
  • 46
  • 84
  • 9
    You may love apostrophes, but you don’t use them correctly. :) –  Mar 21 '14 at 22:16
  • I did not downvote, so I can’t tell. –  Mar 21 '14 at 23:15
  • @kuzzooroo weak save :) – StackedCrooked Mar 21 '14 at 23:47
  • 1
    It might help if you use C-u C-x = to find out what the apparently-blank character actually is. – db48x Mar 27 '14 at 03:56
  • ObPedantic: The apostrophe in the sentence "I love apostrophe's" is an example of what is somewhat archaically known as the "[greengrocers' apostrophe](http://en.wikipedia.org/wiki/Apostrophe#Superfluous_apostrophes_.28.22greengrocers.27_apostrophes.22.29)". The More You Know™ – Aaron Miller Mar 31 '14 at 15:13

3 Answers3

2

I had the same problem with German Umlaut characters and figured out a solution: If I add the line

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

to the beginning of the markdown file it ends up in the html-file and, although embedded in <p></p> tags, works. C-c C-c e exports nicely my Umlauts and your apostrophe’s, too.

  • Didn't work for me. What implementation of markdown are you using, e.g., markdown.pl, pandoc, or something else? – kuzzooroo Aug 26 '15 at 18:41
  • I don't really know, how to check this. When I tried first, emacs exported a string "zsh: command not found: markdown". I installed the package discount (on fedora) which has a command line binary markdown. Now it works, so I guess it's this. The command itself only translates the body and doesn't put the header tags, nor the body tags. So emacs' markdown-mode must take care of that by itself. – Pieter Bruegel the Elder Aug 26 '15 at 22:38
  • Sounds like it's almost certainly discount. But just to check could you do `C-h v` and enter `markdown-command` as the variable to query? – kuzzooroo Aug 27 '15 at 21:56
  • wohoo, learnt something emacs today!... yes, it is "markdown" – Pieter Bruegel the Elder Aug 28 '15 at 18:24
2

To avoid typing <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the header of all your markdown files (which is not straightforward), you can tell the markdown mode of emacs to do this for you at compilation. You just have to customize the Markdown Xhtml Header Content variable and setting it to <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />.

You juste need to run M-x customize-mode, look for Markdown Xhtml Header Content and save with its new value.

Johann Bzh
  • 834
  • 3
  • 10
  • 25
1

Running M-x customize-variable and toggling markdown-command-needs-filename to on solved the problem for me.

kuzzooroo
  • 6,788
  • 11
  • 46
  • 84