-
-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·40 lines (33 loc) · 919 Bytes
/
cli.js
File metadata and controls
executable file
·40 lines (33 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node
var optimist = require('optimist');
var htmlToText = require('../lib/html-to-text');
var argv = optimist
.string('tables')
.default('wordwrap', 80)
.default('ignore-href', false)
.default('ignore-image', false)
.default('ignore-video', false)
.argv;
var text = '';
process.title = 'html-to-text';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function data(data) {
text += data;
});
process.stdin.on('end', function end() {
text = htmlToText.fromString(text, {
tables: interpretTables(argv.tables),
wordwrap: argv.wordwrap,
ignoreHref: argv['ignore-href'],
ignoreImage: argv['ignore-image'],
ignoreVideo: argv['ignore-video']
});
process.stdout.write(text + '\n', 'utf-8');
});
function interpretTables(tables) {
if (!tables || tables === '' || tables === 'false') {
return [];
}
return tables === 'true' || tables.split(',');
}