Skip to content

Commit

Permalink
added lic info
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Glebsky committed Feb 18, 2014
1 parent 35169f1 commit aad760d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,48 @@

Convert HTML to JSONML or vice versa

##Installation

```
$ npm install -g jsonml-cli
```

##Usage

jsonml.js [options]
```
$ jsonml [options]
```

##Options

```
-o, --out <file> output file
-i, --in <file> input file
-u, --url <url> input URL
-o, --out <file> output file
-i, --in <file> input file
-u, --url <url> input URL
-s, --space [string] adds indentation, white space and line break
-s, --space [string] adds indentation, white space and line break
-n, --noProcInst don't generate processing instructions
-l, --lowerTagNames tag names in lower case
-L, --lowerAttrNames attribute names in lower case
-a, --childrenInArray children in separate array
-r, --requireAttr HTML -> JSONML: add attributes object in any case
-e, --decodeEntities HTML -> JSONML: decode Entities
-n, --noProcInst don't generate processing instructions
-l, --lowerTagNames tag names in lower case
-L, --lowerAttrNames attribute names in lower case
-a, --childrenInArray children in separate array
-r, --requireAttr HTML -> JSONML: add attributes object in any case
-e, --decodeEntities HTML -> JSONML: decode Entities
-v, --version output the version number
-h, --help output usage information
-v, --version output the version number
-h, --help output usage information
```

####Without -i, --in and -u, --url

input from stdin
input from stdin

####Without -o, --out

output to stdout
output to stdout

## Contributors

- Maqentaer

## MIT Licenced
32 changes: 26 additions & 6 deletions jsonml.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env node

/*
jsonml.js
Convert Convert HTML to JSONML or vice versa
Created: 2014-02-14
Copyright (c)2014 Roman Glebsky <[email protected]>
Distributed under The MIT License: http://github.com/Maqentaer/jsonml-cli/raw/master/LICENSE
*/

var fs = require('fs');
var request = require('request');
var html2jsonml = require('html2jsonml');
Expand All @@ -16,7 +26,7 @@ cli.optionHelp = function() {
var help = cli.optionHelpOld().split('\n');
help.push(help.shift());
return help.join('\n');
}
};

cli
.description('Convert HTML to JSONML or vice versa')
Expand Down Expand Up @@ -53,7 +63,9 @@ var isJson = function(data) {
var saveData = function(data) {
if (cli['out']) {
fs.writeFile(cli['out'], data, function(err) {
if (err) showError(err);
if (err) {
showError(err);
}
});
} else {
process.stdout.write(data);
Expand All @@ -78,25 +90,33 @@ var parseData = function(data) {
return showError(err);
}
json2html(jsonML, options, function(err, html) {
if (err) return showError(err);
if (err) {
return showError(err);
}
saveData(html);
});
} else {
html2jsonml(data, options, function(err, jsonMl) {
if (err) return showError(err);
if (err) {
return showError(err);
}
saveData(JSON.stringify(jsonMl, null, options.space));
});
}
};

if (cli['url']) {
request(cli['url'], function(err, res, body) {
if (err) return showError(err);
if (err) {
return showError(err);
}
parseData(body);
});
} else if (cli['in']) {
fs.readFile(cli['in'], 'utf8', function(err, content) {
if (err) return showError(err);
if (err) {
return showError(err);
}
parseData(content);
});
} else {
Expand Down
10 changes: 10 additions & 0 deletions lib/json2html.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
json2html.js
Convert JSONML to HTML
Created: 2014-02-14
Copyright (c)2014 Roman Glebsky <[email protected]>
Distributed under The MIT License: http://github.com/Maqentaer/jsonml-cli/raw/master/LICENSE
*/

var isDoubleQuote = /"/g
var isSingleQuote = /'/g

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jsonml-cli",
"version": "0.1.0",
"description": "Parse HTML and convert to JSONML",
"description": "Convert HTML to JSONML or vice versa",
"main": "./jsonml",
"bin": {
"jsonml": "./bin/jsonml"
Expand Down

0 comments on commit aad760d

Please sign in to comment.