Python docutils.nodes.NodeVisitor() Examples
The following are 30
code examples of docutils.nodes.NodeVisitor().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
docutils.nodes
, or try the search function
.
Example #1
Source File: ansi.py From python-rst2ansi with MIT License | 6 votes |
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 = []
Example #2
Source File: doctree2md.py From sphinx-markdown-builder with MIT License | 6 votes |
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()
Example #3
Source File: textwriter.py From bash-lambda-layer with MIT License | 5 votes |
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
Example #4
Source File: table.py From python-rst2ansi with MIT License | 5 votes |
def __init__(self, document): nodes.NodeVisitor.__init__(self, document) self.level = 0 self.widths = [] self.heights = [] self.rows = 0
Example #5
Source File: table.py From python-rst2ansi with MIT License | 5 votes |
def __init__(self, document, cols, rows, width): nodes.NodeVisitor.__init__(self, document) self.cols = cols self.rows = rows self.width = width self.height = 0
Example #6
Source File: rst2txt.py From releases with Apache License 2.0 | 5 votes |
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
Example #7
Source File: table.py From python-rst2ansi with MIT License | 5 votes |
def __init__(self, props, document, **options): nodes.NodeVisitor.__init__(self, document) self.props = props self.level = 0 self.line = 0 self.cursor = 0 self.col = 0 self.row = 0 self.nb_rows = 0 self.options = options
Example #8
Source File: textwriter.py From aws-extender with MIT License | 5 votes |
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
Example #9
Source File: TextWriter.py From redeem with GNU General Public License v3.0 | 5 votes |
def __init__(self, document): nodes.NodeVisitor.__init__(self, document) self.states = [[]] self.stateindent = [0] self.sectionlevel = 0 self.table = None
Example #10
Source File: rst.py From Tickeys-linux with MIT License | 5 votes |
def __init__(self, *largs): self.toctree = self.current = [] self.queue = [] self.text = '' nodes.NodeVisitor.__init__(self, *largs)
Example #11
Source File: textwriter.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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
Example #12
Source File: rst.py From Tickeys-linux with MIT License | 5 votes |
def __init__(self, root, *largs): self.root = root self.title = None self.current_list = [] self.current = None self.idx_list = None self.text = '' self.text_have_anchor = False self.section = 0 self.do_strip_text = False nodes.NodeVisitor.__init__(self, *largs)
Example #13
Source File: textwriter.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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
Example #14
Source File: rst.py From Tickeys-linux with MIT License | 5 votes |
def __init__(self, *largs): self.toctree = self.current = [] self.queue = [] self.text = '' nodes.NodeVisitor.__init__(self, *largs)
Example #15
Source File: rst.py From Tickeys-linux with MIT License | 5 votes |
def __init__(self, root, *largs): self.root = root self.title = None self.current_list = [] self.current = None self.idx_list = None self.text = '' self.text_have_anchor = False self.section = 0 self.do_strip_text = False nodes.NodeVisitor.__init__(self, *largs)
Example #16
Source File: textwriter.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
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
Example #17
Source File: textwriter.py From deepWordBug with Apache License 2.0 | 5 votes |
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
Example #18
Source File: textwriter.py From faces with GNU General Public License v2.0 | 5 votes |
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
Example #19
Source File: textwriter.py From faces with GNU General Public License v2.0 | 5 votes |
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
Example #20
Source File: symbolator_sphinx.py From symbolator with MIT License | 5 votes |
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
Example #21
Source File: symbolator_sphinx.py From symbolator with MIT License | 5 votes |
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
Example #22
Source File: symbolator_sphinx.py From symbolator with MIT License | 5 votes |
def texinfo_visit_symbolator(self, node): # type: (nodes.NodeVisitor, symbolator) -> None render_symbol_texinfo(self, node, node['code'], node['options'])
Example #23
Source File: symbolator_sphinx.py From symbolator with MIT License | 5 votes |
def latex_visit_symbolator(self, node): # type: (nodes.NodeVisitor, symbolator) -> None render_symbol_latex(self, node, node['code'], node['options'])
Example #24
Source File: symbolator_sphinx.py From symbolator with MIT License | 5 votes |
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
Example #25
Source File: symbolator_sphinx.py From symbolator with MIT License | 5 votes |
def html_visit_symbolator(self, node): # type: (nodes.NodeVisitor, symbolator) -> None render_symbol_html(self, node, node['code'], node['options'])
Example #26
Source File: symbolator_sphinx.py From symbolator with MIT License | 5 votes |
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
Example #27
Source File: _html_base.py From aws-builders-fair-projects with Apache License 2.0 | 4 votes |
def __init__(self, document): nodes.NodeVisitor.__init__(self, document) self.settings = settings = document.settings lcode = settings.language_code self.language = languages.get_language(lcode, document.reporter) self.meta = [self.generator % docutils.__version__] self.head_prefix = [] self.html_prolog = [] if settings.xml_declaration: self.head_prefix.append(self.xml_declaration % settings.output_encoding) # self.content_type = "" # encoding not interpolated: self.html_prolog.append(self.xml_declaration) self.head = self.meta[:] self.stylesheet = [self.stylesheet_call(path) for path in utils.get_stylesheet_list(settings)] self.body_prefix = ['</head>\n<body>\n'] # document title, subtitle display self.body_pre_docinfo = [] # author, date, etc. self.docinfo = [] self.body = [] self.fragment = [] self.body_suffix = ['</body>\n</html>\n'] self.section_level = 0 self.initial_header_level = int(settings.initial_header_level) self.math_output = settings.math_output.split() self.math_output_options = self.math_output[1:] self.math_output = self.math_output[0].lower() self.context = [] """Heterogeneous stack. Used by visit_* and depart_* functions in conjunction with the tree traversal. Make sure that the pops correspond to the pushes.""" self.topic_classes = [] # TODO: replace with self_in_contents self.colspecs = [] self.compact_p = True self.compact_simple = False self.compact_field_list = False self.in_docinfo = False self.in_sidebar = False self.in_footnote_list = False self.title = [] self.subtitle = [] self.header = [] self.footer = [] self.html_head = [self.content_type] # charset not interpolated self.html_title = [] self.html_subtitle = [] self.html_body = [] self.in_document_title = 0 # len(self.body) or 0 self.in_mailto = False self.author_in_authors = False # for html4css1 self.math_header = []
Example #28
Source File: symbolator_sphinx.py From symbolator with MIT License | 4 votes |
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
Example #29
Source File: table.py From python-rst2ansi with MIT License | 4 votes |
def __init__(self, props, document, **options): nodes.NodeVisitor.__init__(self, document) self.props = props self.level = 0 self.lines = [''] self.line = 0 self.cursor = 0 self.col = 0 self.row = 0 self.nb_rows = 0 self.options = options def unicode_intersection(char, next): switch = { ('─', '│'): '┬', ('┐', '│'): '┐', ('┘', '│'): '┤', ('┘', '─'): '┴', ('┴', '│'): '┼', ('│', '─'): '├', ('┤', '─'): '┼', (' ', '─'): '┘', ('└', '─'): '└', ('═', '│'): '╤', ('╕', '│'): '╕', ('╛', '│'): '╡', ('╛', '═'): '╧', ('╧', '│'): '╪', ('│', '═'): '╞', ('╡', '═'): '╪', (' ', '═'): '╛', ('╘', '═'): '╘', } return switch[(u(char), u(next))] if options.get('unicode', False): self.char_single_rule = '─' self.char_double_rule = '═' self.char_vertical_rule = '│' self.get_intersection = unicode_intersection self.top_left = '┌' self.top_right = '┐' self.bottom_left = '╘' else: self.char_single_rule = '-' self.char_double_rule = '=' self.char_vertical_rule = '|' self.get_intersection = lambda *args: '+' self.top_left = self.bottom_left = self.top_right = '+'
Example #30
Source File: _html_base.py From aws-extender with MIT License | 4 votes |
def __init__(self, document): nodes.NodeVisitor.__init__(self, document) self.settings = settings = document.settings lcode = settings.language_code self.language = languages.get_language(lcode, document.reporter) self.meta = [self.generator % docutils.__version__] self.head_prefix = [] self.html_prolog = [] if settings.xml_declaration: self.head_prefix.append(self.xml_declaration % settings.output_encoding) # self.content_type = "" # encoding not interpolated: self.html_prolog.append(self.xml_declaration) self.head = self.meta[:] self.stylesheet = [self.stylesheet_call(path) for path in utils.get_stylesheet_list(settings)] self.body_prefix = ['</head>\n<body>\n'] # document title, subtitle display self.body_pre_docinfo = [] # author, date, etc. self.docinfo = [] self.body = [] self.fragment = [] self.body_suffix = ['</body>\n</html>\n'] self.section_level = 0 self.initial_header_level = int(settings.initial_header_level) self.math_output = settings.math_output.split() self.math_output_options = self.math_output[1:] self.math_output = self.math_output[0].lower() self.context = [] """Heterogeneous stack. Used by visit_* and depart_* functions in conjunction with the tree traversal. Make sure that the pops correspond to the pushes.""" self.topic_classes = [] # TODO: replace with self_in_contents self.colspecs = [] self.compact_p = True self.compact_simple = False self.compact_field_list = False self.in_docinfo = False self.in_sidebar = False self.in_footnote_list = False self.title = [] self.subtitle = [] self.header = [] self.footer = [] self.html_head = [self.content_type] # charset not interpolated self.html_title = [] self.html_subtitle = [] self.html_body = [] self.in_document_title = 0 # len(self.body) or 0 self.in_mailto = False self.author_in_authors = False # for html4css1 self.math_header = []