Online Tools like Beautifiers, Editors, Viewers, Minifier, Validators, Converters for Developers: XML, JSON, CSS, JavaScript, Java, C#, MXML, SQL, CSV, Excel
HTML - Best HTML Viewer, HTML Beautifier, HTML Formatter and to Test / Preview ...
Check if HTML snippet is valid with Javascript - based on this I "validate" the html but I don't know if it's necessary to you, if you want or not to have just the output to be correct (even if the html string you paste is not 100% correct). If you want only the output to be correct then Devan's answer is the most simple
function tidy(html) {
var d = document.createElement('div');
d.innerHTML = html;
return d.innerHTML;
}
function print(){
//get input from textbox
var htmlInputValue = document.getElementById("htmlInput").value;
// "validate" as html
var result = tidy(htmlInputValue);
//print it
document.getElementById("result").innerHTML = result;
}
var myInput = document.getElementById("htmlInput");
myInput.addEventListener("input", print, false);
#result {
font-size: 40px;
font-weight: bold
}
<html>
<body>
<label for="input">Enter your html here </label>
<input class="myInput" id="htmlInput" value="">
<p id="result"/>
</body>
</html>
Edit: i added some css for bold and large text #result { font-size: 40px; font-weight: bold }
You can use the JSON.stringify function with unformatted JSON. It outputs it in a formatted way.
JSON.stringify({ foo: "sample", bar: "sample" }, null, 4)
This turns
{ "foo": "sample", "bar": "sample" }
into
{
"foo": "sample",
"bar": "sample"
}
Now the data is a readable format you can use the Google Code Prettify script as suggested by @A. Levy to colour code it.
It is worth adding that IE7 and older browsers do not support the JSON.stringify method.
If you are looking for a graphviz alternative, may be you could use jsPlumb Library. See some samples here
Also checkout JavaScript InfoVis Toolkit