librelist archives

« back to archive

How to use Tidy with Flask

How to use Tidy with Flask

From:
Stephane Wirtel
Date:
2010-05-17 @ 15:44
Hi all,

I don't like to see an ugly code and sometimes I prefer to use a beautifier.

so, I propose this small code to use the Tidy tools to re-indent and get a
beautiful html code

[code]
import tidy

@app.after_request
def after_request(response):
    options = dict(output_xhtml=1, add_xml_decl=1, indent=1, tidy_mark=0)
    response.data = tidy.parseString(response.data, **options)
    return response
[/code]

Hope this help

Regards,

Stephane

Re: [flask] How to use Tidy with Flask

From:
Armin Ronacher
Date:
2010-05-17 @ 16:24
Hi,

On 2010-05-17 5:44 PM, Stephane Wirtel wrote:
> so, I propose this small code to use the Tidy tools to re-indent
 > and get a beautiful html code
I recommend putting that to the snippet library so that others can find 
it there: http://flask.pocoo.org/snippets/

ALso, I would recommend checking if response.mimetype is 
application/xhtml+xml before running that thing, otherwise it will work 
on HTML and other content such as CSS as well which is probably not what 
you want.


Regards,
Armin

Re: [flask] How to use Tidy with Flask

From:
Stephane Wirtel
Date:
2010-05-17 @ 17:18
I agree with about the mimetype. I fixed this point in my code but nit  
in the email.

is it possible to override the after_request more once ?

Or extend with some hooks ?

Written from my iPhone !

Le 17 mai 2010 à 18:24, Armin Ronacher <armin.ronacher@active-4.com> a  
écrit :

> Hi,
>
> On 2010-05-17 5:44 PM, Stephane Wirtel wrote:
>> so, I propose this small code to use the Tidy tools to re-indent
>> and get a beautiful html code
> I recommend putting that to the snippet library so that others can  
> find
> it there: http://flask.pocoo.org/snippets/
>
> ALso, I would recommend checking if response.mimetype is
> application/xhtml+xml before running that thing, otherwise it will  
> work
> on HTML and other content such as CSS as well which is probably not  
> what
> you want.
>
>
> Regards,
> Armin

Re: [flask] How to use Tidy with Flask

From:
Armin Ronacher
Date:
2010-05-17 @ 17:33
Hi,

Multiple after_request handlers are possible.

Regards,
Armin

(sent from a handheld device)

On 17.05.2010, at 19:18, Stephane Wirtel <stephane@wirtel.be> wrote:

> I agree with about the mimetype. I fixed this point in my code but nit
> in the email.
>
> is it possible to override the after_request more once ?
>
> Or extend with some hooks ?
>
> Written from my iPhone !
>
> Le 17 mai 2010 à 18:24, Armin Ronacher <armin.ronacher@active-4.com> 
>  a
> écrit :
>
>> Hi,
>>
>> On 2010-05-17 5:44 PM, Stephane Wirtel wrote:
>>> so, I propose this small code to use the Tidy tools to re-indent
>>> and get a beautiful html code
>> I recommend putting that to the snippet library so that others can
>> find
>> it there: http://flask.pocoo.org/snippets/
>>
>> ALso, I would recommend checking if response.mimetype is
>> application/xhtml+xml before running that thing, otherwise it will
>> work
>> on HTML and other content such as CSS as well which is probably not
>> what
>> you want.
>>
>>
>> Regards,
>> Armin

Re: [flask] How to use Tidy with Flask

From:
Thadeus Burgess
Date:
2010-05-17 @ 20:52
Tidy breaks things if you have custom formatting in your content,
(like code snippet in a blog).

I usually use firebug, which formats everything for me, and a
compressor to reduce my output to its minimal format.

--
Thadeus





On Mon, May 17, 2010 at 12:33 PM, Armin Ronacher
<armin.ronacher@active-4.com> wrote:
> Hi,
>
> Multiple after_request handlers are possible.
>
> Regards,
> Armin
>
> (sent from a handheld device)
>
> On 17.05.2010, at 19:18, Stephane Wirtel <stephane@wirtel.be> wrote:
>
>> I agree with about the mimetype. I fixed this point in my code but nit
>> in the email.
>>
>> is it possible to override the after_request more once ?
>>
>> Or extend with some hooks ?
>>
>> Written from my iPhone !
>>
>> Le 17 mai 2010 à 18:24, Armin Ronacher <armin.ronacher@active-4.com>
>>  a
>> écrit :
>>
>>> Hi,
>>>
>>> On 2010-05-17 5:44 PM, Stephane Wirtel wrote:
>>>> so, I propose this small code to use the Tidy tools to re-indent
>>>> and get a beautiful html code
>>> I recommend putting that to the snippet library so that others can
>>> find
>>> it there: http://flask.pocoo.org/snippets/
>>>
>>> ALso, I would recommend checking if response.mimetype is
>>> application/xhtml+xml before running that thing, otherwise it will
>>> work
>>> on HTML and other content such as CSS as well which is probably not
>>> what
>>> you want.
>>>
>>>
>>> Regards,
>>> Armin
>