Skip to content
Browse files

Initial commit

  • Loading branch information...
1 parent 15eaefc commit 37e712cdd4b63bf2f0e5d68e3d8bd37450b763e0 @leondealmeida committed May 3, 2012
Showing with 67 additions and 1 deletion.
  1. +4 −1 README.md
  2. +53 −0 index.js
  3. +10 −0 package.json
View
5 README.md
@@ -1,4 +1,7 @@
habisp-tidy
===========
-Node wrapper for HTML Tidy
+## Node wrapper for HTML Tidy
+
+This code was originally posted [here](http://stackoverflow.com/a/8220285/770155).
+This package is a mere packaging to that code.
View
53 index.js
@@ -0,0 +1,53 @@
+/*
+NodeJS binding for HTML Tidy
+
+Originally posted on StackOverflow
+http://stackoverflow.com/a/8220285/770155
+
+Code modified to only output corrected partial HTML
+*/
+
+var spawn = require('child_process').spawn;
+var fs = require('fs');
+
+var tidy = (function() {
+this.html = function(str, callback) {
+ var buffer = '';
+ var error = '';
+
+ if (!callback) {
+ throw new Error('No callback provided for tidy.html');
+ }
+ var ptidy = spawn(
+ 'tidy',
+ [
+ '--quiet', 'y',
+ '--markup', 'y',
+ '--output-xml', 'y',
+ '--input-xml', 'y',
+ '--show-warnings', 'n',
+ '--quote-nbsp', 'y',
+ '--preserve-entities', 'y',
+ '--wrap', '0'
+ ]);
+
+ ptidy.stdout.on('data', function (data) {
+ buffer += data;
+ });
+
+ ptidy.stderr.on('data', function (data) {
+ error += data;
+ });
+
+ ptidy.on('exit', function (code) {
+ //fs.writeFileSync('last_tidy.html', buffer, 'binary');
+ callback(buffer);
+ });
+
+ ptidy.stdin.write(str);
+ ptidy.stdin.end();
+}
+return this;
+})();
+
+module.exports = tidy;
View
10 package.json
@@ -0,0 +1,10 @@
+{
+ "name": "habisp-tidy",
+ "description": "Simple tidy wrapper for Tidy on Nodejs (code from StackOverflow)",
+ "version": "0.0.1",
+ "homepage": "https://github.com/leondealmeida/habisp-tidy/",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/leondealmeida/habisp-tidy.git"
+ }
+}

0 comments on commit 37e712c

Please sign in to comment.
Something went wrong with that request. Please try again.