本文整理汇总了Python中docutils.parsers.rst.directives.uri方法的典型用法代码示例。如果您正苦于以下问题:Python directives.uri方法的具体用法?Python directives.uri怎么用?Python directives.uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.parsers.rst.directives
的用法示例。
在下文中一共展示了directives.uri方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: visit_image
# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def visit_image(self, node):
atts = {}
uri = node['uri']
filename = os.path.basename(uri)
atts['alt'] = node.get('alt', uri)
atts['thumbnail'] = 'true'
if 'width' in node:
atts['width'] = node['width']
if 'name' in node:
atts['title'] = node['name']
if (isinstance(node.parent, nodes.TextElement) or
(isinstance(node.parent, nodes.reference) and
not isinstance(node.parent.parent, nodes.TextElement))):
# Inline context or surrounded by <a>...</a>.
suffix = ''
else:
suffix = '\n'
self.context.append('')
self.body.append(self.imgtag(filename, suffix, **atts))
示例2: run
# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
# we create a new cell and add uri reference to specified file and we add it to the node tree
node = jupyter_node()
node['uri'] = directives.uri(self.arguments[0])
# we return the result
return [node]
示例3: run
# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
# remove 'align' processing
# remove 'target' processing
self.options.pop('align', None)
reference = directives.uri(self.arguments[0])
self.options['uri'] = reference
set_classes(self.options)
image_node = nodes.image(self.block_text, **self.options)
self.add_name(image_node)
return [image_node]
示例4: run
# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
if 'align' in self.options:
if isinstance(self.state, states.SubstitutionDef):
# Check for align_v_values.
if self.options['align'] not in self.align_v_values:
raise self.error(
'Error in "%s" directive: "%s" is not a valid value '
'for the "align" option within a substitution '
'definition. Valid values for "align" are: "%s".'
% (self.name, self.options['align'],
'", "'.join(self.align_v_values)))
elif self.options['align'] not in self.align_h_values:
raise self.error(
'Error in "%s" directive: "%s" is not a valid value for '
'the "align" option. Valid values for "align" are: "%s".'
% (self.name, self.options['align'],
'", "'.join(self.align_h_values)))
messages = []
reference = directives.uri(self.arguments[0])
self.options['uri'] = reference
reference_node = None
if 'target' in self.options:
block = states.escape2null(
self.options['target']).splitlines()
block = [line for line in block]
target_type, data = self.state.parse_target(
block, self.block_text, self.lineno)
if target_type == 'refuri':
reference_node = nodes.reference(refuri=data)
elif target_type == 'refname':
reference_node = nodes.reference(
refname=fully_normalize_name(data),
name=whitespace_normalize_name(data))
reference_node.indirect_reference_name = data
self.state.document.note_refname(reference_node)
else: # malformed target
messages.append(data) # data is a system message
del self.options['target']
set_classes(self.options)
image_node = nodes.image(self.block_text, **self.options)
self.add_name(image_node)
if reference_node:
reference_node += image_node
return messages + [reference_node]
else:
return messages + [image_node]
示例5: run
# 需要导入模块: from docutils.parsers.rst import directives [as 别名]
# 或者: from docutils.parsers.rst.directives import uri [as 别名]
def run(self):
node = nodes.Element()
node.document = self.state.document
env = self.state.document.settings.env
docname = env.docname
template_filename = self.options.get("file")
debug_template = self.options.get("debug")
cxt = (self.app.config.jinja_contexts[self.arguments[0]].copy()
if self.arguments else {})
cxt["options"] = {
"header_char": self.options.get("header_char")
}
if template_filename:
if debug_template is not None:
print('')
print('********** Begin Jinja Debug Output: Template Before Processing **********')
print('********** From {} **********'.format(docname))
reference_uri = directives.uri(os.path.join('source', template_filename))
template_path = urllib.url2pathname(reference_uri)
encoded_path = template_path.encode(sys.getfilesystemencoding())
imagerealpath = os.path.abspath(encoded_path)
with codecs.open(imagerealpath, encoding='utf-8') as f:
print(f.read())
print('********** End Jinja Debug Output: Template Before Processing **********')
print('')
tpl = Environment(
loader=FileSystemLoader(
self.app.config.jinja_base, followlinks=True)
).get_template(template_filename)
else:
if debug_template is not None:
print('')
print('********** Begin Jinja Debug Output: Template Before Processing **********')
print('********** From {} **********'.format(docname))
print('\n'.join(self.content))
print('********** End Jinja Debug Output: Template Before Processing **********')
print('')
tpl = Environment(
loader=FileSystemLoader(
self.app.config.jinja_base, followlinks=True)
).from_string('\n'.join(self.content))
new_content = tpl.render(**cxt)
if debug_template is not None:
print('')
print('********** Begin Jinja Debug Output: Template After Processing **********')
print(new_content)
print('********** End Jinja Debug Output: Template After Processing **********')
print('')
new_content = StringList(new_content.splitlines(), source='')
sphinx.util.nested_parse_with_titles(
self.state, new_content, node)
return node.children