Skip to content

Commit

Permalink
Make requires for beautify-html.js compatible with different systems.
Browse files Browse the repository at this point in the history
Closes #202
  • Loading branch information
bitwiseman committed Apr 3, 2013
1 parent fa6e597 commit 1768f57
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions beautify-html.js
Expand Up @@ -60,12 +60,8 @@
*/

(function() {
if (typeof process !== 'undefined' && process.argv[0] === "node") {
var css_beautify = require(__dirname + '/beautify-css.js').css_beautify;
var js_beautify = require(__dirname + '/beautify.js').js_beautify;
}

function style_html(html_source, options) {
function style_html(html_source, options, js_beautify, css_beautify) {
//Wrapper function to invoke all the necessary constructors and deal with the output.

var multi_parser,
Expand Down Expand Up @@ -616,14 +612,26 @@
if (typeof define === "function") {
// Add support for require.js
define(function(require, exports, module) {
exports.html_beautify = style_html;
var js_beautify = require('./beautify.js').js_beautify;
var css_beautify = require('./beautify-css.js').css_beautify;

exports.html_beautify = function(html_source, options) {
return style_html(html_source, options, js_beautify, css_beautify);
};
});
} else if (typeof exports !== "undefined") {
// Add support for CommonJS. Just put this file somewhere on your require.paths
// and you will be able to `var html_beautify = require("beautify").html_beautify`.
exports.html_beautify = style_html;
var js_beautify = require('./beautify.js').js_beautify;
var css_beautify = require('./beautify-css.js').css_beautify;

exports.html_beautify = function(html_source, options) {
return style_html(html_source, options, js_beautify, css_beautify);
};
} else if (typeof window !== "undefined") {
// If we're running a web page and don't have either of the above, add our one global
window.html_beautify = style_html;
window.html_beautify = function(html_source, options) {
return style_html(html_source, options, window.js_beautify, window.css_beautify);
};;
}
}());
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -264,7 +264,7 @@
opts.space_after_anon_function = true;

if (looks_like_html(source)) {
output = style_html(source, opts);
output = html_beautify(source, opts);
} else {
if ($('#detect-packers').attr('checked')) {
source = unpacker_filter(source);
Expand Down

0 comments on commit 1768f57

Please sign in to comment.