Skip to content
This repository was archived by the owner on Feb 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.c9*
.settings
node_modules
.idea

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ var worker = tidy.createWorker(opts);
request.get('http://www.nodejs.org').pipe(worker).pipe(process.stdout);
```

[Task runner](https://github.com/modulejs/modjs) support
--------------------------------------------------------

```javascript
// Modfile
module.exports = {
plugins: {
htmltidy: 'htmltidy'
},
tasks: {
htmltidy: {
src: ['foo.html', 'bar.html'],
dest: 'output/'
}
}
};
```

Platform support
----------------
* Linux
Expand Down
11 changes: 11 additions & 0 deletions examples/Modfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
plugins: {
htmltidy: '../htmltidy'
},
tasks: {
htmltidy: {
src: 'input/*.html',
dest: 'output/'
}
}
};
2 changes: 2 additions & 0 deletions examples/input/bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<title>bar</title>
<table><tr><td>badly formatted html</tr>
2 changes: 2 additions & 0 deletions examples/input/foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<title>foo</title>
<table><tr><td>badly formatted html</tr>
36 changes: 36 additions & 0 deletions htmltidy.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,41 @@ function merge(obj1, obj2) {
return obj3;
}

/**
* Task.JS API
* @param options
* @param done
* @see https://github.com/taskjs/spec
*/
function run(options, done){
var charset = options.charset;
var dest = options.dest;

delete options.src;
delete options.dest;
delete options.charset;

var async = exports.async;
var file = exports.file;

async.forEach(exports.files, function(inputFile, cb){
var outputFile = dest;
if(file.isFile(inputFile) && file.isDirFormat(dest)){
var filename = path.basename(inputFile);
outputFile = path.join(dest, filename);
}
var text = file.read(inputFile, charset);
tidy(text, options, function(err, html){
// output to file
if(html){
file.write(outputFile, html, charset);
exports.log(inputFile, '>', outputFile);
}
cb(err);
});
}, done);
}

exports.createWorker = createWorker;
exports.tidy = tidy;
exports.run = run;