symbolator_sphinx.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:symbolator 作者: kevinpt 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号