From b092628426fa0398c2cde2e573e7f6996372e3e6 Mon Sep 17 00:00:00 2001 From: crdx Date: Mon, 29 Oct 2012 15:44:04 +0000 Subject: [PATCH] add --encoding argument (implements #1) --- lib/markdowns.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/markdowns.js b/lib/markdowns.js index 4afffbc..8a90ef0 100644 --- a/lib/markdowns.js +++ b/lib/markdowns.js @@ -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(); @@ -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 + "'..."); @@ -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); }