creationix / wheat

Wheat is a blog engine for coders written in node.JS
Other
1.36k stars 134 forks source link

Assume UTF-8 encoding for .markdown and .haml - using new Git.readFile functionality #31

Open pirxpilot opened 13 years ago

pirxpilot commented 13 years ago

Only pull after new version of git-fs is published to npm. This should fix encoding problems #18, #28 etc. Tested with howtonode.org - seems OK.

Reads .markdown, .haml and snippets as "utf8" Everything else is read as raw buffers - no conversion needed.

creationix commented 13 years ago

Why not read everything as buffers. They automatically toString to utf8 strings when coerced.

pirxpilot commented 13 years ago

I had another look. I am pretty sure my patch loads them as strings (i.e. explicitly passing 'utf8' encoding) only when they are used as strings. The results of Git.readFile are passed to 'Haml.compile' and various string methods (substr, match etc.) are called on them: I don't think such usage triggers implicit coercion.

There was actually one explicit conversion that I was able to remove from prepareMarkdown:

if (!(typeof markdown === 'string')) {
  markdown = markdown.toString();
}

After reading your comment I experimented with loading everything as buffers and wheat predictably breaks in couple of places. What am I missing?