本文整理匯總了Python中docutils.nodes.substitution_reference方法的典型用法代碼示例。如果您正苦於以下問題:Python nodes.substitution_reference方法的具體用法?Python nodes.substitution_reference怎麽用?Python nodes.substitution_reference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類docutils.nodes
的用法示例。
在下文中一共展示了nodes.substitution_reference方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: substitution_reference
# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import substitution_reference [as 別名]
def substitution_reference(self, match, lineno):
before, inlines, remaining, sysmessages, endstring = self.inline_obj(
match, lineno, self.patterns.substitution_ref,
nodes.substitution_reference)
if len(inlines) == 1:
subref_node = inlines[0]
if isinstance(subref_node, nodes.substitution_reference):
subref_text = subref_node.astext()
self.document.note_substitution_ref(subref_node, subref_text)
if endstring[-1:] == '_':
reference_node = nodes.reference(
'|%s%s' % (subref_text, endstring), '')
if endstring[-2:] == '__':
reference_node['anonymous'] = 1
else:
reference_node['refname'] = normalize_name(subref_text)
self.document.note_refname(reference_node)
reference_node += subref_node
inlines = [reference_node]
return before, inlines, remaining, sysmessages
示例2: apply
# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import substitution_reference [as 別名]
def apply(self, **kwargs):
# only handle those not otherwise defined in the document
to_handle = self.emojis - set(self.document.substitution_defs)
for ref in self.document.traverse(nodes.substitution_reference):
refname = ref['refname']
if refname in to_handle:
node = nodes.image(
uri='http://www.tortue.me/emoji/{0}.png'.format(refname),
alt=refname,
classes=['emoji'],
height="24px",
width="24px")
ref.replace_self(node)