本文整理汇总了Python中lxml.html.builder.SPAN.text方法的典型用法代码示例。如果您正苦于以下问题:Python SPAN.text方法的具体用法?Python SPAN.text怎么用?Python SPAN.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.html.builder.SPAN
的用法示例。
在下文中一共展示了SPAN.text方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit
# 需要导入模块: from lxml.html.builder import SPAN [as 别名]
# 或者: from lxml.html.builder.SPAN import text [as 别名]
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' or (last_val is None and val == 1):
child.attrib.pop('value')
last_val = val
current_run[-1].tail = '\n'
del current_run[:]
示例2: commit
# 需要导入模块: from lxml.html.builder import SPAN [as 别名]
# 或者: from lxml.html.builder.SPAN import text [as 别名]
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: commit
# 需要导入模块: from lxml.html.builder import SPAN [as 别名]
# 或者: from lxml.html.builder.SPAN import text [as 别名]
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({'list-style-type': lvl.fmt}, '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[:]