domFormat is a simple javascript library to get DOM nodes as formatted/pretty strings.
You can find the source code here:
https://github.com/skratchdot/domFormat
And some examples here:
http://projects.skratchdot.com/domFormat/examples/index-html5.html
Here are 2 bookmarklets: