Package: html5print
This tool pretty print your HTML, CSS and JavaScript file.  The package comes
with two parts:a command line tool,html5-printa python module,html5printIntroductionThis module reformat web page code and make it more readable.  It is targeted
for developers, hence is not optimized for speed.  I start out looking for a
tool, ended up created this module.  Hope it helps you!Key features:Pretty print HTML as well as embedded CSS and JavaScript within itPretty print pure CSS and JavaScriptTry to fix fragmented HTML5Try to fix HTML with broken unicode encodingTry to guess encoding of the document, and in some cases manage
to convert 8-bit byte code back into correct UTF-8 formatSupport both Python 2 and 3Installation$[sudo]pipinstallhtml5printUninstallation$[sudo]pipuninstallhtml5print$[sudo]pipuninstallbs4html5libslimittinycss2requestschardetCommand Line ToolSynopsis$html5-print--helpusage:html5-print[-h][-oOUTFILE][-sINDENT_WIDTH][-eENCODING][-t{html,js,css}][-v]infileBeautifyHTML5,CSS,JavaScript-Version0.1.2(ByBernardYue)Thistoolreformattheinputandreturnabeautifiedversion,inunicode.positionalarguments:infilefilename|url|-,adash,whichrepresentsstdinoptionalarguments:-h,--helpshowthishelpmessageandexit-oOUTFILE,--outputOUTFILEfilenameforformattedHTML,stdoutifomitted-sINDENT_WIDTH,--indent-widthINDENT_WIDTHnumberofspaceforindentation,default2-eENCODING,--encodingENCODINGencodingofinput,defaultUTF-8-t{html,js,css},--filetype{html,js,css}typeoffiletoparse,default"html"-v,--versionshowprogram'sversionnumberandexitExamplePretty print HTML:$html5-print-s4-PressCtrl-Dwhenfinished<html><head><title>SmallHTMLpage</title><style>p{margin:10px20px;color:black;}</style><script>functionmyFunction(){document.getElementById("demo").innerHTML="Paragraph changed.";}</script></head><body><p>Sometextfortesting</body></html>^D<html><head><title>SmallHTMLpage</title><style>p{margin:10px20px;color:black;}</style><script>functionmyFunction(){document.getElementById("demo").innerHTML="Paragraph changed.";}</script></head><body><p>Sometextfortesting</p></body></html>$Create valid HTML5 document from HTML fragment:$html5-print-s4-PressCtrl-Dwhenfinished<title>Helloindifferentlanguage</title><p>Hereis"hello"indifferentlanguages</p><ul><li>Hello<li>您好<li>こんにちは<li>Dobrýden,<li>สวัสดี^D<html><head><title>Helloindifferentlanguage</title></head><body><p>Hereis"hello"indifferentlanguages</p><ul><li>Hello</li><li>您好</li><li>こんにちは</li><li>Dobrýden,</li><li>สวัสดี</li></ul></body></html>$Python APIThis module requires Python 2.6+ (should work for Python
3.0 and 3.1 but was not tested).Pretty Print HTML>>>fromhtml5printimportHTMLBeautifier>>>html='<title>Page Title</title><p>Some text here</p>'>>>print(HTMLBeautifier.beautify(html,4))<html>
    <head>
        <title>
            Testing
        </title>
    </head>
    <body>
        <p>
            Some Text
        </p>
    </body>
</html>
<BLANKLINE>>>>Pretty Print CSSFormat common CSS>>>fromhtml5printimportCSSBeautifier>>>css="""....para { margin: 10px 20px;.../* Cette règle contrôle l'espacement de tous les côtés \*/""">>>print(CSSBeautifier.beautify(css,4)).para {
    margin              : 10px 20px; /* Cette règle contrôle l'espacement de tous les côtés \*/
}Format media query>>>fromhtml5printimportCSSBeautifier>>>css='''@media (-webkit-min-device-pixel-ratio:0) {...h2.collapse { margin: -22px 0 22px 18px;...}...::i-block-chrome, h2.collapse { margin: 0 0 22px 0; } }...'''>>>print(CSSBeautifier.beautify(css,4))@media (-webkit-min-device-pixel-ratio:0) {
    h2.collapse {
        margin              : -22px 0 22px 18px;
    }
    ::i-block-chrome, h2.collapse {
        margin              : 0 0 22px 0;
    }
}Pretty Print JavaScript>>>fromhtml5printimportJSBeautifier>>>js='''..."use strict"; /* Des bribes de commentaires ici et là \*/...function MSIsPlayback() { try { return parent && parent.WebPlayer }...catch (e) { return !1 } }...'''>>>print(JSBeautifier.beautify(js,4))"use strict"; /* Des bribes de commentaires ici et là \*/

function MSIsPlayback() {
    try {
        return parent && parent.WebPlayer
    } catch (e) {
        return !1
    }
}TestingThe module usespytest.  Use pip to installpytestif you do not have it installed.$[sudo]pipinstallpytestThen checkout source code and run test as normal.$gitclonehttps://github.com/berniey/html5print.git$pythonsetup.pytestYou are encouraged to usevirtualenvandvirtualenvwrapperfor to avoid changing your currently operating environment.LicenseThis module is distributed under Apache License Version 2.0.