我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用docutils.nodes.SkipNode()。
def visit_footnote_reference(self, node): num = node.astext().strip() try: footnode, used = self.footnotestack[-1][num] except (KeyError, IndexError): raise nodes.SkipNode # if a footnote has been inserted once, it shouldn't be repeated # by the next reference if used: if self.table or self.in_term or self.in_title: self.body.append('\\protect\\footnotemark[%s]' % num) else: self.body.append('\\footnotemark[%s]' % num) elif self.footnote_restricted: self.footnotestack[-1][num][1] = True self.body.append('\\protect\\footnotemark[%s]' % num) self.pending_footnotes.append(footnode) else: self.footnotestack[-1][num][1] = True footnode.walkabout(self) raise nodes.SkipChildren
def visit_title(self, node): if isinstance(node.parent, nodes.topic): self.body.append(self.defs['topic-title'][0]) elif isinstance(node.parent, nodes.sidebar): self.body.append(self.defs['sidebar-title'][0]) elif isinstance(node.parent, nodes.admonition): self.body.append('.IP "') elif self.section_level == 0: self._docinfo['title'] = node.astext() # document title for .TH self._docinfo['title_upper'] = node.astext().upper() raise nodes.SkipNode elif self.section_level == 1: self.body.append('.SH %s\n' % self.deunicode(node.astext().upper())) raise nodes.SkipNode else: self.body.append('.SS ')
def visit_docinfo(self, node): for info in node.children: if info.tagname == 'field': name, body = info.children name = name.astext() value = body.astext() if name in ('date', 'eventdate'): value = get_date(value) self.article.set_metadata(name, value) else: if info.tagname.lower() in ('date', 'eventdate'): value = get_date(info.astext()) else: value = info.astext() self.article.set_metadata(info.tagname.lower(), value) self.result.append(node.realsource) self.result.append('') raise SkipNode()
def render_html(self, node, text, options, imgcls=None): try: options['format'] = self.builder.config.aafig_format['html'] fname, outfn, id, extra = render_aafigure(self, text, options) except AafigError, exc: self.builder.warn('aafigure error: ' + str(exc)) raise nodes.SkipNode self.body.append(self.starttag(node, 'p', CLASS='aafigure')) if fname is None: self.body.append(self.encode(text)) else: imgcss = imgcls and 'class="%s"' % imgcls or '' if options['format'].lower() == 'svg': self.body.append('<object type="image/svg+xml" data="%s" %s %s />' % (fname, extra, imgcss)) else: self.body.append('<img src="%s" alt="%s" %s/>\n' % (fname, self.encode(text).strip(), imgcss)) self.body.append('</p>\n') raise nodes.SkipNode
def html_visit(self, node): #print node.attributes #merge_defaults(node['options'], self) #render_html(self, node, node['text'], node['options']) #return options = node['options'].copy() #merge_defaults(options, self) try: options['format'] = self.builder.config.aafig_format['html'] fname, outfn, id, extra = render_aafigure(self, node.rawsource, options) except AafigError, exc: self.builder.warn('aafigure error: ' + str(exc)) raise nodes.SkipNode image_node = node[0] image_node['src'] = fname # FIXME: no lo está tomando =/ # TODO: improve image_node['alt']
def html_visit_math(self, node): try: fname, depth = render_math(self, '$'+node['latex']+'$') except MathExtError as exc: msg = text_type(exc) sm = nodes.system_message(msg, type='WARNING', level=2, backrefs=[], source=node['latex']) sm.walkabout(self) self.builder.warn('display latex %r: ' % node['latex'] + msg) raise nodes.SkipNode if fname is None: # something failed -- use text-only as a bad substitute self.body.append('<span class="math">%s</span>' % self.encode(node['latex']).strip()) else: c = ('<img class="math" src="%s"' % fname) + get_tooltip(self, node) if depth is not None: c += ' style="vertical-align: %dpx"' % (-depth) self.body.append(c + '/>') raise nodes.SkipNode
def html_visit_displaymath(self, node): if node['nowrap']: latex = node['latex'] else: latex = wrap_displaymath(node['latex'], None) try: fname, depth = render_math(self, latex) except MathExtError as exc: sm = nodes.system_message(str(exc), type='WARNING', level=2, backrefs=[], source=node['latex']) sm.walkabout(self) self.builder.warn('inline latex %r: ' % node['latex'] + str(exc)) raise nodes.SkipNode self.body.append(self.starttag(node, 'div', CLASS='math')) self.body.append('<p>') if node['number']: self.body.append('<span class="eqno">(%s)</span>' % node['number']) if fname is None: # something failed -- use text-only as a bad substitute self.body.append('<span class="math">%s</span></p>\n</div>' % self.encode(node['latex']).strip()) else: self.body.append(('<img src="%s"' % fname) + get_tooltip(self, node) + '/></p>\n</div>') raise nodes.SkipNode
def render_dot_latex(self, node, code, options, prefix='graphviz'): try: fname, outfn = render_dot(self, code, options, 'pdf', prefix) except GraphvizError as exc: self.builder.warn('dot code %r: ' % code + str(exc)) raise nodes.SkipNode inline = node.get('inline', False) if inline: para_separator = '' else: para_separator = '\n' if fname is not None: self.body.append('%s\\includegraphics{%s}%s' % (para_separator, fname, para_separator)) raise nodes.SkipNode
def visit_productionlist(self, node): # self.new_state() # names = [] # for production in node: # names.append(production['tokenname']) # maxlen = max(len(name) for name in names) # lastname = None # for production in node: # if production['tokenname']: # self.add_text(production['tokenname'].ljust(maxlen) + ' ::=') # lastname = production['tokenname'] # elif lastname is not None: # self.add_text('%s ' % (' ' * len(lastname))) # self.add_text(production.astext() + self.nl) # self.end_state(wrap=False) # raise nodes.SkipNode self.body.append('PRODUCTIONLIST:')
def visit_rubric(self, node): if len(node.children) == 1 and node.children[0].astext() in \ ('Footnotes', _('Footnotes')): raise nodes.SkipNode self.body.append('\\paragraph{') self.context.append('}\n') self.in_title = 1
def visit_docinfo(self, node): raise nodes.SkipNode # text handling
def visit_title(self, node): if isinstance(node.parent, nodes.Admonition): self.add_text(node.astext()+': ') raise nodes.SkipNode self.new_state(0)
def visit_footnote(self, node): self.new_state(0) label_node = node.next_node() if not isinstance(label_node, nodes.label): raise nodes.SkipNode anchor = node['ids'][0] self.add_text('|') if self.can_anchor: self.add_text('{anchor:%s}' % anchor) self.add_text('%s|' % label_node.astext())
def visit_field_name(self, node): if self._in_docinfo: self._field_name = node.astext() raise nodes.SkipNode else: self.body.append(self.defs['field_name'][0])
def visit_label(self, node): # footnote and citation if (isinstance(node.parent, nodes.footnote) or isinstance(node.parent, nodes.citation)): raise nodes.SkipNode self.document.reporter.warning('"unsupported "label"', base_node=node) self.body.append('[')
def depart_subtitle(self, node): # document subtitle calls SkipNode self.body.append(self.defs['strong'][1]+'\n.PP\n')
def visit_system_message(self, node): # TODO add report_level #if node['level'] < self.document.reporter['writer'].report_level: # Level is too low to display: # raise nodes.SkipNode attr = {} backref_text = '' if node.hasattr('id'): attr['name'] = node['id'] if node.hasattr('line'): line = ', line %s' % node['line'] else: line = '' self.body.append('.IP "System Message: %s/%s (%s:%s)"\n' % (node['type'], node['level'], node['source'], line))
def ignore_node(self, node): # ignore nodes that are never complex (can contain only inline nodes) raise nodes.SkipNode # Paragraphs and text
def visit_raw(self, node): if 'xml' not in node.get('format', '').split(): # skip other raw content? # raise nodes.SkipNode self.default_visit(node) return # wrap in <raw> element self.default_visit(node) # or not? xml_string = node.astext() self.output.append(xml_string) self.default_departure(node) # or not? # Check validity of raw XML: if isinstance(xml_string, unicode) and sys.version_info < (3,): xml_string = xml_string.encode('utf8') try: self.xmlparser.parse(StringIO(xml_string)) except xml.sax._exceptions.SAXParseException, error: col_num = self.the_handle.locator.getColumnNumber() line_num = self.the_handle.locator.getLineNumber() srcline = node.line if not isinstance(node.parent, nodes.TextElement): srcline += 2 # directive content start line msg = 'Invalid raw XML in column %d, line offset %d:\n%s' % ( col_num, line_num, node.astext()) self.warn(msg, source=node.source, line=srcline+line_num-1) raise nodes.SkipNode # content already processed
def visit_docinfo_item(self, node, name): if name == 'author': self.pdfauthor.append(self.attval(node.astext())) if self.use_latex_docinfo: if name in ('author', 'organization', 'contact', 'address'): # We attach these to the last author. If any of them precedes # the first author, put them in a separate "author" group # (in lack of better semantics). if name == 'author' or not self.author_stack: self.author_stack.append([]) if name == 'address': # newlines are meaningful self.insert_newline = True text = self.encode(node.astext()) self.insert_newline = False else: text = self.attval(node.astext()) self.author_stack[-1].append(text) raise nodes.SkipNode elif name == 'date': self.date.append(self.attval(node.astext())) raise nodes.SkipNode self.out.append('\\textbf{%s}: &\n\t' % self.language_label(name)) if name == 'address': self.insert_newline = True self.out.append('{\\raggedright\n') self.context.append(' } \\\\\n') else: self.context.append(' \\\\\n')
def label_delim(self, node, bracket, superscript): if isinstance(node.parent, nodes.footnote): raise nodes.SkipNode else: assert isinstance(node.parent, nodes.citation) if not self._use_latex_citations: self.out.append(bracket)
def visit_raw(self, node): if not 'latex' in node.get('format', '').split(): raise nodes.SkipNode if not self.is_inline(node): self.out.append('\n') if node['classes']: self.visit_inline(node) # append "as-is" skipping any LaTeX-encoding self.verbatim = True
def visit_label(self, node): raise nodes.SkipNode # XXX: option list could use some better styling
def html_visit_displaymath(self, node): self.body.append(self.starttag(node, 'div', CLASS='math')) if node['nowrap']: self.body.append(self.builder.config.mathjax_display[0] + \ node['latex'] +\ self.builder.config.mathjax_display[1]) self.body.append('</div>') raise nodes.SkipNode parts = [prt for prt in node['latex'].split('\n\n') if prt.strip() != ''] for i, part in enumerate(parts): part = self.encode(part) if i == 0: # necessary to e.g. set the id property correctly if node['number']: self.body.append('<span class="eqno">(%s)</span>' % node['number']) if '&' in part or '\\\\' in part: self.body.append(self.builder.config.mathjax_display[0] + \ '\\begin{split}' + part + '\\end{split}' + \ self.builder.config.mathjax_display[1]) else: self.body.append(self.builder.config.mathjax_display[0] + part + \ self.builder.config.mathjax_display[1]) self.body.append('</div>\n') raise nodes.SkipNode
def visit_title(self, node): if not self._main_title_visited: self.article['title'] = node.astext() self.article['title_source'] = node.realsource self._main_title_visited = True self.result.append(node.realsource) self.result.append('') raise SkipNode()
def visit_enumerated_list(self, node): self.result.append(node.rawsource) self.result.append('') raise SkipNode()
def visit_block_quote(self, node): self.result.append(node.rawsource) self.result.append('') raise SkipNode()
def visit_line_block(self, node): self.result.append(node.rawsource) self.result.append('') raise SkipNode()
def visit_substitution_definition(self, node): self.result.append(node.rawsource) raise SkipNode()
def visit_target(self, node): self.result.append(node.rawsource) raise SkipNode()
def visit_reference(self, node): self.result.append(node.rawsource) raise SkipNode()