本文整理汇总了Python中docutils.nodes.NodeVisitor方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.NodeVisitor方法的具体用法?Python nodes.NodeVisitor怎么用?Python nodes.NodeVisitor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.NodeVisitor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def __init__(self, document, builder=None):
nodes.NodeVisitor.__init__(self, document)
self.builder = builder
self.settings = settings = document.settings
lcode = settings.language_code
self.language = languages.get_language(lcode, document.reporter)
# Not-None here indicates Markdown should use HTTP for internal and
# download links.
self.markdown_http_base = (
builder.markdown_http_base if builder else None
)
# Warn only once per writer about unsupported elements
self._warned = set()
# Lookup table to get section list from name
self._lists = OrderedDict((('head', []), ('body', []), ('foot', [])))
# Reset attributes modified by reading
self.reset()
# Attribute shortcuts
self.head, self.body, self.foot = self._lists.values()
示例2: __init__
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def __init__(self, document, termsize=None, **options):
nodes.NodeVisitor.__init__(self, document)
self.document = document
self.output = ''
self.lines = ['']
self.line = 0
self.indent_width = 2
self.termsize = termsize or get_terminal_size((80,20))
self.options = options
self.references = []
self.refcount = 0
self.ctx = self.Context()
self.ctx_stack = []
self.style = self.StyleContext()
self.style_stack = []
示例3: render_symbol_html
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def render_symbol_html(self, node, code, options, prefix='symbol',
imgcls=None, alt=None):
# type: (nodes.NodeVisitor, symbolator, unicode, Dict, unicode, unicode, unicode) -> Tuple[unicode, unicode] # NOQA
format = self.builder.config.symbolator_output_format
try:
if format not in ('png', 'svg'):
raise SymbolatorError("symbolator_output_format must be one of 'png', "
"'svg', but is %r" % format)
fname, outfn = render_symbol(self, code, options, format, prefix)
except SymbolatorError as exc:
logger.warning('symbolator code %r: ' % code + str(exc))
raise nodes.SkipNode
if fname is None:
self.body.append(self.encode(code))
else:
if alt is None:
alt = node.get('alt', self.encode(code).strip())
imgcss = imgcls and 'class="%s"' % imgcls or ''
if format == 'svg':
svgtag = '''<object data="%s" type="image/svg+xml">
<p class="warning">%s</p></object>\n''' % (fname, alt)
self.body.append(svgtag)
else:
if 'align' in node:
self.body.append('<div align="%s" class="align-%s">' %
(node['align'], node['align']))
self.body.append('<img src="%s" alt="%s" %s/>\n' %
(fname, alt, imgcss))
if 'align' in node:
self.body.append('</div>\n')
raise nodes.SkipNode
示例4: html_visit_symbolator
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def html_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
render_symbol_html(self, node, node['code'], node['options'])
示例5: render_symbol_latex
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def render_symbol_latex(self, node, code, options, prefix='symbol'):
# type: (nodes.NodeVisitor, symbolator, unicode, Dict, unicode) -> None
try:
fname, outfn = render_symbol(self, code, options, 'pdf', prefix)
except SymbolatorError as exc:
logger.warning('symbolator code %r: ' % code + str(exc))
raise nodes.SkipNode
is_inline = self.is_inline(node)
if is_inline:
para_separator = ''
else:
para_separator = '\n'
if fname is not None:
post = None # type: unicode
if not is_inline and 'align' in node:
if node['align'] == 'left':
self.body.append('{')
post = '\\hspace*{\\fill}}'
elif node['align'] == 'right':
self.body.append('{\\hspace*{\\fill}')
post = '}'
self.body.append('%s\\includegraphics{%s}%s' %
(para_separator, fname, para_separator))
if post:
self.body.append(post)
raise nodes.SkipNode
示例6: latex_visit_symbolator
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def latex_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
render_symbol_latex(self, node, node['code'], node['options'])
示例7: texinfo_visit_symbolator
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def texinfo_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
render_symbol_texinfo(self, node, node['code'], node['options'])
示例8: text_visit_symbolator
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def text_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
if 'alt' in node.attributes:
self.add_text(_('[symbol: %s]') % node['alt'])
else:
self.add_text(_('[symbol]'))
raise nodes.SkipNode
示例9: man_visit_symbolator
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def man_visit_symbolator(self, node):
# type: (nodes.NodeVisitor, symbolator) -> None
if 'alt' in node.attributes:
self.body.append(_('[symbol: %s]') % node['alt'])
else:
self.body.append(_('[symbol]'))
raise nodes.SkipNode
示例10: __init__
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.table = None
示例11: __init__
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.nl = os.linesep
self.states = [[]]
self.stateindent = [0]
self.list_counter = []
self.sectionlevel = 0
self.lineblocklevel = 0
self.table = None
示例12: __init__
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def __init__(self, document, cols, rows, width):
nodes.NodeVisitor.__init__(self, document)
self.cols = cols
self.rows = rows
self.width = width
self.height = 0
示例13: __init__
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def __init__(self, document):
nodes.NodeVisitor.__init__(self, document)
self.states = [[]]
self.stateindent = [0]
self.sectionlevel = 0
self.table = None
示例14: __init__
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def __init__(self, *largs):
self.toctree = self.current = []
self.queue = []
self.text = ''
nodes.NodeVisitor.__init__(self, *largs)
示例15: render_symbol
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import NodeVisitor [as 别名]
def render_symbol(self, code, options, format, prefix='symbol'):
# type: (nodes.NodeVisitor, unicode, Dict, unicode, unicode) -> Tuple[unicode, unicode]
"""Render symbolator code into a PNG or SVG output file."""
symbolator_cmd = options.get('symbolator_cmd', self.builder.config.symbolator_cmd)
hashkey = (code + str(options) + str(symbolator_cmd) +
str(self.builder.config.symbolator_cmd_args)).encode('utf-8')
# Use name option if present otherwise fallback onto SHA-1 hash
name = options.get('name', sha1(hashkey).hexdigest())
fname = '%s-%s.%s' % (prefix, name, format)
relfn = posixpath.join(self.builder.imgpath, fname)
outfn = path.join(self.builder.outdir, self.builder.imagedir, fname)
if path.isfile(outfn):
return relfn, outfn
if (hasattr(self.builder, '_symbolator_warned_cmd') and
self.builder._symbolator_warned_cmd.get(symbolator_cmd)):
return None, None
ensuredir(path.dirname(outfn))
# Symbolator expects UTF-8 by default
if isinstance(code, text_type):
code = code.encode('utf-8')
cmd_args = [symbolator_cmd]
cmd_args.extend(self.builder.config.symbolator_cmd_args)
cmd_args.extend(['-i', '-', '-f', format, '-o', outfn])
try:
p = Popen(cmd_args, stdout=PIPE, stdin=PIPE, stderr=PIPE)
except OSError as err:
if err.errno != ENOENT: # No such file or directory
raise
logger.warning('symbolator command %r cannot be run (needed for symbolator '
'output), check the symbolator_cmd setting', symbolator_cmd)
if not hasattr(self.builder, '_symbolator_warned_cmd'):
self.builder._symbolator_warned_cmd = {}
self.builder._symbolator_warned_cmd[symbolator_cmd] = True
return None, None
try:
# Symbolator may close standard input when an error occurs,
# resulting in a broken pipe on communicate()
stdout, stderr = p.communicate(code)
except (OSError, IOError) as err:
if err.errno not in (EPIPE, EINVAL):
raise
# in this case, read the standard output and standard error streams
# directly, to get the error message(s)
stdout, stderr = p.stdout.read(), p.stderr.read()
p.wait()
if p.returncode != 0:
raise SymbolatorError('symbolator exited with error:\n[stderr]\n%s\n'
'[stdout]\n%s' % (stderr, stdout))
if not path.isfile(outfn):
raise SymbolatorError('symbolator did not produce an output file:\n[stderr]\n%s\n'
'[stdout]\n%s' % (stderr, stdout))
return relfn, outfn