mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-08-28 12:02:40 +00:00
![Jeremy Ruston](/assets/img/avatar_default.png)
Internal links don't work yet. @natecain - have I included the node module in the right way?
53 lines
1.0 KiB
JavaScript
Executable File
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);
|
|
});
|
|
|
|
}())
|