Skip to content

Commit

Permalink
feat: add content format output options (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
adampash authored Feb 8, 2019
1 parent a57f29e commit 9b0664b
Show file tree
Hide file tree
Showing 106 changed files with 1,904 additions and 23,749 deletions.
25 changes: 19 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,38 @@
/* eslint-disable */

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

const [, , url] = process.argv;

(async urlToParse => {
const {
_: [url],
format,
f,
} = argv;
(async (urlToParse, contentType) => {
if (!urlToParse) {
console.log(
'\n\
mercury-parser\n\n\
The Mercury Parser extracts semantic content from any url\n\n\
Usage:\n\
\n\
mercury-parser [url-to-parse]\n\
$ mercury-parser url-to-parse [--format=html|text|markdown]\n\
\n\
'
);
return;
}
try {
const result = await Mercury.parse(urlToParse);
const contentTypeMap = {
html: 'html',
markdown: 'markdown',
md: 'markdown',
text: 'text',
txt: 'text',
};
const result = await Mercury.parse(urlToParse, null, {
contentType: contentTypeMap[contentType],
});
console.log(JSON.stringify(result, null, 2));
} catch (e) {
if (e.message === 'ETIMEDOUT' && false) {
Expand All @@ -38,4 +51,4 @@ Usage:\n\
console.error(`\n${reportBug}\n`);
process.exit(1);
}
})(url);
})(url, format || f);
Loading

0 comments on commit 9b0664b

Please sign in to comment.