Permalink
Browse files

Modified logic to accomodate users who ask to have show-warnings = true

  • Loading branch information...
1 parent b13f6ba commit 2e7304dd87d500e4062dae0be1e276a65c83d5b7 @netpoetica netpoetica committed with Feb 24, 2013
Showing with 30 additions and 6 deletions.
  1. BIN bin/darwin/tidy
  2. +5 −0 examples/basic.js
  3. +25 −6 htmltidy.js
View
Binary file not shown.
View
@@ -5,6 +5,11 @@ var text = '<table><tr><td>badly formatted html</tr>';
// default options
tidy(text, function(err, html) {
+ // If the user has enabled warning messages, show them.
+ if(err){
+ console.log(err);
+ }
+
console.log(html);
});
View
@@ -11,20 +11,24 @@ var TIDY_ERR = 2;
// default tidy opts
var DEFAULT_OPTS = {
- showWarnings: false,
+ showWarnings: true,
tidyMark: false,
forceOutput: true,
- quiet: true
- }
+ quiet: false
+};
// choose suitable executable
var tidyExec = chooseExec();
function TidyWorker(opts) {
Stream.call(this);
+
+ // Store a reference to the merged options for consumption by error reporting logic
+ var mergedOpts = merge(opts, DEFAULT_OPTS);
+
this.writable= true;
this.readable= true;
- this._worker = spawn(tidyExec, parseOpts(merge(opts, DEFAULT_OPTS)));
+ this._worker = spawn(tidyExec, parseOpts(mergedOpts));
var self = this;
var errors = '';
this._worker.stdin.on('drain', function () {
@@ -43,9 +47,24 @@ function TidyWorker(opts) {
errors+= data;
});
this._worker.on('exit', function (code) {
- if (code > TIDY_WARN)
- self.emit('error', errors);
+ switch(code){
+ // If there were any warnings or errors from Tiny command
+ case TIDY_WARN:
+ // The user asks to see warnings.
+ if(mergedOpts.showWarnings){
+ self.emit('error', errors);
+ }
+ break;
+ case TIDY_ERR:
+ // The user asks to see errors.
+ if(mergedOpts.showErrors){
+ self.emit('error', errors);
+ }
+ break;
+ }
+
self.emit('end');
+
});
}

0 comments on commit 2e7304d

Please sign in to comment.