Booktype Library

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

The Binary Chronicles

Python

EPUB engine can recognize source code in text and highlight it.

Example 1

from ebooklib.plugins.base import BasePlugin

class BooktypeLinks(BasePlugin):
    NAME = 'Booktype Links'

    def __init__(self, booktype_book):
        self.booktype_book = booktype_book

    def process_html(self, book, chapter):
        from urlparse import urlparse, urljoin

        from lxml import html, etree

        utf8_parser = html.HTMLParser(encoding='utf-8')
        tree = html.document_fromstring(chapter.content, parser=utf8_parser)
        root = tree.getroottree()

Example 2

def _get_children(elems, n):
    label, content = '', ''
    children = []

    for a in elems.getchildren():
        if a.tag == '{%s}navLabel' %  NAMESPACES['DAISY']:
            label = a.getchildren()[0].text
        if a.tag == '{%s}content' %  NAMESPACES['DAISY']:
            content = a.get('src')
        if a.tag == '{%s}navPoint' %  NAMESPACES['DAISY']:
            children.append(_get_children(a, n+1))

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.