librelist archives

« back to archive

Flask and Markdown

Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-20 @ 10:53
Hi all,

I want to include the markdown python library in my web site with Flask.

Checked.

1. Use the library directly in the code

admin = Module(__name__)
@admin.route('/')
def index():
    import markdown

    text = """
Administration
==============
"""

    message = markdown.markdown(text)
    return render_template('administration/index.html', message=message)

But the result is not very useful, because I think jinja2 replaces some 
characters (<, >) with a html entity.

Result:
<h1>Administration</h1>


2. I found an example of code allowing to create an extension of Jinja2 to
support the Markdown style.

http://www.silassewell.com/blog/2010/05/10/jinja2-markdown-extension/

How can I extend Jinja2 in Flask ?

Regards,

Stéphane

Re: [flask] Flask and Markdown

From:
Kenneth Reitz
Date:
2010-05-20 @ 10:59
Stephanie:

Any interest in teaming up to build a Flask extension for Markdown?
 
See: http://flask.pocoo.org/extensions/

Thinking of doing this during lunch today.

Kenneth Reitz
http://kennethreitz.com/contact-me



On May 20, 2010, at 6:53 AM, Stephane Wirtel wrote:

> admin = Module(__name__)
> @admin.route('/')
> def index():
>    import markdown
> 
>    text = """
> Administration
> ==============

Re: [flask] Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-20 @ 11:09
Hi Kenneth:

1. Stephane and not Stephanie (it's not the same gender ;-))
   Stephane is male and Stephanie is female.

2. Yes, If I find how to integrate Markdown in my site, I can provide an 
extension for Flask, for example, flask-markdown

Regards,

Stephane
On 05/20/2010 12:59 PM, Kenneth Reitz wrote:
> Stephanie:
> 
> Any interest in teaming up to build a Flask extension for Markdown?
>  
> See: http://flask.pocoo.org/extensions/
> 
> Thinking of doing this during lunch today.
> 
> Kenneth Reitz
> http://kennethreitz.com/contact-me
> 
> 
> 
> On May 20, 2010, at 6:53 AM, Stephane Wirtel wrote:
> 
>> admin = Module(__name__)
>> @admin.route('/')
>> def index():
>>    import markdown
>>
>>    text = """
>> Administration
>> ==============
> 
> 

Re: [flask] Flask and Markdown

From:
Kenneth Reitz
Date:
2010-05-20 @ 11:13
Hah! Sorry about that.

I have a repository on GitHub setup. Can I add you as a collaborator?

Kenneth Reitz
http://kennethreitz.com/contact-me



On May 20, 2010, at 7:09 AM, Stephane Wirtel wrote:

> Hi Kenneth:
> 
> 1. Stephane and not Stephanie (it's not the same gender ;-))
>   Stephane is male and Stephanie is female.
> 
> 2. Yes, If I find how to integrate Markdown in my site, I can provide an
extension for Flask, for example, flask-markdown
> 
> Regards,
> 
> Stephane
> On 05/20/2010 12:59 PM, Kenneth Reitz wrote:
>> Stephanie:
>> 
>> Any interest in teaming up to build a Flask extension for Markdown?
>> 
>> See: http://flask.pocoo.org/extensions/
>> 
>> Thinking of doing this during lunch today.
>> 
>> Kenneth Reitz
>> http://kennethreitz.com/contact-me
>> 
>> 
>> 
>> On May 20, 2010, at 6:53 AM, Stephane Wirtel wrote:
>> 
>>> admin = Module(__name__)
>>> @admin.route('/')
>>> def index():
>>>   import markdown
>>> 
>>>   text = """
>>> Administration
>>> ==============
>> 
>> 
> 

Re: [flask] Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-20 @ 11:24
On 05/20/2010 01:13 PM, Kenneth Reitz wrote:
> Hah! Sorry about that.
Don't worry
> 
> I have a repository on GitHub setup. Can I add you as a collaborator?
Before to be a collaborator, I prefer to show my contributions.

I hope to integrate Markdown during this week, because I'm very busy with 
the OpenERP project
and I don't have the time to make a patch or an extension today.

Regards,

Stéphane

Re: [flask] Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-20 @ 17:13
ok, in the html file, use the safe filter on the output from markdown

in brief: 

{{ message|safe }}

I can propose a snippet for markdown

Regards
On 20 May 2010, at 13:24, Stephane Wirtel wrote:

> On 05/20/2010 01:13 PM, Kenneth Reitz wrote:
>> Hah! Sorry about that.
> Don't worry
>> 
>> I have a repository on GitHub setup. Can I add you as a collaborator?
> Before to be a collaborator, I prefer to show my contributions.
> 
> I hope to integrate Markdown during this week, because I'm very busy 
with the OpenERP project
> and I don't have the time to make a patch or an extension today.
> 
> Regards,
> 
> Stéphane
> 

Re: [flask] Flask and Markdown

From:
Dag Odenhall
Date:
2010-05-20 @ 17:26
from flask import Markup

message = Markup(markdown.markdown(text))

http://flask.pocoo.org/docs/api/#flask.Markup

tor 2010-05-20 klockan 19:13 +0200 skrev Stephane Wirtel:
> ok, in the html file, use the safe filter on the output from markdown
> 
> in brief: 
> 
> {{ message|safe }}
> 
> I can propose a snippet for markdown
> 
> Regards
> On 20 May 2010, at 13:24, Stephane Wirtel wrote:
> 
> > On 05/20/2010 01:13 PM, Kenneth Reitz wrote:
> >> Hah! Sorry about that.
> > Don't worry
> >> 
> >> I have a repository on GitHub setup. Can I add you as a collaborator?
> > Before to be a collaborator, I prefer to show my contributions.
> > 
> > I hope to integrate Markdown during this week, because I'm very busy 
with the OpenERP project
> > and I don't have the time to make a patch or an extension today.
> > 
> > Regards,
> > 
> > Stéphane
> > 
> 

Re: [flask] Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-20 @ 17:41
and I add something, jinja2 is configured to use the autoescape in the  
code of flask.

regards

Written from my iPhone !

Le 20 mai 2010 à 19:26, Dag Odenhall <dag.odenhall@gmail.com> a  
écrit :

> from flask import Markup
>
> message = Markup(markdown.markdown(text))
>
> http://flask.pocoo.org/docs/api/#flask.Markup
>
> tor 2010-05-20 klockan 19:13 +0200 skrev Stephane Wirtel:
>> ok, in the html file, use the safe filter on the output from markdown
>>
>> in brief:
>>
>> {{ message|safe }}
>>
>> I can propose a snippet for markdown
>>
>> Regards
>> On 20 May 2010, at 13:24, Stephane Wirtel wrote:
>>
>>> On 05/20/2010 01:13 PM, Kenneth Reitz wrote:
>>>> Hah! Sorry about that.
>>> Don't worry
>>>>
>>>> I have a repository on GitHub setup. Can I add you as a  
>>>> collaborator?
>>> Before to be a collaborator, I prefer to show my contributions.
>>>
>>> I hope to integrate Markdown during this week, because I'm very  
>>> busy with the OpenERP project
>>> and I don't have the time to make a patch or an extension today.
>>>
>>> Regards,
>>>
>>> Stéphane
>>>
>>
>
>

Re: [flask] Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-20 @ 17:40
markup will escape the HTML code with the HTML entities.

if the code generated by markdown should be inserted in a html page,  
the content must be safe with the safe filter.

but honnestly, I didn't read the documentation of markup.

regards

Written from my iPhone !

Le 20 mai 2010 à 19:26, Dag Odenhall <dag.odenhall@gmail.com> a  
écrit :

> from flask import Markup
>
> message = Markup(markdown.markdown(text))
>
> http://flask.pocoo.org/docs/api/#flask.Markup
>
> tor 2010-05-20 klockan 19:13 +0200 skrev Stephane Wirtel:
>> ok, in the html file, use the safe filter on the output from markdown
>>
>> in brief:
>>
>> {{ message|safe }}
>>
>> I can propose a snippet for markdown
>>
>> Regards
>> On 20 May 2010, at 13:24, Stephane Wirtel wrote:
>>
>>> On 05/20/2010 01:13 PM, Kenneth Reitz wrote:
>>>> Hah! Sorry about that.
>>> Don't worry
>>>>
>>>> I have a repository on GitHub setup. Can I add you as a  
>>>> collaborator?
>>> Before to be a collaborator, I prefer to show my contributions.
>>>
>>> I hope to integrate Markdown during this week, because I'm very  
>>> busy with the OpenERP project
>>> and I don't have the time to make a patch or an extension today.
>>>
>>> Regards,
>>>
>>> Stéphane
>>>
>>
>
>

Re: [flask] Flask and Markdown

From:
Dag Odenhall
Date:
2010-05-20 @ 17:48
Markup() marks a string as safe without the need to filter it.

tor 2010-05-20 klockan 19:40 +0200 skrev Stephane Wirtel:
> markup will escape the HTML code with the HTML entities.
> 
> if the code generated by markdown should be inserted in a html page,  
> the content must be safe with the safe filter.
> 
> but honnestly, I didn't read the documentation of markup.
> 
> regards
> 
> Written from my iPhone !
> 
> Le 20 mai 2010 à 19:26, Dag Odenhall <dag.odenhall@gmail.com> a  
> écrit :
> 
> > from flask import Markup
> >
> > message = Markup(markdown.markdown(text))
> >
> > http://flask.pocoo.org/docs/api/#flask.Markup
> >
> > tor 2010-05-20 klockan 19:13 +0200 skrev Stephane Wirtel:
> >> ok, in the html file, use the safe filter on the output from markdown
> >>
> >> in brief:
> >>
> >> {{ message|safe }}
> >>
> >> I can propose a snippet for markdown
> >>
> >> Regards
> >> On 20 May 2010, at 13:24, Stephane Wirtel wrote:
> >>
> >>> On 05/20/2010 01:13 PM, Kenneth Reitz wrote:
> >>>> Hah! Sorry about that.
> >>> Don't worry
> >>>>
> >>>> I have a repository on GitHub setup. Can I add you as a  
> >>>> collaborator?
> >>> Before to be a collaborator, I prefer to show my contributions.
> >>>
> >>> I hope to integrate Markdown during this week, because I'm very  
> >>> busy with the OpenERP project
> >>> and I don't have the time to make a patch or an extension today.
> >>>
> >>> Regards,
> >>>
> >>> Stéphane
> >>>
> >>
> >
> >

Re: [flask] Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-20 @ 22:16

Written from my iPhone !

Le 20 mai 2010 à 19:48, Dag Odenhall <dag.odenhall@gmail.com> a  
écrit :

> Markup() marks a string as safe without the need to filter it.
>
I agree with you, but you have forgotten the autoescape of jinja2.  
check the code of flask. there is a specific value autoescape=True in  
the code.

regards,

stephane
> tor 2010-05-20 klockan 19:40 +0200 skrev Stephane Wirtel:
>> markup will escape the HTML code with the HTML entities.
>>
>> if the code generated by markdown should be inserted in a html page,
>> the content must be safe with the safe filter.
>>
>> but honnestly, I didn't read the documentation of markup.
>>
>> regards
>>
>> Written from my iPhone !
>>
>> Le 20 mai 2010 à 19:26, Dag Odenhall <dag.odenhall@gmail.com> a
>> écrit :
>>
>>> from flask import Markup
>>>
>>> message = Markup(markdown.markdown(text))
>>>
>>> http://flask.pocoo.org/docs/api/#flask.Markup
>>>
>>> tor 2010-05-20 klockan 19:13 +0200 skrev Stephane Wirtel:
>>>> ok, in the html file, use the safe filter on the output from  
>>>> markdown
>>>>
>>>> in brief:
>>>>
>>>> {{ message|safe }}
>>>>
>>>> I can propose a snippet for markdown
>>>>
>>>> Regards
>>>> On 20 May 2010, at 13:24, Stephane Wirtel wrote:
>>>>
>>>>> On 05/20/2010 01:13 PM, Kenneth Reitz wrote:
>>>>>> Hah! Sorry about that.
>>>>> Don't worry
>>>>>>
>>>>>> I have a repository on GitHub setup. Can I add you as a
>>>>>> collaborator?
>>>>> Before to be a collaborator, I prefer to show my contributions.
>>>>>
>>>>> I hope to integrate Markdown during this week, because I'm very
>>>>> busy with the OpenERP project
>>>>> and I don't have the time to make a patch or an extension today.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Stéphane
>>>>>
>>>>
>>>
>>>
>
>

Re: [flask] Flask and Markdown

From:
Armin Ronacher
Date:
2010-05-21 @ 05:23
Hi,

On 2010-05-21 12:16 AM, Stephane Wirtel wrote:
>> Markup() marks a string as safe without the need to filter it.
>>
> I agree with you, but you have forgotten the autoescape of jinja2.
> check the code of flask. there is a specific value autoescape=True in
> the code.
The point of Markup is to mark a string as "contains HTML" so that 
autoescaping does not escape that value.  In fact, |safe and Markup are 
the very same thing, the only difference is that in the first case, 
Markup is registered as Jinja2 filter.


Regards,
Armin

Re: [flask] Flask and Markdown

From:
Stephane Wirtel
Date:
2010-05-21 @ 08:35
On 05/21/2010 07:23 AM, Armin Ronacher wrote:
> Hi,
> 
> On 2010-05-21 12:16 AM, Stephane Wirtel wrote:
>>> Markup() marks a string as safe without the need to filter it.
>>>
>> I agree with you, but you have forgotten the autoescape of jinja2.
>> check the code of flask. there is a specific value autoescape=True in
>> the code.
> The point of Markup is to mark a string as "contains HTML" so that 
> autoescaping does not escape that value.  In fact, |safe and Markup are 
> the very same thing, the only difference is that in the first case, 
> Markup is registered as Jinja2 filter.
> 
> 
> Regards,
> Armin
Ok, I checked and mea culpa.

Thank you for this information.

How can I propose a snippet for this feature ?

Regards