예제 #1
0
 def as_html(self):
     markdowner = markup.get_parser()
     return QUESTION_REVISION_TEMPLATE % {
         "title": self.title,
         "html": sanitize_html(markdowner.convert(self.text)),
         "tags": " ".join(['<a class="post-tag">%s</a>' % tag for tag in self.tagnames.split(" ")]),
     }
예제 #2
0
 def as_html(self):
     markdowner = markup.get_parser()
     return QUESTION_REVISION_TEMPLATE % {
         'title': self.title,
         'html': sanitize_html(markdowner.convert(self.text)),
         'tags': ' '.join(['<a class="post-tag">%s</a>' % tag
                           for tag in self.tagnames.split(' ')]),
     }
예제 #3
0
 def as_html(self):
     markdowner = markup.get_parser()
     return QUESTION_REVISION_TEMPLATE % {
         'title': self.title,
         'html': sanitize_html(markdowner.convert(self.text)),
         'tags': ' '.join(['<a class="post-tag">%s</a>' % tag
                           for tag in self.tagnames.split(' ')]),
     }
예제 #4
0
파일: base.py 프로젝트: melug/askbot-devel
    def as_html(self, **kwargs):
        markdowner = markup.get_parser()
        sanitized_html = sanitize_html(markdowner.convert(self.text))

        if self.is_question_revision():
            return self.QUESTION_REVISION_TEMPLATE_NO_TAGS % {"title": self.title, "html": sanitized_html}
        elif self.is_answer_revision():
            return sanitized_html
예제 #5
0
    def as_html(self, **kwargs):
        markdowner = markup.get_parser()
        sanitized_html = sanitize_html(markdowner.convert(self.text))

        if self.is_question_revision():
            return self.QUESTION_REVISION_TEMPLATE_NO_TAGS % {
                'title': self.title,
                'html': sanitized_html
            }
        elif self.is_answer_revision():
            return sanitized_html
예제 #6
0
파일: base.py 프로젝트: oloed/askbot-devel
def parse_post_text(post):
    """typically post has a field to store raw source text
    in comment it is called .comment, in Question and Answer it is 
    called .text
    also there is another field called .html (consistent across models)
    so the goal of this function is to render raw text into .html
    and extract any metadata given stored in source (currently
    this metadata is limited by twitter style @mentions
    but there may be more in the future

    function returns a dictionary with the following keys
    html
    newly_mentioned_users - list of <User> objects
    removed_mentions - list of mention <Activity> objects - for removed ones
    """

    text = post.get_text()

    if post._escape_html:
        text = cgi.escape(text)

    if post._urlize:
        text = html.urlize(text)

    if post._use_markdown:
        text = sanitize_html(markup.get_parser().convert(text))

    #todo, add markdown parser call conditional on
    #post.use_markdown flag
    post_html = text
    mentioned_authors = list()
    removed_mentions = list()
    if '@' in text:
        op = post.get_origin_post()
        anticipated_authors = op.get_author_list(include_comments=True,
                                                 recursive=True)

        extra_name_seeds = markup.extract_mentioned_name_seeds(text)

        extra_authors = set()
        for name_seed in extra_name_seeds:
            extra_authors.update(
                User.objects.filter(username__istartswith=name_seed))

        #it is important to preserve order here so that authors of post
        #get mentioned first
        anticipated_authors += list(extra_authors)

        mentioned_authors, post_html = markup.mentionize_text(
            text, anticipated_authors)

        #find mentions that were removed and identify any previously
        #entered mentions so that we can send alerts on only new ones
        from askbot.models.user import Activity
        if post.pk is not None:
            #only look for previous mentions if post was already saved before
            prev_mention_qs = Activity.objects.get_mentions(mentioned_in=post)
            new_set = set(mentioned_authors)
            for prev_mention in prev_mention_qs:

                user = prev_mention.get_mentioned_user()
                if user is None:
                    continue
                if user in new_set:
                    #don't report mention twice
                    new_set.remove(user)
                else:
                    removed_mentions.append(prev_mention)
            mentioned_authors = list(new_set)

    data = {
        'html': post_html,
        'newly_mentioned_users': mentioned_authors,
        'removed_mentions': removed_mentions,
    }
    return data
예제 #7
0
 def test_markdown_class_addr(self):
     parser = get_parser('askbot.tests.utils.Markdown')
     self.assertIsInstance(parser, markdown2.Markdown)
예제 #8
0
 def test_func(self):
     parser = get_parser()
     self.assertIsInstance(parser, markdown2.Markdown)
예제 #9
0
 def as_html(self):
     markdowner = markup.get_parser()
     return sanitize_html(markdowner.convert(self.text))
예제 #10
0
파일: base.py 프로젝트: Arpaso/askbot-devel
def parse_post_text(post):
    """typically post has a field to store raw source text
    in comment it is called .comment, in Question and Answer it is 
    called .text
    also there is another field called .html (consistent across models)
    so the goal of this function is to render raw text into .html
    and extract any metadata given stored in source (currently
    this metadata is limited by twitter style @mentions
    but there may be more in the future

    function returns a dictionary with the following keys
    html
    newly_mentioned_users - list of <User> objects
    removed_mentions - list of mention <Activity> objects - for removed ones
    """

    text = post.get_text()

    if post._escape_html:
        text = cgi.escape(text)

    if post._urlize:
        text = html.urlize(text)

    if post._use_markdown:
        text = sanitize_html(markup.get_parser().convert(text))

    #todo, add markdown parser call conditional on
    #post.use_markdown flag
    post_html = text
    mentioned_authors = list()
    removed_mentions = list()
    if '@' in text:
        op = post.get_origin_post()
        anticipated_authors = op.get_author_list(
                                    include_comments = True,
                                    recursive = True 
                                )

        extra_name_seeds = markup.extract_mentioned_name_seeds(text)

        extra_authors = set()
        for name_seed in extra_name_seeds:
            extra_authors.update(User.objects.filter(
                                        username__startswith = name_seed
                                    )
                            )

        #it is important to preserve order here so that authors of post 
        #get mentioned first
        anticipated_authors += list(extra_authors)

        mentioned_authors, post_html = markup.mentionize_text(
                                                text, 
                                                anticipated_authors
                                            )

        #find mentions that were removed and identify any previously
        #entered mentions so that we can send alerts on only new ones
        from askbot.models.user import Activity
        if post.pk is not None:
            #only look for previous mentions if post was already saved before
            prev_mention_qs = Activity.objects.get_mentions(
                                        mentioned_in = post
                                    )
            new_set = set(mentioned_authors)
            for prev_mention in prev_mention_qs:

                user = prev_mention.get_mentioned_user()
                if user is None:
                    continue
                if user in new_set:
                    #don't report mention twice
                    new_set.remove(user)
                else:
                    removed_mentions.append(prev_mention)
            mentioned_authors = list(new_set)

    data = {
        'html': post_html,
        'newly_mentioned_users': mentioned_authors,
        'removed_mentions': removed_mentions,
    }
    return data
예제 #11
0
 def test_markdown_class_addr(self):
     parser = get_parser('askbot.tests.utils.Markdown')
     self.assertIsInstance(parser, markdown2.Markdown)
예제 #12
0
 def test_func(self):
     parser = get_parser()
     self.assertIsInstance(parser, markdown2.Markdown)
예제 #13
0
 def as_html(self):
     markdowner = markup.get_parser()
     return sanitize_html(markdowner.convert(self.text))