<s> from django import template <EOL> from django . utils . safestring import mark_safe <EOL> try : <EOL> from django . utils . encoding import force_text <EOL> except ImportError : <EOL> from django . utils . encoding import force_unicode as force_text <EOL> import markdown_deux <EOL> from markdown_deux . conf import settings <EOL> register = template . Library ( ) <EOL> @ register . filter ( name = "<STR_LIT>" ) <EOL> def markdown_filter ( value , style = "<STR_LIT:default>" ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return mark_safe ( markdown_deux . markdown ( value , style ) ) <EOL> except ImportError : <EOL> if settings . DEBUG : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return force_text ( value ) <EOL> markdown_filter . is_safe = True <EOL> @ register . tag ( name = "<STR_LIT>" ) <EOL> def markdown_tag ( parser , token ) : <EOL> nodelist = parser . parse ( ( '<STR_LIT>' , ) ) <EOL> bits = token . split_contents ( ) <EOL> if len ( bits ) == <NUM_LIT:1> : <EOL> style = "<STR_LIT:default>" <EOL> elif len ( bits ) == <NUM_LIT:2> : <EOL> style = bits [ <NUM_LIT:1> ] <EOL> else : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . delete_first_token ( ) <EOL> return MarkdownNode ( style , nodelist ) <EOL> class MarkdownNode ( template . Node ) : <EOL> def __init__ ( self , style , nodelist ) : <EOL> self . style = style <EOL> self . nodelist = nodelist <EOL> def render ( self , context ) : <EOL> value = self . nodelist . render ( context ) <EOL> try : <EOL> return mark_safe ( markdown_deux . markdown ( value , self . style ) ) <EOL> except ImportError : <EOL> if settings . DEBUG : <EOL> raise template . TemplateSyntaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return force_text ( value ) <EOL> @ register . inclusion_tag ( "<STR_LIT>" ) <EOL> def markdown_cheatsheet ( ) : <EOL> return { "<STR_LIT>" : settings . MARKDOWN_DEUX_HELP_URL } <EOL> @ register . simple_tag <EOL> def markdown_allowed ( ) : <EOL> return ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % settings . MARKDOWN_DEUX_HELP_URL ) </s>
