本文整理汇总了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))
示例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)