Пример #1
0
 def __init__(self, link: HtmlElement, bigbook_dir: Path) -> None:
     """
     :param bigbook_dir: the Big Book of Key directory
     :param link: an 'a' element from the table of contents that links
                 to the article's page and contains the article's
                 fully formatted title.
     """
     self.file = bigbook_dir / 'Text' / link.get('href')
     self.id = link.get('href')[:-6]  # remove ".xhtml" suffix
     self.date = datetime.fromisoformat(self.id[:10])
     self.link = html_tostring(link, encoding='unicode').replace('.xhtml', '.html')
     self.title = str(link.text_content())
     self.sorting_key = dictionary_order_sorting_key(self.title)
     self.narrations = []
Пример #2
0
    def render(self):
        """render the webstats snippet adding a div arround it
        """
        ptool = getToolByName(self.context, "portal_properties")
        snippet = safe_unicode(ptool.site_properties.webstats_js)

        # Putting a div arround the snippets
        div = html_builder.DIV({'id': 'plone-analytics'})  # create the div
        tags = html_fromstring(snippet)  # parse the snippets from html to lxml classes
        div.extend(tags)  # insert the tags into the div
        snippet = safe_unicode(html_tostring(div))  # convert back to string the new tag
        # Putting a div arround the snippets

        return snippet
Пример #3
0
    def render(self):
        """render the webstats snippet adding a div arround it
        """
        ptool = getToolByName(self.context, 'portal_properties')
        snippet = safe_unicode(ptool.site_properties.webstats_js)

        # Putting a div arround the snippets
        div = html_builder.DIV({'id': 'plone-analytics'})  # create the div
        tags = html_fromstring(
            snippet)  # parse the snippets from html to lxml classes
        div.extend(tags)  # insert the tags into the div
        snippet = safe_unicode(
            html_tostring(div))  # convert back to string the new tag
        # Putting a div arround the snippets

        return snippet
Пример #4
0
    blog_entry_el      = full_html.find('//div[@class="BlogEntry"]')

    # TODO: Deal with local media files and page links

    blog_entry_el.make_links_absolute(base_url="http://improbable.org/chris/")
    blog_entry_el.rewrite_links(link_launderer)

    for pre in blog_entry_el.cssselect("pre.code"):
        pre.attrib['class'] += " prettyprint"

    if blog_entry_el.text:
        post.body += unicode(blog_entry_el.text)

    for c in blog_entry_el:
        post.body += html_tostring(c, encoding=unicode)

    if DEBUG and (post.body != attrs['Body']):
        print >>sys.stderr, "Mismatch between imported content and web-delivered:"
        print >>sys.stderr, "\n".join(difflib.unified_diff(attrs['Body'].split(), post.body.split(), "Dump", "HTTP", lineterm=""))

    post.owner    = owner

    if attrs['TextID']:
        post.slug = attrs['TextID']
    else:
        post.slug = slugify(post.title.encode("ascii", "replace"))

    if len(post.slug) > 50:
        slug_parts = post.slug.split("-")
        post.slug  = slug_parts.pop(0)