Skip to content

Commit

Permalink
add --encoding argument (implements #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
crdx committed Oct 29, 2012
1 parent 2d52787 commit b092628
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/markdowns.js
Expand Up @@ -17,6 +17,7 @@ parser.addArgument([ "-V", "--verbose" ], { action: "storeTrue", help: "Be verbo
parser.addArgument([ "-d", "--debug" ], { action: "storeTrue", help: "Show debugging output." });
parser.addArgument([ "-e", "--extension" ], { defaultValue: "md", help: "Set the file extension of Markdown files. Defaults to md." });
parser.addArgument([ "-f", "--force" ], { action: "storeTrue", help: "Ignore warnings." });
parser.addArgument([ "-n", "--encoding" ], { defaultValue: "utf8", help: "Set the file encoding of the output files (ascii or utf8). Defaults to utf8." });
parser.addArgument([ "directory" ], { defaultValue: ".", nargs: "?", help: "The directory to process or watch. Defaults to the current directory." });

var args = parser.parseArgs();
Expand All @@ -33,6 +34,9 @@ if (!fs.statSync(args.directory).isDirectory())
if (args.extension === "html" && !args.force)
return console.warn("Warning: using extension 'html' could result in data loss. If you're sure you want to do this, try --force.");

if (args.encoding != "utf8" && args.encoding != "ascii")
return console.error("Error: encoding must be utf8 or ascii.");

if (args.process)
{
console.log("Processing '*." + args.extension + "' files in '" + args.directory + "'...");
Expand Down Expand Up @@ -93,7 +97,7 @@ function writeHtmlFile(inputFilePath, markdown)
var html = marked(markdown.toString('utf8'));
var outputFilePath = path.join(path.dirname(inputFilePath), path.basename(inputFilePath, path.extname(inputFilePath)) + ".html");

fs.writeFileSync(outputFilePath, html, 'utf8');
fs.writeFileSync(outputFilePath, html, args.encoding);
console.log("Success:", inputFilePath, "->", outputFilePath);
}

Expand Down

0 comments on commit b092628

Please sign in to comment.