def run(self):
# type: () -> List[nodes.Node]
if self.arguments:
document = self.state.document
if self.content:
return [document.reporter.warning(
__('Symbolator directive cannot have both content and '
'a filename argument'), line=self.lineno)]
env = self.state.document.settings.env
argument = search_image_for_language(self.arguments[0], env)
rel_filename, filename = env.relfn2path(argument)
env.note_dependency(rel_filename)
try:
with codecs.open(filename, 'r', 'utf-8') as fp:
symbolator_code = fp.read()
except (IOError, OSError):
return [document.reporter.warning(
__('External Symbolator file %r not found or reading '
'it failed') % filename, line=self.lineno)]
else:
symbolator_code = '\n'.join(self.content)
if not symbolator_code.strip():
return [self.state_machine.reporter.warning(
__('Ignoring "symbolator" directive without content.'),
line=self.lineno)]
node = symbolator()
node['code'] = symbolator_code
node['options'] = {}
if 'symbolator_cmd' in self.options:
node['options']['symbolator_cmd'] = self.options['symbolator_cmd']
if 'alt' in self.options:
node['alt'] = self.options['alt']
if 'align' in self.options:
node['align'] = self.options['align']
if 'name' in self.options:
node['options']['name'] = self.options['name']
caption = self.options.get('caption')
if caption:
node = figure_wrapper(self, node, caption)
self.add_name(node)
return [node]
评论列表
文章目录