Small HTML page

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Prettier pretty-printing of HTML, in Python.

License

nate-parrott/beautiful_print

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Better pretty-printing of HTML in Python

Sometimes you want to take ugly HTML and fix it up, adding proper indentation and consistent style and all that. The best way I found to do this in Python was through BeautifulSoup ‘s prettify function, but it didn’t do everything I needed. beautiful_print does.

  • choose the whitespace you want to use for indentation
  • break long lines
  • treat certain tags like as inline, and don’t insert new lines every time they’re encountered

And it’s built atop the HTML-parsing magic of BeautifulSoup.

$ pip install beautiful_print 
from beautiful_print import beautiful_print ugly_html = """  
it sure is hot inside this div! right?

Yep!

""" print beautiful_print(ugly_html)
it sure is hot inside this div! right?

Yep!

About

Prettier pretty-printing of HTML, in Python.

Источник

html5print 0.1.2

This tool pretty print your HTML, CSS and JavaScript file. The package comes with two parts:

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!

  • 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

Uninstallation

$  pip uninstall html5print  pip uninstall bs4 html5lib slimit tinycss2 requests chardet

Command Line Tool

Synopsis

$ html5-print —help html5-print OUTFILE INDENT_WIDTH ENCODING infile HTML5, CSS, JavaScript — Version Bernard Yue tool reformat the input and a beautified version, unicode. arguments: infile filename url -, a dash, which represents stdin arguments: -h, —help show this message and -o OUTFILE, —output OUTFILE filename formatted HTML, stdout omitted -s INDENT_WIDTH, —indent-width INDENT_WIDTH number of space indentation, default -e ENCODING, —encoding ENCODING encoding of input, default UTF-8 -t —filetype of file to parse, default -v, —version show program version number and

Example

$ html5-print -s4 - Ctrl-D when finished HTML page  margin: 10px 20px color: black  myFunction    text  testing       

Some text testing

Create valid HTML5 document from HTML fragment:

Python API

This module requires Python 2.6+ (should work for Python 3.0 and 3.1 but was not tested).

Pretty Print HTML

Some text here

Some Text

Pretty Print CSS

Pretty Print JavaScript

Testing

The module uses pytest. Use pip to install pytest if you do not have it installed.

Then checkout source code and run test as normal.

$ git clone https://github.com/berniey/html5print.git python setup.py You are encouraged to use virtualenv and virtualenvwrapper for to avoid changing your currently operating environment.

License

This module is distributed under Apache License Version 2.0.

Источник

HTML5 Print¶

This tool pretty print your HTML, CSS and JavaScript file. The package comes with two parts:

https://travis-ci.org/berniey/html5print.png?branch=master

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!

  • 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 ] [-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 , --filetype type of file to parse, default "html" -v, --version show program's version number and exit

Example¶

$ html5-print -s4 - Press Ctrl-D when finished  p function myFunction() 

Some text for testing ^D p function myFunction()

Some text for testing

$

Create valid HTML5 document from HTML fragment:

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

    Here is «hello» in different languages

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

    Testing¶

    The module uses pytest. Use pip to install pytest .

    $ tar zxf html5print-0.1.2.tar.gz $ cd html5print-0.1.2 $ python setup.py test 

    License¶

    This module is distributed under Apache License Version 2.0.

    Python API¶

    A CSS Beautifier that pretty print CSS. It loosely supports CSS3.

    Prettifing css by reindending to width of indent per level. css is expected to be a valid Cascading Style Sheet

    >>> # a single css rule >>> from html5print import CSSBeautifier >>> css = ".para < margin: 10px 20px; >" >>> print(CSSBeautifier.beautify(css)) .para  margin : 10px 20px; > 
    >>> # multiple css rules >>> from html5print import CSSBeautifier >>> css = ".para < margin: 10px 20px; >" >>> css += os.linesep + "p < border: 5px solid red; >" >>> print(CSSBeautifier.beautify(css)) .para  margin : 10px 20px; > p  border : 5px solid red; > 
    >>> # pseudo-class css rule >>> from html5print import CSSBeautifier >>> css = ' /* beginning of css*/\n ::after < margin: 10px 20px; >' >>> print(CSSBeautifier.beautify(css)) /* beginning of css*/ ::after  margin : 10px 20px; > 
    >>> # pseudo-class css rule with different indent >>> from html5print import CSSBeautifier >>> css = ' /* beginning of css*/\n ::after < margin: 10px 20px; >' >>> print(CSSBeautifier.beautify(css, 4)) /* beginning of css*/ ::after  margin : 10px 20px; > 
    >>> # pseudo-class css rules with comments in between >>> from html5print import CSSBeautifier >>> css = ' /* beginning of css*/\n ::after < margin: 10px 20px; >' >>> css += os.linesep + ' /* another comment */p >>> css += 'h1 : color: #36CFFF; font-weight: normal;>' >>> print(CSSBeautifier.beautify(css, 4)) /* beginning of css*/ ::after  margin : 10px 20px; > /* another comment */ p  h1 : color: #36CFFF; font-weight : normal; > 
    >>> # 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; > > 

    Beautifying CSS within the tag. HTML comments(s) (i.e. ) within the style tag , if any, will be moved to the end of the tag block.

    Note: The function assumes tag the first element in a new line containing the tag (except for whitespace). Indention of the style block will be the indent of tag plus one indent of current indentation

    html with CSS beautified (i.e. text within

    )

    >>> # pretty print css >>> from html5print import CSSBeautifier >>> html = ''' . . .para . . p .  . ''' >>> print(CSSBeautifier.beautifyTextInHTML(html))    .para  margin : 10px 20px; > p  color : red; font-style : normal; >  
    >>> # not the first element, no pretty print >>> from html5print import CSSBeautifier >>> html = ''' . .para . . p .  . ''' >>> print(CSSBeautifier.beautifyTextInHTML(html))   .para p  

    A Javascript Beautifier that pretty print Javascript

    Prettifing js by reindending to width of indent per level. js is expected to be a valid Javascipt

    >>> from html5print import JSBeautifier >>> js = '''function myFunction() . document.getElementById("demo").innerHTML = "Paragraph changed."; . >''' 
    >>> # test default indent of 2 spaces >>> print(JSBeautifier.beautify(js)) function myFunction()  document.getElementById("demo").innerHTML = "Paragraph changed."; > 
    >>> # test indent of 4 spaces >>> print(JSBeautifier.beautify(js, 4)) function myFunction()  document.getElementById("demo").innerHTML = "Paragraph changed."; > 

    Beautifying Javascript within the tag . HTML comments(s) (i.e. ) within the script tag, if any, will be moved to the end of the tag block

    html with javascript beautified (i.e. text within )

    >>> from html5print import JSBeautifier >>> js = ''' . function myFunction() . document.getElementById("demo").innerHTML = "Paragraph changed."; . > .  .  . ''' >>> print(JSBeautifier.beautifyTextInHTML(js))    function myFunction()  document.getElementById("demo").innerHTML = "Paragraph changed."; >   

    HTML Beautifier. Powered by BeautifulSoup 4

    Pretty print html with indentation of indent per level

    >>> # pretty print HTML >>> from html5print import HTMLBeautifier >>> html = '

    Some Text

    '
    >>> print(HTMLBeautifier.beautify(html)) Testing Some Text
    >>> # pretty print HTML with embedded CSS and Javascript >>> from html5print import HTMLBeautifier >>> html = ''' . p . h1 .  .  . 

    Some Text

    . . . ''' >>> print(HTMLBeautifier.beautify(html)) Testing p color : red; font-weight : nornal > h1 color : green; > Some Text function myFunction() document.getElementById("demo").innerHTML = "changed."; >

    Decoding text to encoding . If encoding is None, encoding will be guessed.

    Note: encoding provided will be disregarded if it causes decoding error

    new decoded text as unicode

    >>> import sys >>> from html5print import decodeText >>> s = 'Hello! 您好! こんにちは! halló!' >>> output = decodeText(s) >>> print(output) Hello! 您好! こんにちは! halló! >>> if sys.version_info[0] >= 3: . unicode = str >>> isinstance(output, unicode) True 

    Return True if text is unicode. False otherwise. Note that because the function has to work on both Python 2 and Python 3, u’’ cannot be used in doctest.

    >>> import sys >>> if sys.version_info[0] >= 3: . isUnicode(bytes('hello', 'ascii')) . else: . isUnicode(bytes('hello')) False 
    >>> import sys >>> if sys.version_info[0] >= 3: . unicode = str >>> isUnicode(unicode('hello')) True 

    Источник

    Читайте также:  What is html rich text editor
Оцените статью