README
Victorica
a simple html beautifier
Installation
Via npm
$ npm install victorica --save
var victorica= require('victorica');
console.log(victorica); //function
Via bower
$ bower install victorica --save
<script src="bower_components/victorica/victorica.min.js"></script>
<script>
console.log(victorica); //function
</script>
Via rawgit.com(the simple way)
<script src="https://cdn.rawgit.com/59naga/victorica/v0.0.1/victorica.min.js"></script>
<script>
console.log(victorica); //function
</script>
API
victorica(html,options) -> beautified
Adjust the indentation using options.space
(default
).
<!DOCTYPE html><html>
<head><meta charset="UTF-8" />
<title>index.html</title><script>
console.log("<dont touch this>");
</script><style>/*ignore me*/</style></head>
<body><pre>foo bar baz</pre><div>
<span><strong>Lorem</strong> <em>ipsum</em> dolor sit amet.</span>
<pre> dont touch
this. </pre>
</div><!--this
is
comment -->
</body>
</html>
victorica
of default:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index.html</title>
<script>
console.log("<dont touch this>");
</script>
<style>/*ignore me*/</style>
</head>
<body>
<pre>foo bar baz</pre>
<div>
<span><strong>Lorem</strong> <em>ipsum</em> dolor sit amet.</span>
<pre> dont touch
this. </pre>
</div>
<!--this
is
comment -->
</body>
</html>
usage:
// Dependencies
var victorica= require('victorica');
var fs= require('fs');
var html= fs.readFileSync('index.html','utf8');
// Defaults
var options= {
// indentation character
space: ' ',
// doesn't handle the innerHTML of matching elements
ignore: ['script','style','title','a','abbr','acronym','b','bdo','big','button','cite','code','dfn','em','i','img','kbd','label','map','object','pre','q','samp','small','span','strong','sub','sup','textarea','tt','var'],
// if true, remove self closing char (e.g <img /> -> <img>)
removeSelfClose: true,
};
console.log(victorica(html,options));