As you may have guessed, css-beautify and html-beautify will beautify HTML and CSS. html-beautify will even beautify nested CSS and JavaScript in an HTML file. However, as the program itself is written in JavaScript, it's not as easy to install and use as other programs. You can't just download an .exe file and run it. Here's how to install and run it on Windows:
- Download and install node.js. This is actually a Windows program, not a JavaScript file as the name may suggest. It allows you to download applications written in JavaScript and run them from the Windows command line.
- Open a Windows command prompt and type
npm install -g js-beautify
. This will download and install three tools on your system: js-beautify, css-beautify and html-beautify. - To beautify a JavaScript file, type
js-beautify -f input.js -o output.js
at the command line. The same goes forcss-beautify
andhtml-beautify
. Note that html-beautify will also beautify CSS and JavaScript embedded in the HTML file, so it's kind of an all-in-one solution. All three tools also support stdin and stdout (typejs-beautify -h
for help)
Before:
<html><head><title>Test</title>
<style>
div.test { background-color: blue; }
</style>
<script>
function test()
{ alert("hello world" ) ;
}
</script>
</head>
<body><div class="test"></div></body>
</html>
After:
<html>
<head>
<title>Test</title>
<style>
div.test {
background-color: blue;
}
</style>
<script>
function test() {
alert("hello world");
}
</script>
</head>
<body>
<div class="test"></div>
</body>
</html>
Now isn't that beautiful?
No comments:
Post a Comment