当前位置: 首页>>代码示例>>Python>>正文


Python builder.HTML类代码示例

本文整理汇总了Python中lxml.html.builder.HTML的典型用法代码示例。如果您正苦于以下问题:Python HTML类的具体用法?Python HTML怎么用?Python HTML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TouchscreenIndexTemplate

class TouchscreenIndexTemplate(Template):
    def _generate(self, title, masthead, datefmt, feeds, extra_css=None, style=None):

        self.IS_HTML = False

        if isinstance(datefmt, unicode):
            datefmt = datefmt.encode(preferred_encoding)
        date = "%s, %s %s, %s" % (strftime("%A"), strftime("%B"), strftime("%d").lstrip("0"), strftime("%Y"))
        masthead_p = etree.Element("p")
        masthead_p.set("style", "text-align:center")
        masthead_img = etree.Element("img")
        masthead_img.set("src", masthead)
        masthead_img.set("alt", "masthead")
        masthead_p.append(masthead_img)

        head = HEAD(TITLE(title))
        if style:
            head.append(STYLE(style, type="text/css"))
        if extra_css:
            head.append(STYLE(extra_css, type="text/css"))

        toc = TABLE(CLASS("toc"), width="100%", border="0", cellpadding="3px")
        for i, feed in enumerate(feeds):
            if feed:
                tr = TR()
                tr.append(TD(CLASS("calibre_rescale_120"), A(feed.title, href="feed_%d/index.html" % i)))
                tr.append(TD("%s" % len(feed.articles), style="text-align:right"))
                toc.append(tr)
        div = DIV(masthead_p, H3(CLASS("publish_date"), date), DIV(CLASS("divider")), toc)
        self.root = HTML(head, BODY(div))
        if self.html_lang:
            self.root.set("lang", self.html_lang)
开发者ID:JapaChin,项目名称:calibre,代码行数:32,代码来源:templates.py

示例2: TouchscreenIndexTemplate

class TouchscreenIndexTemplate(Template):

    def _generate(self, title, masthead, datefmt, feeds, extra_css=None, style=None):
        self.IS_HTML = False
        date = '%s, %s %s, %s' % (strftime('%A'), strftime('%B'), strftime('%d').lstrip('0'), strftime('%Y'))
        masthead_p = etree.Element("p")
        masthead_p.set("style","text-align:center")
        masthead_img = etree.Element("img")
        masthead_img.set("src",masthead)
        masthead_img.set("alt","masthead")
        masthead_p.append(masthead_img)

        head = HEAD(TITLE(title))
        if style:
            head.append(STYLE(style, type='text/css'))
        if extra_css:
            head.append(STYLE(extra_css, type='text/css'))

        toc = TABLE(CLASS('toc'),width="100%",border="0",cellpadding="3px")
        for i, feed in enumerate(feeds):
            if feed:
                tr = TR()
                tr.append(TD(CLASS('calibre_rescale_120'), A(feed.title, href='feed_%d/index.html'%i)))
                tr.append(TD('%s' % len(feed.articles), style="text-align:right"))
                toc.append(tr)
        div = DIV(
                masthead_p,
                H3(CLASS('publish_date'),date),
                DIV(CLASS('divider')),
                toc)
        self.root = HTML(head, BODY(div))
        if self.html_lang:
            self.root.set('lang', self.html_lang)
开发者ID:JimmXinu,项目名称:calibre,代码行数:33,代码来源:templates.py

示例3: IndexTemplate

class IndexTemplate(Template):
    def _generate(self, title, masthead, datefmt, feeds, extra_css=None, style=None):
        self.IS_HTML = False
        if isinstance(datefmt, unicode):
            datefmt = datefmt.encode(preferred_encoding)
        date = strftime(datefmt)
        head = HEAD(TITLE(title))
        if style:
            head.append(STYLE(style, type="text/css"))
        if extra_css:
            head.append(STYLE(extra_css, type="text/css"))
        ul = UL(CLASS("calibre_feed_list"))
        for i, feed in enumerate(feeds):
            if feed:
                li = LI(
                    A(feed.title, CLASS("feed", "calibre_rescale_120", href="feed_%d/index.html" % i)), id="feed_%d" % i
                )
                ul.append(li)
        div = DIV(
            PT(IMG(src=masthead, alt="masthead"), style="text-align:center"),
            PT(date, style="text-align:right"),
            ul,
            CLASS("calibre_rescale_100"),
        )
        self.root = HTML(head, BODY(div))
        if self.html_lang:
            self.root.set("lang", self.html_lang)
开发者ID:JapaChin,项目名称:calibre,代码行数:27,代码来源:templates.py

示例4: EmbeddedContent

class EmbeddedContent(Template):
    def _generate(self, article, style=None, extra_css=None):
        content = article.content if article.content else ""
        summary = article.summary if article.summary else ""
        text = content if len(content) > len(summary) else summary
        head = HEAD(TITLE(article.title))
        if style:
            head.append(STYLE(style, type="text/css"))
        if extra_css:
            head.append(STYLE(extra_css, type="text/css"))

        if isbytestring(text):
            text = text.decode("utf-8", "replace")
        elements = html.fragments_fromstring(text)
        self.root = HTML(head, BODY(H2(article.title), DIV()))
        div = self.root.find("body").find("div")
        if elements and isinstance(elements[0], unicode):
            div.text = elements[0]
            elements = list(elements)[1:]
        for elem in elements:
            if hasattr(elem, "getparent"):
                elem.getparent().remove(elem)
            else:
                elem = SPAN(elem)
            div.append(elem)
开发者ID:JapaChin,项目名称:calibre,代码行数:25,代码来源:templates.py

示例5: __init__

 def __init__(self, path_or_stream, dest_dir=None, log=None, notes_text=None):
     self.docx = DOCX(path_or_stream, log=log)
     self.ms_pat = re.compile(r'\s{2,}')
     self.ws_pat = re.compile(r'[\n\r\t]')
     self.log = self.docx.log
     self.notes_text = notes_text or _('Notes')
     self.dest_dir = dest_dir or os.getcwdu()
     self.mi = self.docx.metadata
     self.body = BODY()
     self.tables = Tables()
     self.styles = Styles(self.tables)
     self.images = Images()
     self.object_map = OrderedDict()
     self.html = HTML(
         HEAD(
             META(charset='utf-8'),
             TITLE(self.mi.title or _('Unknown')),
             LINK(rel='stylesheet', type='text/css', href='docx.css'),
         ),
         self.body
     )
     self.html.text='\n\t'
     self.html[0].text='\n\t\t'
     self.html[0].tail='\n'
     for child in self.html[0]:
         child.tail = '\n\t\t'
     self.html[0][-1].tail = '\n\t'
     self.html[1].text = self.html[1].tail = '\n'
     lang = canonicalize_lang(self.mi.language)
     if lang and lang != 'und':
         lang = lang_as_iso639_1(lang)
         if lang:
             self.html.set('lang', lang)
开发者ID:RealEnder,项目名称:calibre,代码行数:33,代码来源:to_html.py

示例6: _generate

    def _generate(self, article, style=None, extra_css=None):
        content = article.content if article.content else ''
        summary = article.summary if article.summary else ''
        text = content if len(content) > len(summary) else summary
        head = HEAD(TITLE(article.title))
        if style:
            head.append(STYLE(style, type='text/css'))
        if extra_css:
            head.append(STYLE(extra_css, type='text/css'))

        if isbytestring(text):
            text = text.decode('utf-8', 'replace')
        elements = html.fragments_fromstring(text)
        self.root = HTML(head,
                BODY(H2(article.title), DIV()))
        div = self.root.find('body').find('div')
        if elements and isinstance(elements[0], unicode_type):
            div.text = elements[0]
            elements = list(elements)[1:]
        for elem in elements:
            if hasattr(elem, 'getparent'):
                elem.getparent().remove(elem)
            else:
                elem = SPAN(elem)
            div.append(elem)
开发者ID:JimmXinu,项目名称:calibre,代码行数:25,代码来源:templates.py

示例7: __init__

 def __init__(self, path_or_stream, dest_dir=None, log=None, notes_text=None):
     self.docx = DOCX(path_or_stream, log=log)
     self.log = self.docx.log
     self.notes_text = notes_text or _("Notes")
     self.dest_dir = dest_dir or os.getcwdu()
     self.mi = self.docx.metadata
     self.body = BODY()
     self.styles = Styles()
     self.images = Images()
     self.tables = Tables()
     self.object_map = OrderedDict()
     self.html = HTML(
         HEAD(
             META(charset="utf-8"),
             TITLE(self.mi.title or _("Unknown")),
             LINK(rel="stylesheet", type="text/css", href="docx.css"),
         ),
         self.body,
     )
     self.html.text = "\n\t"
     self.html[0].text = "\n\t\t"
     self.html[0].tail = "\n"
     for child in self.html[0]:
         child.tail = "\n\t\t"
     self.html[0][-1].tail = "\n\t"
     self.html[1].text = self.html[1].tail = "\n"
     lang = canonicalize_lang(self.mi.language)
     if lang and lang != "und":
         lang = lang_as_iso639_1(lang)
         if lang:
             self.html.set("lang", lang)
开发者ID:bjhemens,项目名称:calibre,代码行数:31,代码来源:to_html.py

示例8: IndexTemplate

class IndexTemplate(Template):

    def _generate(self, title, masthead, datefmt, feeds, extra_css=None, style=None):
        self.IS_HTML = False
        date = strftime(datefmt)
        head = HEAD(TITLE(title))
        if style:
            head.append(STYLE(style, type='text/css'))
        if extra_css:
            head.append(STYLE(extra_css, type='text/css'))
        ul = UL(CLASS('calibre_feed_list'))
        for i, feed in enumerate(feeds):
            if feed:
                li = LI(A(feed.title, CLASS('feed', 'calibre_rescale_120',
                    href='feed_%d/index.html'%i)), id='feed_%d'%i)
                ul.append(li)
        div = DIV(
                PT(IMG(src=masthead,alt="masthead"),style='text-align:center'),
                PT(date, style='text-align:right'),
                ul,
                CLASS('calibre_rescale_100'))
        self.root = HTML(head, BODY(div))
        if self.html_lang:
            self.root.set('lang', self.html_lang)
开发者ID:JimmXinu,项目名称:calibre,代码行数:24,代码来源:templates.py

示例9: __init__

 def __init__(self, path_or_stream, dest_dir=None, log=None, detect_cover=True, notes_text=None, notes_nopb=False, nosupsub=False):
     self.docx = DOCX(path_or_stream, log=log)
     self.namespace = self.docx.namespace
     self.ms_pat = re.compile(r'\s{2,}')
     self.ws_pat = re.compile(r'[\n\r\t]')
     self.log = self.docx.log
     self.detect_cover = detect_cover
     self.notes_text = notes_text or _('Notes')
     self.notes_nopb = notes_nopb
     self.nosupsub = nosupsub
     self.dest_dir = dest_dir or os.getcwdu()
     self.mi = self.docx.metadata
     self.body = BODY()
     self.theme = Theme(self.namespace)
     self.settings = Settings(self.namespace)
     self.tables = Tables(self.namespace)
     self.fields = Fields(self.namespace)
     self.styles = Styles(self.namespace, self.tables)
     self.images = Images(self.namespace, self.log)
     self.object_map = OrderedDict()
     self.html = HTML(
         HEAD(
             META(charset='utf-8'),
             TITLE(self.mi.title or _('Unknown')),
             LINK(rel='stylesheet', type='text/css', href='docx.css'),
         ),
         self.body
     )
     self.html.text='\n\t'
     self.html[0].text='\n\t\t'
     self.html[0].tail='\n'
     for child in self.html[0]:
         child.tail = '\n\t\t'
     self.html[0][-1].tail = '\n\t'
     self.html[1].text = self.html[1].tail = '\n'
     lang = html_lang(self.mi.language)
     if lang:
         self.html.set('lang', lang)
         self.doc_lang = lang
     else:
         self.doc_lang = None
开发者ID:miurahr,项目名称:calibre,代码行数:41,代码来源:to_html.py

示例10: _generate

    def _generate(self, f, feeds, cutoff, extra_css=None, style=None):
        feed = feeds[f]
        head = HEAD(TITLE(feed.title))
        if style:
            head.append(STYLE(style, type="text/css"))
        if extra_css:
            head.append(STYLE(extra_css, type="text/css"))
        body = BODY()
        body.append(self.get_navbar(f, feeds))

        div = DIV(H2(feed.title, CLASS("calibre_feed_title", "calibre_rescale_160")), CLASS("calibre_rescale_100"))
        body.append(div)
        if getattr(feed, "image", None):
            div.append(
                DIV(IMG(alt=feed.image_alt if feed.image_alt else "", src=feed.image_url), CLASS("calibre_feed_image"))
            )
        if getattr(feed, "description", None):
            d = DIV(feed.description, CLASS("calibre_feed_description", "calibre_rescale_80"))
            d.append(BR())
            div.append(d)
        ul = UL(CLASS("calibre_article_list"))
        for i, article in enumerate(feed.articles):
            if not getattr(article, "downloaded", False):
                continue
            li = LI(
                A(article.title, CLASS("article calibre_rescale_120", href=article.url)),
                SPAN(article.formatted_date, CLASS("article_date")),
                CLASS("calibre_rescale_100", id="article_%d" % i, style="padding-bottom:0.5em"),
            )
            if article.summary:
                li.append(DIV(cutoff(article.text_summary), CLASS("article_description", "calibre_rescale_70")))
            ul.append(li)
        div.append(ul)
        div.append(self.get_navbar(f, feeds, top=False))
        self.root = HTML(head, body)
        if self.html_lang:
            self.root.set("lang", self.html_lang)
开发者ID:JapaChin,项目名称:calibre,代码行数:37,代码来源:templates.py

示例11: FeedTemplate

class FeedTemplate(Template):
    def get_navbar(self, f, feeds, top=True):
        if len(feeds) < 2:
            return DIV()
        navbar = DIV("| ", CLASS("calibre_navbar", "calibre_rescale_70", style="text-align:center"))
        if not top:
            hr = HR()
            navbar.append(hr)
            navbar.text = None
            hr.tail = "| "

        if f + 1 < len(feeds):
            link = A(_("Next section"), href="../feed_%d/index.html" % (f + 1))
            link.tail = " | "
            navbar.append(link)
        link = A(_("Main menu"), href="../index.html")
        link.tail = " | "
        navbar.append(link)
        if f > 0:
            link = A(_("Previous section"), href="../feed_%d/index.html" % (f - 1))
            link.tail = " |"
            navbar.append(link)
        if top:
            navbar.append(HR())
        return navbar

    def _generate(self, f, feeds, cutoff, extra_css=None, style=None):
        feed = feeds[f]
        head = HEAD(TITLE(feed.title))
        if style:
            head.append(STYLE(style, type="text/css"))
        if extra_css:
            head.append(STYLE(extra_css, type="text/css"))
        body = BODY()
        body.append(self.get_navbar(f, feeds))

        div = DIV(H2(feed.title, CLASS("calibre_feed_title", "calibre_rescale_160")), CLASS("calibre_rescale_100"))
        body.append(div)
        if getattr(feed, "image", None):
            div.append(
                DIV(IMG(alt=feed.image_alt if feed.image_alt else "", src=feed.image_url), CLASS("calibre_feed_image"))
            )
        if getattr(feed, "description", None):
            d = DIV(feed.description, CLASS("calibre_feed_description", "calibre_rescale_80"))
            d.append(BR())
            div.append(d)
        ul = UL(CLASS("calibre_article_list"))
        for i, article in enumerate(feed.articles):
            if not getattr(article, "downloaded", False):
                continue
            li = LI(
                A(article.title, CLASS("article calibre_rescale_120", href=article.url)),
                SPAN(article.formatted_date, CLASS("article_date")),
                CLASS("calibre_rescale_100", id="article_%d" % i, style="padding-bottom:0.5em"),
            )
            if article.summary:
                li.append(DIV(cutoff(article.text_summary), CLASS("article_description", "calibre_rescale_70")))
            ul.append(li)
        div.append(ul)
        div.append(self.get_navbar(f, feeds, top=False))
        self.root = HTML(head, body)
        if self.html_lang:
            self.root.set("lang", self.html_lang)
开发者ID:JapaChin,项目名称:calibre,代码行数:63,代码来源:templates.py

示例12: FeedTemplate

class FeedTemplate(Template):

    def get_navbar(self, f, feeds, top=True):
        if len(feeds) < 2:
            return DIV()
        navbar = DIV('| ', CLASS('calibre_navbar', 'calibre_rescale_70',
            style='text-align:center'))
        if not top:
            hr = HR()
            navbar.append(hr)
            navbar.text = None
            hr.tail = '| '

        if f+1 < len(feeds):
            link = A(_('Next section'), href='../feed_%d/index.html'%(f+1))
            link.tail = ' | '
            navbar.append(link)
        link = A(_('Main menu'), href="../index.html")
        link.tail = ' | '
        navbar.append(link)
        if f > 0:
            link = A(_('Previous section'), href='../feed_%d/index.html'%(f-1))
            link.tail = ' |'
            navbar.append(link)
        if top:
            navbar.append(HR())
        return navbar

    def _generate(self, f, feeds, cutoff, extra_css=None, style=None):
        from calibre.utils.cleantext import clean_xml_chars
        feed = feeds[f]
        head = HEAD(TITLE(feed.title))
        if style:
            head.append(STYLE(style, type='text/css'))
        if extra_css:
            head.append(STYLE(extra_css, type='text/css'))
        body = BODY()
        body.append(self.get_navbar(f, feeds))

        div = DIV(
                H2(feed.title,
                    CLASS('calibre_feed_title', 'calibre_rescale_160')),
                CLASS('calibre_rescale_100')
              )
        body.append(div)
        if getattr(feed, 'image', None):
            div.append(DIV(IMG(
                alt=feed.image_alt if feed.image_alt else '',
                src=feed.image_url
                ),
                CLASS('calibre_feed_image')))
        if getattr(feed, 'description', None):
            d = DIV(clean_xml_chars(feed.description), CLASS('calibre_feed_description',
                'calibre_rescale_80'))
            d.append(BR())
            div.append(d)
        ul = UL(CLASS('calibre_article_list'))
        for i, article in enumerate(feed.articles):
            if not getattr(article, 'downloaded', False):
                continue
            li = LI(
                    A(article.title, CLASS('article calibre_rescale_120',
                                    href=article.url)),
                    SPAN(article.formatted_date, CLASS('article_date')),
                    CLASS('calibre_rescale_100', id='article_%d'%i,
                            style='padding-bottom:0.5em')
                    )
            if article.summary:
                li.append(DIV(clean_xml_chars(cutoff(article.text_summary)),
                    CLASS('article_description', 'calibre_rescale_70')))
            ul.append(li)
        div.append(ul)
        div.append(self.get_navbar(f, feeds, top=False))
        self.root = HTML(head, body)
        if self.html_lang:
            self.root.set('lang', self.html_lang)
开发者ID:JimmXinu,项目名称:calibre,代码行数:76,代码来源:templates.py

示例13: Convert

class Convert(object):
    def __init__(self, path_or_stream, dest_dir=None, log=None, notes_text=None):
        self.docx = DOCX(path_or_stream, log=log)
        self.log = self.docx.log
        self.notes_text = notes_text or _("Notes")
        self.dest_dir = dest_dir or os.getcwdu()
        self.mi = self.docx.metadata
        self.body = BODY()
        self.styles = Styles()
        self.images = Images()
        self.tables = Tables()
        self.object_map = OrderedDict()
        self.html = HTML(
            HEAD(
                META(charset="utf-8"),
                TITLE(self.mi.title or _("Unknown")),
                LINK(rel="stylesheet", type="text/css", href="docx.css"),
            ),
            self.body,
        )
        self.html.text = "\n\t"
        self.html[0].text = "\n\t\t"
        self.html[0].tail = "\n"
        for child in self.html[0]:
            child.tail = "\n\t\t"
        self.html[0][-1].tail = "\n\t"
        self.html[1].text = self.html[1].tail = "\n"
        lang = canonicalize_lang(self.mi.language)
        if lang and lang != "und":
            lang = lang_as_iso639_1(lang)
            if lang:
                self.html.set("lang", lang)

    def __call__(self):
        doc = self.docx.document
        relationships_by_id, relationships_by_type = self.docx.document_relationships
        self.read_styles(relationships_by_type)
        self.images(relationships_by_id)
        self.layers = OrderedDict()
        self.framed = [[]]
        self.framed_map = {}
        self.anchor_map = {}
        self.link_map = defaultdict(list)

        self.read_page_properties(doc)
        for wp, page_properties in self.page_map.iteritems():
            self.current_page = page_properties
            p = self.convert_p(wp)
            self.body.append(p)

        notes_header = None
        if self.footnotes.has_notes:
            dl = DL()
            dl.set("class", "notes")
            self.body.append(H1(self.notes_text))
            notes_header = self.body[-1]
            notes_header.set("class", "notes-header")
            self.body.append(dl)
            for anchor, text, note in self.footnotes:
                dl.append(DT("[", A("←" + text, href="#back_%s" % anchor, title=text), id=anchor))
                dl[-1][0].tail = "]"
                dl.append(DD())
                in_table = False
                for wp in note:
                    if wp.tag.endswith("}tbl"):
                        self.tables.register(wp)
                        in_table = True
                        continue
                    if in_table:
                        if ancestor(wp, "w:tbl") is not None:
                            self.tables.add(wp)
                        else:
                            in_table = False
                    p = self.convert_p(wp)
                    dl[-1].append(p)

        self.resolve_links(relationships_by_id)

        self.styles.cascade(self.layers)

        self.tables.apply_markup(self.object_map)

        numbered = []
        for html_obj, obj in self.object_map.iteritems():
            raw = obj.get("calibre_num_id", None)
            if raw is not None:
                lvl, num_id = raw.partition(":")[0::2]
                try:
                    lvl = int(lvl)
                except (TypeError, ValueError):
                    lvl = 0
                numbered.append((html_obj, num_id, lvl))
        self.numbering.apply_markup(numbered, self.body, self.styles, self.object_map)
        self.apply_frames()

        if len(self.body) > 0:
            self.body.text = "\n\t"
            for child in self.body:
                child.tail = "\n\t"
            self.body[-1].tail = "\n"
#.........这里部分代码省略.........
开发者ID:bjhemens,项目名称:calibre,代码行数:101,代码来源:to_html.py

示例14: Convert

class Convert(object):

    def __init__(self, path_or_stream, dest_dir=None, log=None, detect_cover=True, notes_text=None):
        self.docx = DOCX(path_or_stream, log=log)
        self.ms_pat = re.compile(r'\s{2,}')
        self.ws_pat = re.compile(r'[\n\r\t]')
        self.log = self.docx.log
        self.detect_cover = detect_cover
        self.notes_text = notes_text or _('Notes')
        self.dest_dir = dest_dir or os.getcwdu()
        self.mi = self.docx.metadata
        self.body = BODY()
        self.theme = Theme()
        self.settings = Settings()
        self.tables = Tables()
        self.fields = Fields()
        self.styles = Styles(self.tables)
        self.images = Images(self.log)
        self.object_map = OrderedDict()
        self.html = HTML(
            HEAD(
                META(charset='utf-8'),
                TITLE(self.mi.title or _('Unknown')),
                LINK(rel='stylesheet', type='text/css', href='docx.css'),
            ),
            self.body
        )
        self.html.text='\n\t'
        self.html[0].text='\n\t\t'
        self.html[0].tail='\n'
        for child in self.html[0]:
            child.tail = '\n\t\t'
        self.html[0][-1].tail = '\n\t'
        self.html[1].text = self.html[1].tail = '\n'
        lang = canonicalize_lang(self.mi.language)
        if lang and lang != 'und':
            lang = lang_as_iso639_1(lang)
            if lang:
                self.html.set('lang', lang)

    def __call__(self):
        doc = self.docx.document
        relationships_by_id, relationships_by_type = self.docx.document_relationships
        self.fields(doc, self.log)
        self.read_styles(relationships_by_type)
        self.images(relationships_by_id)
        self.layers = OrderedDict()
        self.framed = [[]]
        self.framed_map = {}
        self.anchor_map = {}
        self.link_map = defaultdict(list)
        self.link_source_map = {}
        paras = []

        self.log.debug('Converting Word markup to HTML')

        self.read_page_properties(doc)
        self.current_rels = relationships_by_id
        for wp, page_properties in self.page_map.iteritems():
            self.current_page = page_properties
            if wp.tag.endswith('}p'):
                p = self.convert_p(wp)
                self.body.append(p)
                paras.append(wp)

        self.read_block_anchors(doc)
        self.styles.apply_contextual_spacing(paras)
        # Apply page breaks at the start of every section, except the first
        # section (since that will be the start of the file)
        self.styles.apply_section_page_breaks(self.section_starts[1:])

        notes_header = None
        orig_rid_map = self.images.rid_map
        if self.footnotes.has_notes:
            dl = DL()
            dl.set('class', 'notes')
            self.body.append(H1(self.notes_text))
            notes_header = self.body[-1]
            notes_header.set('class', 'notes-header')
            self.body.append(dl)
            for anchor, text, note in self.footnotes:
                dl.append(DT('[', A('←' + text, href='#back_%s' % anchor, title=text), id=anchor))
                dl[-1][0].tail = ']'
                dl.append(DD())
                paras = []
                self.images.rid_map = self.current_rels = note.rels[0]
                for wp in note:
                    if wp.tag.endswith('}tbl'):
                        self.tables.register(wp, self.styles)
                        self.page_map[wp] = self.current_page
                    else:
                        p = self.convert_p(wp)
                        dl[-1].append(p)
                        paras.append(wp)
                self.styles.apply_contextual_spacing(paras)

        for p, wp in self.object_map.iteritems():
            if len(p) > 0 and not p.text and len(p[0]) > 0 and not p[0].text and p[0][0].get('class', None) == 'tab':
                # Paragraph uses tabs for indentation, convert to text-indent
                parent = p[0]
#.........这里部分代码省略.........
开发者ID:AtulKumar2,项目名称:calibre,代码行数:101,代码来源:to_html.py

示例15: Convert

class Convert(object):

    def __init__(self, path_or_stream, dest_dir=None, log=None, notes_text=None):
        self.docx = DOCX(path_or_stream, log=log)
        self.ms_pat = re.compile(r'\s{2,}')
        self.ws_pat = re.compile(r'[\n\r\t]')
        self.log = self.docx.log
        self.notes_text = notes_text or _('Notes')
        self.dest_dir = dest_dir or os.getcwdu()
        self.mi = self.docx.metadata
        self.body = BODY()
        self.tables = Tables()
        self.styles = Styles(self.tables)
        self.images = Images()
        self.object_map = OrderedDict()
        self.html = HTML(
            HEAD(
                META(charset='utf-8'),
                TITLE(self.mi.title or _('Unknown')),
                LINK(rel='stylesheet', type='text/css', href='docx.css'),
            ),
            self.body
        )
        self.html.text='\n\t'
        self.html[0].text='\n\t\t'
        self.html[0].tail='\n'
        for child in self.html[0]:
            child.tail = '\n\t\t'
        self.html[0][-1].tail = '\n\t'
        self.html[1].text = self.html[1].tail = '\n'
        lang = canonicalize_lang(self.mi.language)
        if lang and lang != 'und':
            lang = lang_as_iso639_1(lang)
            if lang:
                self.html.set('lang', lang)

    def __call__(self):
        doc = self.docx.document
        relationships_by_id, relationships_by_type = self.docx.document_relationships
        self.read_styles(relationships_by_type)
        self.images(relationships_by_id)
        self.layers = OrderedDict()
        self.framed = [[]]
        self.framed_map = {}
        self.anchor_map = {}
        self.link_map = defaultdict(list)

        self.read_page_properties(doc)
        for wp, page_properties in self.page_map.iteritems():
            self.current_page = page_properties
            if wp.tag.endswith('}p'):
                p = self.convert_p(wp)
                self.body.append(p)

        notes_header = None
        if self.footnotes.has_notes:
            dl = DL()
            dl.set('class', 'notes')
            self.body.append(H1(self.notes_text))
            notes_header = self.body[-1]
            notes_header.set('class', 'notes-header')
            self.body.append(dl)
            for anchor, text, note in self.footnotes:
                dl.append(DT('[', A('←' + text, href='#back_%s' % anchor, title=text), id=anchor))
                dl[-1][0].tail = ']'
                dl.append(DD())
                for wp in note:
                    if wp.tag.endswith('}tbl'):
                        self.tables.register(wp, self.styles)
                        self.page_map[wp] = self.current_page
                    p = self.convert_p(wp)
                    dl[-1].append(p)

        self.resolve_links(relationships_by_id)

        self.styles.cascade(self.layers)

        self.tables.apply_markup(self.object_map, self.page_map)

        numbered = []
        for html_obj, obj in self.object_map.iteritems():
            raw = obj.get('calibre_num_id', None)
            if raw is not None:
                lvl, num_id = raw.partition(':')[0::2]
                try:
                    lvl = int(lvl)
                except (TypeError, ValueError):
                    lvl = 0
                numbered.append((html_obj, num_id, lvl))
        self.numbering.apply_markup(numbered, self.body, self.styles, self.object_map)
        self.apply_frames()

        if len(self.body) > 0:
            self.body.text = '\n\t'
            for child in self.body:
                child.tail = '\n\t'
            self.body[-1].tail = '\n'

        self.styles.generate_classes()
        for html_obj, obj in self.object_map.iteritems():
#.........这里部分代码省略.........
开发者ID:RealEnder,项目名称:calibre,代码行数:101,代码来源:to_html.py


注:本文中的lxml.html.builder.HTML类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。