source: node_modules/remarkable/dist/cjs/cli.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
5var fs = _interopDefault(require('fs'));
6var argparse = _interopDefault(require('argparse'));
7var index = require('./index.js');
8require('autolinker');
9var linkify = require('./linkify.js');
10
11var version = "2.0.1";
12
13////////////////////////////////////////////////////////////////////////////////
14
15var cli = new argparse.ArgumentParser({
16 prog: 'remarkable',
17 version: version,
18 addHelp: true
19});
20
21cli.addArgument([ 'file' ], {
22 help: 'File to read',
23 nargs: '?',
24 defaultValue: '-'
25});
26
27var options = cli.parseArgs();
28
29
30function readFile(filename, encoding, callback) {
31 if (options.file === '-') {
32 var chunks = [];
33
34 // read from stdin
35 process.stdin.on('data', function(chunk) {
36 chunks.push(chunk);
37 });
38
39 process.stdin.on('end', function() {
40 return callback(null, Buffer.concat(chunks).toString(encoding));
41 });
42 } else {
43 fs.readFile(filename, encoding, callback);
44 }
45}
46
47
48////////////////////////////////////////////////////////////////////////////////
49
50readFile(options.file, 'utf8', function (err, input) {
51 var output, md;
52
53 if (err) {
54 if (err.code === 'ENOENT') {
55 console.error('File not found: ' + options.file);
56 process.exit(2);
57 }
58
59 console.error(err.stack || err.message || String(err));
60 process.exit(1);
61 }
62
63 md = new index.Remarkable('full', {
64 html: true,
65 xhtmlOut: true,
66 typographer: true,
67 }).use(linkify.linkify);
68
69 try {
70 output = md.render(input);
71 } catch (e) {
72 console.error(e.stack || e.message || String(e));
73 process.exit(1);
74 }
75
76 process.stdout.write(output);
77 process.exit(0);
78});
Note: See TracBrowser for help on using the repository browser.