Example #1
0
    def test_textilize(self):
        """Test textilize function"""
        tests = [(u"<b>No bold</b>", u"No bold"),
                 (u'<span class="blah">A span</span>', u"A span"),
                 (u"Just text", u"Just text"),
                 (u"<p>paragraph</p>", u" paragraph")]

        for test, result in tests:
            self.assertEqual(postmarkup.textilize(test), result)
Example #2
0
 def test_textilize(self):
     """Test textilize function"""
     tests = [(u"<b>No bold</b>", u"No bold"),
              (u'<span class="blah">A span</span>', u"A span"),
              (u"Just text", u"Just text"),
              (u"<p>paragraph</p>", u" paragraph")]
     
     for test, result in tests:
         self.assertEqual(postmarkup.textilize(test), result)
def update_microblogs():


    def char_break(text, num_chars):
        if len(text) < num_chars:
            return text
        return text[:num_chars-3].rsplit(' ', 1)[0] + '...'

    twitter_api = twitter.Api();
    for microblog in Microblog.objects.all():
        if not microblog.enabled:
            continue
        for tweet in twitter_api.GetUserTimeline(microblog.username):

            if re_microblog_reply.match(tweet.text):
                continue

            tweet_guid = u"TWITTER:%s" % str(tweet.id)
            try:
                post = Post.objects.get(blog=microblog.blog, guid=tweet_guid)
            except Post.DoesNotExist:
                tweet_time = datetime.fromtimestamp(tweet.created_at_in_seconds)
                title = char_break(tweet.text, 50)

                tweet_text = tweet.text
                tweet_text = postmarkup.textilize(tweet_text)
                tweet_text = microblog_microformat(tweet_text, microblog.url)


                tags = [t.strip() for t in microblog.tags.split(',')]
                tags += list(parse_hashtags(tweet.text))
                if 'http' in tweet.text:
                    tags.append('link')
                tags = list(set(tags))

                post = Post(blog = microblog.blog,
                            title = "Microblog: " + title,
                            source = "microblog:" + microblog.service,
                            tags_text = ",".join(tags),
                            slug = slugify(title),
                            published = True,
                            guid = tweet_guid,
                            allow_comments=True,
                            created_time=datetime.now(),
                            edit_time=datetime.now(),
                            display_time=tweet_time,
                            content = tweet_text,
                            content_markup_type = "html",
                            version = 'live',
                            template_path = microblog.template_path,
                            )
                post.save()
                post.display_time = tweet_time
                post.save()
def update_microblogs():
    def char_break(text, num_chars):
        if len(text) < num_chars:
            return text
        return text[:num_chars - 3].rsplit(' ', 1)[0] + '...'

    twitter_api = twitter.Api()
    for microblog in Microblog.objects.all():
        if not microblog.enabled:
            continue
        for tweet in twitter_api.GetUserTimeline(microblog.username):

            if re_microblog_reply.match(tweet.text):
                continue

            tweet_guid = u"TWITTER:%s" % str(tweet.id)
            try:
                post = Post.objects.get(blog=microblog.blog, guid=tweet_guid)
            except Post.DoesNotExist:
                tweet_time = datetime.fromtimestamp(
                    tweet.created_at_in_seconds)
                title = char_break(tweet.text, 50)

                tweet_text = tweet.text
                tweet_text = postmarkup.textilize(tweet_text)
                tweet_text = microblog_microformat(tweet_text, microblog.url)

                tags = [t.strip() for t in microblog.tags.split(',')]
                tags += list(parse_hashtags(tweet.text))
                if 'http' in tweet.text:
                    tags.append('link')
                tags = list(set(tags))

                post = Post(
                    blog=microblog.blog,
                    title="Microblog: " + title,
                    source="microblog:" + microblog.service,
                    tags_text=",".join(tags),
                    slug=slugify(title),
                    published=True,
                    guid=tweet_guid,
                    allow_comments=True,
                    created_time=datetime.now(),
                    edit_time=datetime.now(),
                    display_time=tweet_time,
                    content=tweet_text,
                    content_markup_type="html",
                    version='live',
                    template_path=microblog.template_path,
                )
                post.save()
                post.display_time = tweet_time
                post.save()
Example #5
0
def textilize(value):
    return postmarkup.textilize(value)
Example #6
0
def render(markup, markup_type):

    markup = markup or ""

    if markup_type == "postmarkup":

        tag_data = {}
        html = post_render(markup, paragraphs=True, clean=True, tag_data=tag_data)

        text = postmarkup.textilize(html)
        output = tag_data.get("output", {})
        sections = output.get("sections", {})
        for key, value in sections.items():
            sections[key] = [post_markup(s, paragraphs=True, clean=True) for s in value]
        data = output

        summary_markup = output.get("summary", "")
        summary_html = ""
        if summary_markup.strip():
            summary = post_markup(output.get("summary", ""), paragraphs=True, clean=True)
            summary_html = summary

    elif markup_type == "emarkup":

        sections = extendedmarkup.parse(markup)

        html = extendedmarkup.chunks_to_html(sections["main"])
        summary_html = html
        text = postmarkup.textilize(html)
        data = dict(sections=sections)

    elif markup_type == "comment_bbcode":

        html = postmarkup.render_bbcode(markup, paragraphs=True, clean=True)
        text = postmarkup.textilize(html)
        return html, html, text, {}

    elif markup_type == "comment_wordpress":

        html = markup
        summary_html = html
        text = postmarkup.textilize(html)
        data = {}

    elif markup_type == "text":

        html = "<p>%s</p>" % postmarkup._escape(markup)
        summary_html = html
        text = postmarkup.textilize(markup)
        data = {}

    else:

        html = markup
        summary_html = html
        text = postmarkup.textilize(html)
        data = {}

    more_i = html.find("<!--more-->")
    if more_i == -1:
        more_i = html.find("<!-- more -->")

    if more_i != -1:
        summary_html = html[:more_i]
        summary_html = unicode(BeautifulSoup(summary_html))

    return html, summary_html, text, data
Example #7
0
def render(markup, markup_type):

    markup = markup or ""

    if markup_type == "postmarkup":

        tag_data = {}
        html = post_render(markup,
                           paragraphs=True,
                           clean=True,
                           tag_data=tag_data)

        text = postmarkup.textilize(html)
        output = tag_data.get('output', {})
        sections = output.get("sections", {})
        for key, value in sections.items():
            sections[key] = [
                post_markup(s, paragraphs=True, clean=True) for s in value
            ]
        data = output

        summary_markup = output.get("summary", "")
        summary_html = ""
        if summary_markup.strip():
            summary = post_markup(output.get("summary", ""),
                                  paragraphs=True,
                                  clean=True)
            summary_html = summary

    elif markup_type == "emarkup":

        sections = extendedmarkup.parse(markup)

        html = extendedmarkup.chunks_to_html(sections['main'])
        summary_html = html
        text = postmarkup.textilize(html)
        data = dict(sections=sections)

    elif markup_type == "comment_bbcode":

        html = postmarkup.render_bbcode(markup, paragraphs=True, clean=True)
        text = postmarkup.textilize(html)
        return html, html, text, {}

    elif markup_type == "comment_wordpress":

        html = markup
        summary_html = html
        text = postmarkup.textilize(html)
        data = {}

    elif markup_type == "text":

        html = "<p>%s</p>" % postmarkup._escape(markup)
        summary_html = html
        text = postmarkup.textilize(markup)
        data = {}

    else:

        html = markup
        summary_html = html
        text = postmarkup.textilize(html)
        data = {}

    more_i = html.find('<!--more-->')
    if more_i == -1:
        more_i = html.find('<!-- more -->')

    if more_i != -1:
        summary_html = html[:more_i]
        summary_html = unicode(BeautifulSoup(summary_html))

    return html, summary_html, text, data
Example #8
0
def textilize(value):
    return postmarkup.textilize(value)
Example #9
0
    def _defaultrenderer(cls, markup, markup_type):

        return markup, '', textilize(markup), {}
Example #10
0
    def _defaultrenderer(cls, markup, markup_type):

        return markup, '', textilize(markup), {}