This function provides the ability to compress your html response into a minimal format.
It will convert all newlines, tabs, linefeeds, 3-spaces, all down to one space. For most purposes it can actually compress your entire html page down to ONE line!
By default the function will not compress anything in between the pre, textarea, or blockqoute tags.
Warning
Since this compresses your output to the smallest possible size, you need to make sure that your javascript is syntatically valid. If you do not have your braces and semi-colons, your javascripts will break.
Warning
Make sure you use blockqoutes for javascript comments. Otherwise, a single line comment will effectively comment out everything else on your script tag.
If debug is True, it will NOT compress your response period. This way you can control based on a boolean flag such as PRODUCTION.
Usage:
>>> from web2py_utils import output
>>> output.compress_output(response, debug=False,):
Alternatively, you can assign functions to be executed after the response has been compressed. This is useful if you wanted to take a memory snapshot of your application before web2py sends its response to the client.
@param data The html content.
>>> output.compress_output(response, funcs=[lambda data: guppy.heapy()])
Removes HTML or XML character references and entities from a text string.
This works similar to PHPs version.
@param text The HTML (or XML) source text. @return The plain text, as a Unicode string, if necessary.
Usage:
>>> decoded_text = output.html_entity_decode('<html>hello world</html>')
Performs syntax highlighting on text inside of dom_element Uses BeautifulSoup for processing and pygments for highlighting
@param content The HTML (or XML) content to parse @param dom_element The dom tag to search and replace with highlighted @return The content with highlighted code withing dom_element
Usage:
>>> html = __highlight__(html_content, dom_element='code', linenos=True, noclasses=True)
You can combine this with compress_output
>>> c_high = lambda html: __highlight__(html, dom_element='pre')
>>> compress_output(response, funcs=[c_high])