-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roman Glebsky
committed
Feb 18, 2014
1 parent
35169f1
commit aad760d
Showing
4 changed files
with
66 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
@@ -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') | ||
|
@@ -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); | ||
|
@@ -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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters