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


Python E.title方法代码示例

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


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

示例1: _build_html_title

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import title [as 别名]
    def _build_html_title(self):
        if self.meta.title:
            title_text = '{} – {}'.format(self.meta.title, self.meta.app_name)
        else:
            title_text = self.meta.app_name

        self.elements.head.append(E.title(title_text))
开发者ID:chfoo,项目名称:wuff,代码行数:9,代码来源:html.py

示例2: main

# 需要导入模块: from lxml.html.builder import E [as 别名]
# 或者: from lxml.html.builder.E import title [as 别名]

#.........这里部分代码省略.........
                heading.text, heading[:] = None, []
                href = {"href": "#" + id_}
                link = HTML.a(href, *contents)
                heading.insert(0, link)

        # ----------------------------------------------------------------------


        # TODO: deal with metadata & insert a document header with:
        #   - title, 
        #   - date (format: Month Day, Year), autoformat, autogen ? 
        #   - author(s) (with mail & affiliation when available ?).
        #     Assume custom metadata or parse the author field ?
        #     Representation of multiple authors ? MMm eLIFEsciences use
        #     popup for author info. Ex: http://elifesciences.org/content/4/e06356 !
        #     here, use hints from http://dtd.nlm.nih.gov/book/tag-library/:
        #
        #       - name (don't be more precise)
        #       - affiliation (concatenate)
        #       - address ???
        #       - email  --> Font Awesome Icon
        #       - url / uri ?
        #       - form of ID ? (like HAL ? or ZBlatt ?)



        # TODO: look at the rendering of
        #       http://kieranhealy.org/blog/archives/2014/01/23/plain-text/:
        #         - small grey date on top, bold title, bold author name,
        #           italics affiliation, repeat.


        metadata = get_metadata(str(doc))

        items = []

        date = parse_html(metadata.get("date"))
        if date is not None:
            items.append(HTML.p({"class": "date"}, *date))

#        def textify(item):
#          if isinstance(item, basestring):
#              return item
#          elif hasattr(item, "text"):
#              return item.text
#          else:
#              return "".join([textify(it) or "" for it in item])

        title = parse_html(metadata.get("title"))
        title_id = None
        if title is not None:
            #title_id = textify(title).lower().replace(" ", "-")
            items.append(
              HTML.h1(
                {"class": "title"}, 
                HTML.a(
                  {"href": "#"},
                  *title
                )
              )
            )
            head.insert(0, HTML.title(*title))

        authors = metadata.get("author") or []

        for author in authors:
            if isinstance(author, basestring):
                name = parse_html(author)
                email = None
                affiliation = None
            else:
                name = parse_html(author.get("name"))
                email = parse_html(author.get("email"))
                affiliation = parse_html(author.get("affiliation"))

            if name is not None:
                if email is not None:
                    name = [HTML.a({"href": "mailto:" + email[0]}, *name)]
                name = HTML.p({"class": "author"}, *name)
                items.append(name)
                if affiliation is not None:
                    affiliation = HTML.p({"class": "affiliation"}, *affiliation)
                    items.append(affiliation)
        
        header_attr = {"class": "main"}
#        if title_id is not None:
#          header_attr["id"] = title_id
        header = HTML.header(header_attr, *items)
#        print("HEADER", lxml.html.tostring(header))
        body.insert(0, header)
#        print("BODY", lxml.html.tostring(body))
#        print("HTML", lxml.html.tostring(html))


        # ----------------------------------------------------------------------
        info("Generate the standalone HTML file")
        html_str = lxml.html.tostring(html, encoding="utf-8", doctype="<!DOCTYPE html>")
        doc.with_suffix(".html").open("wb").write(html_str)

    sys.exit(0)
开发者ID:boisgera,项目名称:artdoc,代码行数:104,代码来源:__init__.py


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