本文整理汇总了Python中lxml.html.builder.SPAN类的典型用法代码示例。如果您正苦于以下问题:Python SPAN类的具体用法?Python SPAN怎么用?Python SPAN使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SPAN类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit
def commit(current_run):
if not current_run:
return
start = current_run[0]
parent = start.getparent()
idx = parent.index(start)
d = self.instances[start.get('list-id')]
ilvl = int(start.get('list-lvl'))
lvl = d.levels[ilvl]
lvlid = start.get('list-id') + start.get('list-lvl')
wrap = (OL if lvl.is_numbered else UL)('\n\t')
has_template = 'list-template' in start.attrib
if has_template:
wrap.set('lvlid', lvlid)
else:
wrap.set('class', styles.register(lvl.css(images, self.pic_map, self.rid_map), 'list'))
parent.insert(idx, wrap)
last_val = None
for child in current_run:
wrap.append(child)
child.tail = '\n\t'
if has_template:
span = SPAN()
span.text = child.text
child.text = None
for gc in child:
span.append(gc)
child.append(span)
span = SPAN(child.get('list-template'))
last = templates.get(lvlid, '')
if span.text and len(span.text) > len(last):
templates[lvlid] = span.text
child.insert(0, span)
for attr in ('list-lvl', 'list-id', 'list-template'):
child.attrib.pop(attr, None)
val = int(child.get('value'))
if last_val == val - 1 or wrap.tag == 'ul':
child.attrib.pop('value')
last_val = val
current_run[-1].tail = '\n'
del current_run[:]
示例2: commit
def commit(current_run):
if not current_run:
return
start = current_run[0]
parent = start.getparent()
idx = parent.index(start)
d = self.instances[start.get("list-id")]
ilvl = int(start.get("list-lvl"))
lvl = d.levels[ilvl]
lvlid = start.get("list-id") + start.get("list-lvl")
has_template = "list-template" in start.attrib
wrap = (OL if lvl.is_numbered or has_template else UL)("\n\t")
if has_template:
wrap.set("lvlid", lvlid)
else:
wrap.set("class", styles.register(lvl.css(images, self.pic_map, self.rid_map), "list"))
ccss = lvl.char_css()
if ccss:
ccss = styles.register(ccss, "bullet")
parent.insert(idx, wrap)
last_val = None
for child in current_run:
wrap.append(child)
child.tail = "\n\t"
if has_template:
span = SPAN()
span.text = child.text
child.text = None
for gc in child:
span.append(gc)
child.append(span)
span = SPAN(child.get("list-template"))
if ccss:
span.set("class", ccss)
last = templates.get(lvlid, "")
if span.text and len(span.text) > len(last):
templates[lvlid] = span.text
child.insert(0, span)
for attr in ("list-lvl", "list-id", "list-template"):
child.attrib.pop(attr, None)
val = int(child.get("value"))
if last_val == val - 1 or wrap.tag == "ul":
child.attrib.pop("value")
last_val = val
current_run[-1].tail = "\n"
del current_run[:]
示例3: convert_run
def convert_run(self, run):
ans = SPAN()
self.object_map[ans] = run
text = Text(ans, "text", [])
for child in run:
if is_tag(child, "w:t"):
if not child.text:
continue
space = child.get(XML("space"), None)
if space == "preserve":
text.add_elem(SPAN(child.text, style="whitespace:pre-wrap"))
ans.append(text.elem)
else:
text.buf.append(child.text)
elif is_tag(child, "w:cr"):
text.add_elem(BR())
ans.append(text.elem)
elif is_tag(child, "w:br"):
typ = child.get("type", None)
if typ in {"column", "page"}:
br = BR(style="page-break-after:always")
else:
clear = child.get("clear", None)
if clear in {"all", "left", "right"}:
br = BR(style="clear:%s" % ("both" if clear == "all" else clear))
else:
br = BR()
text.add_elem(br)
ans.append(text.elem)
elif is_tag(child, "w:drawing") or is_tag(child, "w:pict"):
for img in self.images.to_html(child, self.current_page, self.docx, self.dest_dir):
text.add_elem(img)
ans.append(text.elem)
elif is_tag(child, "w:footnoteReference") or is_tag(child, "w:endnoteReference"):
anchor, name = self.footnotes.get_ref(child)
if anchor and name:
l = SUP(A(name, href="#" + anchor, title=name), id="back_%s" % anchor)
l.set("class", "noteref")
text.add_elem(l)
ans.append(text.elem)
if text.buf:
setattr(text.elem, text.attr, "".join(text.buf))
style = self.styles.resolve_run(run)
if style.vert_align in {"superscript", "subscript"}:
ans.tag = "sub" if style.vert_align == "subscript" else "sup"
if style.lang is not inherit:
ans.lang = style.lang
return ans
示例4: convert_run
def convert_run(self, run):
ans = SPAN()
self.object_map[ans] = run
text = Text(ans, 'text', [])
for child in run:
if is_tag(child, 'w:t'):
if not child.text:
continue
space = child.get(XML('space'), None)
preserve = False
if space == 'preserve':
# Only use a <span> with white-space:pre-wrap if this element
# actually needs it, i.e. if it has more than one
# consecutive space or it has newlines or tabs.
multi_spaces = self.ms_pat.search(child.text) is not None
preserve = multi_spaces or self.ws_pat.search(child.text) is not None
if preserve:
text.add_elem(SPAN(child.text, style="white-space:pre-wrap"))
ans.append(text.elem)
else:
text.buf.append(child.text)
elif is_tag(child, 'w:cr'):
text.add_elem(BR())
ans.append(text.elem)
elif is_tag(child, 'w:br'):
typ = get(child, 'w:type')
if typ in {'column', 'page'}:
br = BR(style='page-break-after:always')
else:
clear = child.get('clear', None)
if clear in {'all', 'left', 'right'}:
br = BR(style='clear:%s'%('both' if clear == 'all' else clear))
else:
br = BR()
text.add_elem(br)
ans.append(text.elem)
elif is_tag(child, 'w:drawing') or is_tag(child, 'w:pict'):
for img in self.images.to_html(child, self.current_page, self.docx, self.dest_dir):
text.add_elem(img)
ans.append(text.elem)
elif is_tag(child, 'w:footnoteReference') or is_tag(child, 'w:endnoteReference'):
anchor, name = self.footnotes.get_ref(child)
if anchor and name:
l = SUP(A(name, href='#' + anchor, title=name), id='back_%s' % anchor)
l.set('class', 'noteref')
text.add_elem(l)
ans.append(text.elem)
elif is_tag(child, 'w:tab'):
spaces = int(math.ceil((self.settings.default_tab_stop / 36) * 6))
text.add_elem(SPAN(NBSP * spaces))
ans.append(text.elem)
ans[-1].set('class', 'tab')
elif is_tag(child, 'w:noBreakHyphen'):
text.buf.append(u'\u2011')
elif is_tag(child, 'w:softHyphen'):
text.buf.append(u'\u00ad')
if text.buf:
setattr(text.elem, text.attr, ''.join(text.buf))
style = self.styles.resolve_run(run)
if style.vert_align in {'superscript', 'subscript'}:
ans.tag = 'sub' if style.vert_align == 'subscript' else 'sup'
if style.lang is not inherit:
ans.lang = style.lang
return ans
示例5: build_index
def build_index(books, num, search, sort, order, start, total, url_base, CKEYS,
prefix):
logo = DIV(IMG(src=prefix+'/static/calibre.png', alt=__appname__), id='logo')
search_box = build_search_box(num, search, sort, order, prefix)
navigation = build_navigation(start, num, total, prefix+url_base)
navigation2 = build_navigation(start, num, total, prefix+url_base)
bookt = TABLE(id='listing')
body = BODY(
logo,
search_box,
navigation,
HR(CLASS('spacer')),
bookt,
HR(CLASS('spacer')),
navigation2
)
# Book list {{{
for book in books:
thumbnail = TD(
IMG(type='image/jpeg', border='0',
src=prefix+'/get/thumb/%s' %
book['id']),
CLASS('thumbnail'))
data = TD()
for fmt in book['formats'].split(','):
if not fmt or fmt.lower().startswith('original_'):
continue
a = quote(ascii_filename(book['authors']))
t = quote(ascii_filename(book['title']))
s = SPAN(
A(
fmt.lower(),
href=prefix+'/get/%s/%s-%s_%d.%s' % (fmt, a, t,
book['id'], fmt.lower())
),
CLASS('button'))
s.tail = u''
data.append(s)
div = DIV(CLASS('data-container'))
data.append(div)
series = u'[%s - %s]'%(book['series'], book['series_index']) \
if book['series'] else ''
tags = u'Tags=[%s]'%book['tags'] if book['tags'] else ''
ctext = ''
for key in CKEYS:
val = book.get(key, None)
if val:
ctext += '%s=[%s] '%tuple(val.split(':#:'))
first = SPAN(u'\u202f%s %s by %s' % (book['title'], series,
book['authors']), CLASS('first-line'))
div.append(first)
second = SPAN(u'%s - %s %s %s' % ( book['size'],
book['timestamp'],
tags, ctext), CLASS('second-line'))
div.append(second)
bookt.append(TR(thumbnail, data))
# }}}
body.append(DIV(
A(_('Switch to the full interface (non-mobile interface)'),
href=prefix+"/browse",
style="text-decoration: none; color: blue",
title=_('The full interface gives you many more features, '
'but it may not work well on a small screen')),
style="text-align:center"))
return HTML(
HEAD(
TITLE(__appname__ + ' Library'),
LINK(rel='icon', href='http://calibre-ebook.com/favicon.ico',
type='image/x-icon'),
LINK(rel='stylesheet', type='text/css',
href=prefix+'/mobile/style.css'),
LINK(rel='apple-touch-icon', href="/static/calibre.png")
), # End head
body
) # End html
示例6: build_index
def build_index(books, num, search, sort, order, start, total, url_base, CKEYS, prefix, have_kobo_browser=False):
logo = DIV(IMG(src=prefix + "/static/calibre.png", alt=__appname__), id="logo")
search_box = build_search_box(num, search, sort, order, prefix)
navigation = build_navigation(start, num, total, prefix + url_base)
navigation2 = build_navigation(start, num, total, prefix + url_base)
bookt = TABLE(id="listing")
body = BODY(logo, search_box, navigation, HR(CLASS("spacer")), bookt, HR(CLASS("spacer")), navigation2)
# Book list {{{
for book in books:
thumbnail = TD(
IMG(type="image/jpeg", border="0", src=prefix + "/get/thumb/%s" % book["id"]), CLASS("thumbnail")
)
data = TD()
for fmt in book["formats"].split(","):
if not fmt or fmt.lower().startswith("original_"):
continue
file_extension = "kepub.epub" if have_kobo_browser and fmt.lower() == "kepub" else fmt
a = quote(ascii_filename(book["authors"]))
t = quote(ascii_filename(book["title"]))
s = SPAN(
A(fmt.lower(), href=prefix + "/get/%s/%s-%s_%d.%s" % (fmt, a, t, book["id"], file_extension.lower())),
CLASS("button"),
)
s.tail = u""
data.append(s)
div = DIV(CLASS("data-container"))
data.append(div)
series = u"[%s - %s]" % (book["series"], book["series_index"]) if book["series"] else ""
tags = u"Tags=[%s]" % book["tags"] if book["tags"] else ""
ctext = ""
for key in CKEYS:
val = book.get(key, None)
if val:
ctext += "%s=[%s] " % tuple(val.split(":#:"))
first = SPAN(
u"\u202f%s %s by %s"
% (clean_xml_chars(book["title"]), clean_xml_chars(series), clean_xml_chars(book["authors"])),
CLASS("first-line"),
)
div.append(first)
second = SPAN(u"%s - %s %s %s" % (book["size"], book["timestamp"], tags, ctext), CLASS("second-line"))
div.append(second)
bookt.append(TR(thumbnail, data))
# }}}
body.append(
DIV(
A(
_("Switch to the full interface (non-mobile interface)"),
href=prefix + "/browse",
style="text-decoration: none; color: blue",
title=_(
"The full interface gives you many more features, " "but it may not work well on a small screen"
),
),
style="text-align:center",
)
)
return HTML(
HEAD(
TITLE(__appname__ + " Library"),
LINK(rel="icon", href="//calibre-ebook.com/favicon.ico", type="image/x-icon"),
LINK(rel="stylesheet", type="text/css", href=prefix + "/mobile/style.css"),
LINK(rel="apple-touch-icon", href="/static/calibre.png"),
META(name="robots", content="noindex"),
), # End head
body,
) # End html
示例7: convert_run
def convert_run(self, run):
ans = SPAN()
self.object_map[ans] = run
text = Text(ans, 'text', [])
for child in run:
if is_tag(child, 'w:t'):
if not child.text:
continue
space = child.get(XML('space'), None)
if space == 'preserve':
text.add_elem(SPAN(child.text, style="white-space:pre-wrap"))
ans.append(text.elem)
else:
text.buf.append(child.text)
elif is_tag(child, 'w:cr'):
text.add_elem(BR())
ans.append(text.elem)
elif is_tag(child, 'w:br'):
typ = child.get('type', None)
if typ in {'column', 'page'}:
br = BR(style='page-break-after:always')
else:
clear = child.get('clear', None)
if clear in {'all', 'left', 'right'}:
br = BR(style='clear:%s'%('both' if clear == 'all' else clear))
else:
br = BR()
text.add_elem(br)
ans.append(text.elem)
elif is_tag(child, 'w:drawing') or is_tag(child, 'w:pict'):
for img in self.images.to_html(child, self.current_page, self.docx, self.dest_dir):
text.add_elem(img)
ans.append(text.elem)
elif is_tag(child, 'w:footnoteReference') or is_tag(child, 'w:endnoteReference'):
anchor, name = self.footnotes.get_ref(child)
if anchor and name:
l = SUP(A(name, href='#' + anchor, title=name), id='back_%s' % anchor)
l.set('class', 'noteref')
text.add_elem(l)
ans.append(text.elem)
elif is_tag(child, 'w:fldChar') and get(child, 'w:fldCharType') == 'separate':
text.buf.append('\xa0')
if text.buf:
setattr(text.elem, text.attr, ''.join(text.buf))
style = self.styles.resolve_run(run)
if style.vert_align in {'superscript', 'subscript'}:
ans.tag = 'sub' if style.vert_align == 'subscript' else 'sup'
if style.lang is not inherit:
ans.lang = style.lang
return ans