Skip to content

Commit 9b0664b

Browse files
authored
feat: add content format output options (#256)
1 parent a57f29e commit 9b0664b

File tree

106 files changed

+1904
-23749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1904
-23749
lines changed

cli.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,38 @@
22
/* eslint-disable */
33

44
const Mercury = require('./dist/mercury');
5+
const argv = require('yargs-parser')(process.argv.slice(2));
56

6-
const [, , url] = process.argv;
7-
8-
(async urlToParse => {
7+
const {
8+
_: [url],
9+
format,
10+
f,
11+
} = argv;
12+
(async (urlToParse, contentType) => {
913
if (!urlToParse) {
1014
console.log(
1115
'\n\
1216
mercury-parser\n\n\
1317
The Mercury Parser extracts semantic content from any url\n\n\
1418
Usage:\n\
1519
\n\
16-
mercury-parser [url-to-parse]\n\
20+
$ mercury-parser url-to-parse [--format=html|text|markdown]\n\
1721
\n\
1822
'
1923
);
2024
return;
2125
}
2226
try {
23-
const result = await Mercury.parse(urlToParse);
27+
const contentTypeMap = {
28+
html: 'html',
29+
markdown: 'markdown',
30+
md: 'markdown',
31+
text: 'text',
32+
txt: 'text',
33+
};
34+
const result = await Mercury.parse(urlToParse, null, {
35+
contentType: contentTypeMap[contentType],
36+
});
2437
console.log(JSON.stringify(result, null, 2));
2538
} catch (e) {
2639
if (e.message === 'ETIMEDOUT' && false) {
@@ -38,4 +51,4 @@ Usage:\n\
3851
console.error(`\n${reportBug}\n`);
3952
process.exit(1);
4053
}
41-
})(url);
54+
})(url, format || f);

0 commit comments

Comments
 (0)