Example #1
0
    def _output(self):
        """It is this method that is responsible for rendering the 
        object in HTML.
        """
        if self.text is None or self.text == "":
            return u""

        if self.text_format == '\E':
            return linebreaks(urlize(escape(self.text)))
        elif self.text_format == '\T':
            try:
                return textile(self.text)
            except:
                return mark_safe(_('There is an error in the Textile.'))
        elif self.text_format == '\M':
            try:
                return markdown(self.text, MARKDOWN_EXTENSIONS)
            except:
                return mark_safe(_('There is an error in the Markdown.'))
        elif self.text_format == '\R':
            try:
                return restructuredtext(self.text)
            except:
                return mark_safe(
                    _('There is an error in the reStructuredText.'))
        elif self.text_format == '\H' or self.text_format == '\W':
            return mark_safe(self.text)
        else:
            return mark_safe(escape(self.text))
Example #2
0
def rst_preview(request):
    """
    Returns rendered restructured text.
    """
    def get_rst_error_as_html(message, title='Parser error occured'):
        """
        Returns restructured text error message as html. Manual marking as safe
        is required for rendering.
        """
        html = '\n'.join((
            '<div class="system-message">',
            '<p class="system-message-title">%s</p>' % title,
            message,
            '</div>',
        ))
        return html

    if not request.is_ajax() or not request.method == 'POST':
        raise Http404()
    data = request.POST.get('data', '')
    if len(data) > RESTRUCTUREDTEXT_PARSER_MAX_CHARS:
        html = get_rst_error_as_html(
            'Text is too long (%s). Maximum is %s.' %
            (len(data), RESTRUCTUREDTEXT_PARSER_MAX_CHARS))
    else:
        try:
            html = restructuredtext(data)
        except SystemMessage:
            html = get_rst_error_as_html(
                'Sorry but there are at severe errors in your text '
                'and we cannot show it\'s preview.')
    rendered = mark_safe(html)
    return HttpResponse(dumps(rendered), mimetype='application/json')
Example #3
0
def rst_preview(request):
    """
    Returns rendered restructured text.
    """
    def get_rst_error_as_html(message, title='Parser error occured'):
        """
        Returns restructured text error message as html. Manual marking as safe
        is required for rendering.
        """
        html = '\n'.join((
            '<div class="system-message">',
            '<p class="system-message-title">%s</p>' % title,
            message,
            '</div>',
        ))
        return html

    if not request.is_ajax() or not request.method == 'POST':
        raise Http404()
    data = request.POST.get('data', '')
    if len(data) > RESTRUCTUREDTEXT_PARSER_MAX_CHARS:
        html = get_rst_error_as_html('Text is too long (%s). Maximum is %s.' %
            (len(data), RESTRUCTUREDTEXT_PARSER_MAX_CHARS))
    else:
        try:
            html = restructuredtext(data)
        except SystemMessage:
            html = get_rst_error_as_html(
                'Sorry but there are at severe errors in your text '
                'and we cannot show it\'s preview.')
    rendered = mark_safe(html)
    return HttpResponse(dumps(rendered), mimetype='application/json')
Example #4
0
 def _output(self):   
     """It is this method that is responsible for rendering the 
     object in HTML.
     """ 
     if self.text is None or self.text == "":
         return u""
     
     if self.text_format == '\E':
         return linebreaks(urlize(escape(self.text)))
     elif self.text_format == '\T':
         try:
             return textile(self.text)
         except:
             return mark_safe(_('There is an error in the Textile.'))
     elif self.text_format == '\M':
         try:
             return markdown(self.text, MARKDOWN_EXTENSIONS)
         except:
             return mark_safe(_('There is an error in the Markdown.')) 
     elif self.text_format == '\R':
         try:
             return restructuredtext(self.text)
         except:
             return mark_safe(_('There is an error in the reStructuredText.'))
     elif self.text_format == '\H' or self.text_format == '\W':
         return mark_safe(self.text)
     else:
         return mark_safe(escape(self.text))
Example #5
0
def readme(repository):
    """
    Return a rendered version of the readme for the given repository
    """
    if not repository.readme or not repository.readme.strip():
        return 'No readme :('

    readme = None

    try:
        if repository.readme_type == 'markdown':
            readme = markup.markdown(repository.readme)
        elif repository.readme_type == 'textile':
            readme = markup.textile(repository.readme)
        elif repository.readme_type == 'rest':
            readme = markup.restructuredtext(repository.readme)
    except:
        pass

    if not readme:
        readme = '<pre>%s</pre>' % urlize(repository.readme)

    try:
        result = mark_safe(clean_html(readme))
    except:
        result = 'Unreadble readme :('

    return result
Example #6
0
def format_content(format, content):
    depend = {
        'markdown': 'markdown',
    }
    try:
        if format == 'markdown':
            import markdown
            return markdown.markdown(content)
        elif format == 'txt':
            return linebreaksbr(content)
        elif format == 'html':
            return content
        elif format == 'textile':
            try:
                import textile
                return textile.textile(content)
            except ImportError:
                raise Exception(u"You must install PyTextile to use textile format.")
        elif format == 'restructuredtext':
            try:
                import docutils
                return restructuredtext(content)
            except ImportError:
                raise Exception(u"You must install docutils to use reST format.")

    except ImportError:
        raise Exception('You should install "%s" to use %s format.' % (depend.get(format),  format))
Example #7
0
def auto_transform_markup(comment):
    """
    Given a comment (``ThreadedComment`` or ``FreeThreadedComment``), this tag
    looks up the markup type of the comment and formats the output accordingly.
    
    It can also output the formatted content to a context variable, if a context name is
    specified.
    """
    try:
        from django.utils.html import escape
        from threadedcomments.models import MARKDOWN, TEXTILE, REST, PLAINTEXT
        if comment.markup == MARKDOWN:
            from django.contrib.markup.templatetags.markup import markdown
            return markdown(comment.comment)
        elif comment.markup == TEXTILE:
            from django.contrib.markup.templatetags.markup import textile
            return textile(comment.comment)
        elif comment.markup == REST:
            from django.contrib.markup.templatetags.markup import restructuredtext
            return restructuredtext(comment.comment)


#        elif comment.markup == HTML:
#            return mark_safe(force_unicode(comment.comment))
        elif comment.markup == PLAINTEXT:
            return escape(comment.comment)
    except ImportError:
        # Not marking safe, in case tag fails and users input malicious code.
        return force_unicode(comment.comment)
def auto_transform_markup(comment):
    """
    Given a comment (``ThreadedComment`` or ``FreeThreadedComment``), this tag
    looks up the markup type of the comment and formats the output accordingly.
    
    It can also output the formatted content to a context variable, if a context name is
    specified.
    """
    try:
        from django.utils.html import escape
        from threadedcomments.models import MARKDOWN, TEXTILE, REST, PLAINTEXT
        if comment.markup == MARKDOWN:
            from django.contrib.markup.templatetags.markup import markdown
            return markdown(comment.comment)
        elif comment.markup == TEXTILE:
            from django.contrib.markup.templatetags.markup import textile
            return textile(comment.comment)
        elif comment.markup == REST:
            from django.contrib.markup.templatetags.markup import restructuredtext
            return restructuredtext(comment.comment)
#        elif comment.markup == HTML:
#            return mark_safe(force_unicode(comment.comment))
        elif comment.markup == PLAINTEXT:
            return escape(comment.comment)
    except ImportError:
        # Not marking safe, in case tag fails and users input malicious code.
        return force_unicode(comment.comment)
Example #9
0
 def save_model(self, request, obj, form, change):
     obj.author = request.user
     if obj.is_html:
         obj.content_html = obj.content
     else:
         obj.content_html = restructuredtext(obj.content)
     obj.save()
Example #10
0
def render(content, markup):        
    if markup == MARKUP_RESTRUCTUREDTEXT:
        return restructuredtext(content)
    elif markup == MARKUP_CREOLE:
        return creole_parser(content)
    
    raise NotImplementedError
Example #11
0
 def html_content(self):
     """Return the content correctly formatted"""
     if MARKUP_LANGUAGE == 'markdown':
         return markdown(self.content, MARKDOWN_EXTENSIONS)
     elif MARKUP_LANGUAGE == 'textile':
         return textile(self.content)
     elif MARKUP_LANGUAGE == 'restructuredtext':
         return restructuredtext(self.content)
     return self.content
Example #12
0
def file_preview(request):
    """
    Live preview of restructuredtext payload - currently not wired up
    """
    f = File(heading=request.POST["heading"], content=request.POST["content"])
    rendered_base = render_to_string("projects/doc_file.rst.html", {"file": f})
    rendered = restructuredtext(rendered_base)

    json_response = simplejson.dumps({"payload": rendered})
    return HttpResponse(json_response, mimetype="text/javascript")
Example #13
0
def index(request):
    readme_file = join(dirname(dirname(abspath(__file__))), 'README.txt')
    raw_content = open(readme_file).read()
    try:
        content = restructuredtext(raw_content)
    except template.TemplateSyntaxError:
        content = u'<pre>' + raw_content + u'</pre>'
        
    return render_to_response('index.html', {'content': content},
        context_instance=RequestContext(request))
Example #14
0
def index(request):
    readme_file = join(dirname(dirname(abspath(__file__))), 'README.rst')
    raw_content = open(readme_file).read()
    try:
        content = restructuredtext(raw_content)
    except template.TemplateSyntaxError:
        content = u'<pre>' + raw_content + u'</pre>'
        
    return render_to_response('index.html', {'content': content},
        context_instance=RequestContext(request))
def process_markup(text, markup):
    if markup == 'textile':
        return textile(text)
    elif markup == 'html':
        return mark_safe(text)
    elif markup == 'markdown':
        return markdown(text)
    elif markup == 'rst':
        return restructuredtext(text)
    else:
        return mark_safe('<pre>' + text + '</pre>')
Example #16
0
    def rendered_content(self):
        if self.content_type == 'restructuredtext':
            '''暂时取消restructuredtext的处理'''
            #return restructuredtext(self.content)

            #创建lxml的html过滤器,保留object,embed,去除js,iframe
            return self.html_cleaner.clean_html(self.content)  #使用过滤器,返回安全的html
        elif self.content_type == 'html':
            return self.html
        else:
            return restructuredtext(self.content)
Example #17
0
    def rendered_content(self):
        if self.content_type == 'restructuredtext':
            '''暂时取消restructuredtext的处理'''
            #return restructuredtext(self.content)

            #创建lxml的html过滤器,保留object,embed,去除js,iframe
            return self.html_cleaner.clean_html(self.content) #使用过滤器,返回安全的html
        elif self.content_type == 'html':
            return self.html
        else:
            return restructuredtext(self.content)
Example #18
0
 def html_content(self):
     """Return the Entry.content attribute formatted in HTML"""
     if MARKUP_LANGUAGE == 'markdown':
         return markdown(self.content, MARKDOWN_EXTENSIONS)
     elif MARKUP_LANGUAGE == 'textile':
         return textile(self.content)
     elif MARKUP_LANGUAGE == 'restructuredtext':
         return restructuredtext(self.content)
     elif not '</p>' in self.content:
         return linebreaks(self.content)
     return self.content
Example #19
0
 def html_content(self):
     """Return the content correctly formatted"""
     if MARKUP_LANGUAGE == 'markdown':
         return markdown(self.content, MARKDOWN_EXTENSIONS)
     elif MARKUP_LANGUAGE == 'textile':
         return textile(self.content)
     elif MARKUP_LANGUAGE == 'restructuredtext':
         return restructuredtext(self.content)
     # elif not '</p>' in self.content:
     #     return linebreaks(self.content)
     return self.content
Example #20
0
 def html_content(self):
     """Return the Entry.content attribute formatted in HTML"""
     if MARKUP_LANGUAGE == 'markdown':
         return markdown(self.content, MARKDOWN_EXTENSIONS)
     elif MARKUP_LANGUAGE == 'textile':
         return textile(self.content)
     elif MARKUP_LANGUAGE == 'restructuredtext':
         return restructuredtext(self.content)
     elif not '</p>' in self.content:
         return linebreaks(self.content)
     return self.content
Example #21
0
def get_inline_description(inline):
    """
    Returns a string that has been converted from
    ``restructuredtext`` into HTML.
    
    TODO: The output is kinda wonky (needs html to be reformatted)
    """
    text = getattr(inline, "__doc__", "")
    if text is None:
        return ""
    return restructuredtext(text.strip())
Example #22
0
 def html_content(self):
     """Return the content correctly formatted"""
     if MARKUP_LANGUAGE == "markdown":
         return markdown(self.content, MARKDOWN_EXTENSIONS)
     elif MARKUP_LANGUAGE == "textile":
         return textile(self.content)
     elif MARKUP_LANGUAGE == "restructuredtext":
         return restructuredtext(self.content)
     elif not "</p>" in self.content:
         return linebreaks(self.content)
     return self.content
Example #23
0
def format_flatpage(flatpage):
    value = flatpage.content

    format = flatpage.format
    if format == 'application/xhtml+xml':
        return value
    elif format == 'text/x-livejournal':
        return linebreaks(value)
    elif format == 'text/x-rst':
        return restructuredtext(value)
    else: # format == 'text/plain':
        return linebreaks(escape(value))
Example #24
0
 def get_markuped_body(self):
     if not self.syntax:
         return self.body
     syntax_name = self.syntax.name
     if syntax_name == "textile":
         return textile(self.body)
     elif syntax_name == "markdown":
         return markdown(self.body)
     elif syntax_name == "restructuredtext":
         return restructuredtext(self.body)
     else:
         return self.body
Example #25
0
def markup(txt, markupname=0):
    if markupname is Page.TEXTILE:
        from django.contrib.markup.templatetags.markup import textile
        return textile(txt)
    elif markupname is Page.MARKDOWN:
        from django.contrib.markup.templatetags.markup import markdown
        return markdown(txt)
    elif markupname is Page.RESTRUCTUREDTEXT:
        from django.contrib.markup.templatetags.markup import restructuredtext
        return restructuredtext(txt)
    else:
        return txt
Example #26
0
def markup(text, format):
    if format == 'html':
        return mark_safe(text)
    elif format == 'rest':
        return markup_filters.restructuredtext(text)
    elif format == 'mdown':
        return markup_filters.markdown(text)
    elif format == 'txtile':
        return markup_filters.textile(text)
    elif settings.DEBUG:
        raise Exception, "Invalid 'markup' format: %s" % format
    return ''
Example #27
0
def format_content(value, format):

    if format == 'M':  # markdown
        value = markdown(value, settings.MARKDOWN_EXTENSIONS)
    elif format == 'R':
        value = restructuredtext(value)
    elif format == 'H':
        value = mark_safe(value)
    else:
        value = linebreaks(urlize(escape(value)))

    return value
Example #28
0
 def save_model(self, request, obj, form, change):
     obj.author = request.user
     if not obj.summary:
         obj.summary = obj.content
     if not obj.is_old:
         obj.content_html = restructuredtext(obj.content)
     else:
         obj.content_html = obj.content.replace('\r\n', '<br/>')
         import re
         obj.content_html = re.sub(r"\[cc lang='\w+?'\]", '<pre>', obj.content_html)
         obj.content_html = obj.content_html.replace('[/cc]', '</pre>')
     obj.save()
Example #29
0
def format_content(value, format):

    
    if format=='M': # markdown
        value = markdown(value, settings.MARKDOWN_EXTENSIONS)
    elif format == 'R':
        value = restructuredtext(value) 
    elif format=='H':
        value = mark_safe(value)
    else:
        value = linebreaks(urlize(escape(value)))
            
    return value
Example #30
0
def file_preview(request):
    """
    Live preview of restructuredtext payload - currently not wired up
    """
    f = File(
        heading=request.POST['heading'],
        content=request.POST['content'],
    )
    rendered_base = render_to_string('projects/doc_file.rst.html', {'file': f})
    rendered = restructuredtext(rendered_base)

    json_response = simplejson.dumps({'payload': rendered})
    return HttpResponse(json_response, mimetype='text/javascript')
Example #31
0
def file_preview(request):
    """
    Live preview of restructuredtext payload - currently not wired up
    """
    f = File(
        heading=request.POST['heading'],
        content=request.POST['content'],
    )
    rendered_base = render_to_string('projects/doc_file.rst.html', {'file': f})
    rendered = restructuredtext(rendered_base)

    json_response = simplejson.dumps({'payload': rendered})
    return HttpResponse(json_response, mimetype='text/javascript')
Example #32
0
 def html_content(self):
     """
     Returns the "content" field formatted in HTML.
     """
     MARKUP_LANGUAGE = self.get_content_markup_display()
     if MARKUP_LANGUAGE == 'markdown':
         return markdown(self.content, MARKDOWN_EXTENSIONS)
     elif MARKUP_LANGUAGE == 'textile':
         return textile(self.content)
     elif MARKUP_LANGUAGE == 'restructuredtext':
         return restructuredtext(self.content)
     elif not '</p>' in self.content:
         return linebreaks(self.content)
     return self.content
Example #33
0
    def do_render_markup(self):
        """Turns any markup into HTML"""

        original = self.rendered_content
        if self.markup == MARKUP_MARKDOWN:
            self.rendered_content = markup.markdown(self.content)
        elif self.markup == MARKUP_REST:
            self.rendered_content = markup.restructuredtext(self.content)
        elif self.markup == MARKUP_TEXTILE:
            self.rendered_content = markup.textile(self.content)
        else:
            self.rendered_content = self.content

        return (self.rendered_content != original)
Example #34
0
  def save(self, *args, **kwargs):
    """
    Renders the article using the appropriate markup language.
    """
    if self.markup == MARKUP_REST:
      self.rendered_body = markup.restructuredtext(self.body)
    elif self.markup == MARKUP_MARKDOWN:
      self.rendered_body = markup.markdown(self.body, "codehilite")
#    elif self.markup == MARKUP_TEXTILE:
#      self.rendered_body = markup.textile(self.body)
    else:
      self.rendered_body = self.body

    super(Article, self).save(*args, **kwargs)
Example #35
0
    def do_render_markup(self):
        """Turns any markup into HTML"""

        original = self.rendered_content
        if self.markup == MARKUP_MARKDOWN:
            self.rendered_content = markup.markdown(self.content)
        elif self.markup == MARKUP_REST:
            self.rendered_content = markup.restructuredtext(self.content)
        elif self.markup == MARKUP_TEXTILE:
            self.rendered_content = markup.textile(self.content)
        else:
            self.rendered_content = self.content

        return (self.rendered_content != original)
Example #36
0
 def html_content(self):
     """
     Returns the "content" field formatted in HTML.
     """
     MARKUP_LANGUAGE = self.get_content_markup_display()
     if MARKUP_LANGUAGE == 'markdown':
         return markdown(self.content, MARKDOWN_EXTENSIONS)
     elif MARKUP_LANGUAGE == 'textile':
         return textile(self.content)
     elif MARKUP_LANGUAGE == 'restructuredtext':
         return restructuredtext(self.content)
     elif not '</p>' in self.content:
         return linebreaks(self.content)
     return self.content
Example #37
0
    def do_render_markup(self):
        """Turns any markup into HTML"""

        original = self._rendered
        if self.markup == MARKUP_MARKDOWN:
            rendered = markup.markdown(self._source)
        elif self.markup == MARKUP_REST:
            rendered = markup.restructuredtext(self._source)
        elif self.markup == MARKUP_TEXTILE:
            rendered = markup.textile(self._source)
        else:
            rendered = self._source

        setattr(self, self._markup.rendered_field, rendered)
        return (rendered != original)
Example #38
0
    def do_render_markup(self):
        """Turns any markup into HTML"""

        original = self._rendered
        if self.markup == MARKUP_MARKDOWN:
            rendered = markup.markdown(self._source)
        elif self.markup == MARKUP_REST:
            rendered = markup.restructuredtext(self._source)
        elif self.markup == MARKUP_TEXTILE:
            rendered = markup.textile(self._source)
        else:
            rendered = self._source

        setattr(self, self._markup.rendered_field, rendered)
        return (rendered != original)
Example #39
0
def markuping(markup, value):
    """
    Transform plain text markup syntaxes to HTML with filters in 
    django.contrib.markup.templatetags.
    """
    from django.contrib.markup.templatetags.markup \
        import textile, markdown, restructuredtext
    if markup == 'markdown':
        return markdown(value)
    elif markup == 'rest':
        return restructuredtext(value)
    elif markup == 'textile':
        return textile(value)
    else:
        return value            # raw
Example #40
0
def markuping(markup, value):
    """
    Transform plain text markup syntaxes to HTML with filters in 
    django.contrib.markup.templatetags.
    """
    from django.contrib.markup.templatetags.markup \
        import textile, markdown, restructuredtext
    if markup == 'markdown':
        return markdown(value)
    elif markup == 'rest':
        return restructuredtext(value)
    elif markup == 'textile':
        return textile(value)
    else:
        return value  # raw
Example #41
0
    def save(self, *args, **kwargs):
        """
        Renders the article using the appropriate markup language.
        """

        if self.markup == MARKUP_MARKDOWN:
            self.rendered_content = markup.markdown(self.content)
        elif self.markup == MARKUP_REST:
            self.rendered_content = markup.restructuredtext(self.content)
        elif self.markup == MARKUP_TEXTILE:
            self.rendered_content = markup.textile(self.content)
        else:
            self.rendered_content = self.content

        # if the author wishes to have an "AddThis" button on this article,
        # make sure we have a username to go along with it.
        if self.use_addthis_button and self.addthis_use_author and not self.addthis_username:
            self.addthis_username = self.author.username

        # make sure the slug is always unique for the year this article was posted
        if not self.id:
            # make sure we have a slug first
            if not len(self.slug.strip()):
                self.slug = slugify(self.title)

            self.slug = self.get_unique_slug(self.slug)

        super(Article, self).save(*args, **kwargs)
        requires_save = False

        # if we don't have keywords, use the tags
        if len(self.keywords.strip()) == 0:
            self.keywords = ', '.join([t.name for t in self.tags.all()])
            requires_save = True

        # if we don't have a description, use the teaser
        if len(self.description.strip()) == 0:
            self.description = self.teaser
            requires_save = True

        # we have to have an object before we can create relationships like this
        if not len(self.sites.all()):
            self.sites = [Site.objects.get_current()]
            requires_save = True

        if requires_save:
            super(Article, self).save(*args, **kwargs)
Example #42
0
    def save(self, *args, **kwargs):
        """
        Renders the article using the appropriate markup language.
        """

        if self.markup == MARKUP_MARKDOWN:
            self.rendered_content = markup.markdown(self.content)
        elif self.markup == MARKUP_REST:
            self.rendered_content = markup.restructuredtext(self.content)
        elif self.markup == MARKUP_TEXTILE:
            self.rendered_content = markup.textile(self.content)
        else:
            self.rendered_content = self.content

        # if the author wishes to have an "AddThis" button on this article,
        # make sure we have a username to go along with it.
        if self.use_addthis_button and self.addthis_use_author and not self.addthis_username:
            self.addthis_username = self.author.username

        # make sure the slug is always unique for the year this article was posted
        if not self.id:
            # make sure we have a slug first
            if not len(self.slug.strip()):
                self.slug = slugify(self.title)

            self.slug = self.get_unique_slug(self.slug)

        super(Article, self).save(*args, **kwargs)
        requires_save = False

        # if we don't have keywords, use the tags
        if len(self.keywords.strip()) == 0:
            self.keywords = ', '.join([t.name for t in self.tags.all()])
            requires_save = True

        # if we don't have a description, use the teaser
        if len(self.description.strip()) == 0:
            self.description = self.teaser
            requires_save = True

        # we have to have an object before we can create relationships like this
        if not len(self.sites.all()):
            self.sites = [Site.objects.get_current()]
            requires_save = True

        if requires_save:
            super(Article, self).save(*args, **kwargs)
Example #43
0
def readme(repository):
    """
    Return a rendered version of the readme for the given repository
    """
    if not repository.readme or not repository.readme.strip():
        return 'No readme :('

    if repository.readme_type == 'markdown':
        readme = markup.markdown(repository.readme)
    elif repository.readme_type == 'textile':
        readme = markup.textile(repository.readme)
    elif repository.readme_type == 'rest':
        readme = markup.restructuredtext(repository.readme)
    else:
        readme = '<pre>%s</pre>' % urlize(repository.readme)

    return mark_safe(clean_html(readme))
Example #44
0
    def html_content(self):
        """Return the entry's content formatted in HTML"""
        def asserted_html(s):
            return ( re.match(r'^\s*<\w+>', s) or
                     re.match(r'^\s*<\w+\s+.*>', s)
                   ) and re.search(r'</\w+>\s*$', s)

        if asserted_html(self.content):
            print "ASSERT HTML"
            return self.content
        elif settings.MARKUP_LANGUAGE == 'markdown':
            return markdown(self.content, 'abbr,tables,smart_strong')
        elif settings.MARKUP_LANGUAGE == 'restructuredtext':
            return restructuredtext(self.content)
        elif '</p>' not in self.content:
            return linebreaks(self.content)
        else:
            return self.content
Example #45
0
def markuping(markup, value):
    """
    Transform plain text markup syntaxes to HTML with filters in
    django.contrib.markup.templatetags.

    *Required arguments:*

        * ``markup``: 'markdown', 'rest' or 'texttile'. For any other string
                    value is returned without modifications.
        * ``value``: plain text input

    """
    if markup == 'markdown':
        from markdown import markdown
        return markdown(value)
    elif markup == 'rest':
        from django.contrib.markup.templatetags.markup import restructuredtext
        return restructuredtext(value)
    elif markup == 'textile':
        from django.contrib.markup.templatetags.markup import textile
        return textile(value)
    else:
        return value  # raw
Example #46
0
def saferest(content):
    try:
        return restructuredtext(content)
    except:
        return linebreaks(content)
Example #47
0
def render_rest(text):
    if text is None:
        text = ''
    return markup.restructuredtext(force_text(text))