html css js pretty,GitHub - berniey/html5print: HTML5, CSS, Javascript Pretty Print

HTML5 Pretty Print

This tool pretty print your HTML, CSS and JavaScript file. The package comes

with two parts:

a command line tool, html5-print

a python module, html5print

7cce2acc48dcd1ee0be9b042dcdeb37d.png

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d6c61746573742d627269676874677265656e2e7376673f7374796c653d706c6173746963

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f632d302e312e322d627269676874677265656e2e7376673f7374796c653d706c6173746963

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f736f757263652d6c61746573742d626c75652e7376673f7374796c653d706c6173746963

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d626c75652e7376673f7374796c653d706c6173746963

Introduction

This 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 it

Pretty print pure CSS and JavaScript

Try to fix fragmented HTML5

Try to fix HTML with broken unicode encoding

Try to guess encoding of the document, and in some cases manage

to convert 8-bit byte code back into correct UTF-8 format

Support both Python 2 and 3

Installation

$ [sudo] pip install html5print

Uninstallation

$ [sudo] pip uninstall html5print

$ [sudo] pip uninstall bs4 html5lib slimit tinycss2 requests chardet

Command Line Tool

Synopsis

$ html5-print --help

usage: html5-print [-h] [-o OUTFILE] [-s INDENT_WIDTH] [-e ENCODING]

[-t {html,js,css}] [-v]

infile

Beautify HTML5, CSS, JavaScript - Version 0.1.2 (By Bernard Yue)

This tool reformat the input and return a beautified version,

in unicode.

positional arguments:

infile filename | url | -, a dash, which represents stdin

optional arguments:

-h, --help show this help message and exit

-o OUTFILE, --output OUTFILE

filename for formatted HTML, stdout if omitted

-s INDENT_WIDTH, --indent-width INDENT_WIDTH

number of space for indentation, default 2

-e ENCODING, --encoding ENCODING

encoding of input, default UTF-8

-t {html,js,css}, --filetype {html,js,css}

type of file to parse, default "html"

-v, --version show program's version number and exit

Example

Pretty print HTML:

$ html5-print -s4 -

Press Ctrl-D when finished

Small HTML page

document.getElementById("demo").innerHTML = "Paragraph changed.";

}

Some text for testing

^D

Small HTML page

p {

margin : 10px 20px;

color : black;

}

function myFunction() {

document.getElementById("demo").innerHTML = "Paragraph changed.";

}

Some text for testing

$

Create valid HTML5 document from HTML fragment:

$ html5-print -s4 -

Press Ctrl-D when finished

Hello in different language

Here is "hello" in different languages

  • Hello
  • 您好
  • こんにちは
  • Dobrý den,
  • สวัสดี

    ^D

    Hello in different language

    Here is "hello" in different languages

    • Hello

    • 您好

    • こんにちは

    • Dobrý den,

    • สวัสดี

    $

    Python API

    This module requires Python 2.6+ (should work for Python

    3.0 and 3.1 but was not tested).

    Pretty Print HTML

    >>> from html5print import HTMLBeautifier

    >>> html = '

    Page Title

    Some text here

    '

    >>> print(HTMLBeautifier.beautify(html, 4))

    Testing

    Some Text

    >>>

    Pretty Print CSS

    Format common CSS

    >>> from html5print import CSSBeautifier

    >>> 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

    >>> from html5print import CSSBeautifier

    >>> 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

    >>> from html5print import JSBeautifier

    >>> 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

    }

    }

    Testing

    The module uses pytest. Use pip to install pytest

    if you do not have it installed.

    $ [sudo] pip install pytest

    Then checkout source code and run test as normal.

    $ git clone https://github.com/berniey/html5print.git

    $ python setup.py test

    You are encouraged to use virtualenv

    and virtualenvwrapper

    to avoid changing your currently operating environment.

    License

    This module is distributed under Apache License Version 2.0.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值