Ejemplo n.º 1
0
    def devour(self, content, maxwidth=None, maxheight=None):
        pre_consume.send(sender=self)

        # Soupify with less aggressive entity conversion
        soup = BeautifulSoup(content or '', convertEntities=BeautifulSoup.HTML_ENTITIES)

        for element in soup.findAll(text=self.url_regex):
            # Don't handle linked URLs
            if self._is_hyperlinked(element):
                logger.debug('Skipping hyperlinked content: %s' % element)
                continue
            repl = self.enrich(str(element), maxwidth=maxwidth, maxheight=maxheight)
            element.replaceWith(BeautifulSoup(repl, convertEntities=BeautifulSoup.HTML_ENTITIES))

        post_consume.send(sender=self)
        return str(soup)
Ejemplo n.º 2
0
    def devour(self, content, maxwidth=None, maxheight=None):
        """
        Consumes all OEmbed content URLs in the content. Returns a new
        version of the content with URLs replaced with rich content. This
        sends both ``pre_consume`` and ``post_consume`` signals before and
        after enriching the specified content. Any subclasses should take
        note to honor this behavior.

        :param string content: Content to enrich
        :param integer maxwidth: Maximum width of resource
        :param integer maxheight: Maximum height of resource
        :returns: A version of specific content with matched URLs replaced with
                  rendered resources
        """
        pre_consume.send(sender=self)
        content = self.enrich(content or '', maxwidth=maxwidth, maxheight=maxheight)
        post_consume.send(sender=self)
        return content