1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-02 22:39:56 +00:00
TiddlyWiki5/node_modules/markdown/bin/md2html.js
Jeremy Ruston 36fa41e19a First pass at integrating a Markdown parser
Internal links don't work yet.

@natecain - have I included the node module in the right way?
2013-11-01 16:06:08 +00:00

53 lines
1.0 KiB
JavaScript
Executable File

#!/usr/bin/env node
(function () {
"use strict";
var fs = require("fs")
, markdown = require("markdown").markdown
, nopt = require("nopt")
, stream
, opts
, buffer = ""
;
opts = nopt(
{ "dialect": [ "Gruber", "Maruku"]
, "help": Boolean
}
);
if (opts.help) {
var name = process.argv[1].split("/").pop()
console.warn( require("util").format(
"usage: %s [--dialect=DIALECT] FILE\n\nValid dialects are Gruber (the default) or Maruku",
name
) );
process.exit(0);
}
var fullpath = opts.argv.remain[0];
if (fullpath && fullpath !== "-") {
stream = fs.createReadStream(fullpath);
} else {
stream = process.stdin;
}
stream.resume();
stream.setEncoding("utf8");
stream.on("error", function(error) {
console.error(error.toString());
process.exit(1);
});
stream.on("data", function(data) {
buffer += data;
});
stream.on("end", function() {
var html = markdown.toHTML(buffer, opts.dialect);
console.log(html);
});
}())