我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用docutils.nodes.whitespace_normalize_name()。
def reference(self, match, lineno, anonymous=False): referencename = match.group('refname') refname = normalize_name(referencename) referencenode = nodes.reference( referencename + match.group('refend'), referencename, name=whitespace_normalize_name(referencename)) if anonymous: referencenode['anonymous'] = 1 else: referencenode['refname'] = refname self.document.note_refname(referencenode) string = match.string matchstart = match.start('whole') matchend = match.end('whole') return (string[:matchstart], [referencenode], string[matchend:], [])
def is_reference(self, reference): match = self.explicit.patterns.reference.match( whitespace_normalize_name(reference)) if not match: return None return unescape(match.group('simple') or match.group('phrase'))
def run(self): if 'align' in self.options: if isinstance(self.state, states.SubstitutionDef): # Check for align_v_values. if self.options['align'] not in self.align_v_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value ' 'for the "align" option within a substitution ' 'definition. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join(self.align_v_values))) elif self.options['align'] not in self.align_h_values: raise self.error( 'Error in "%s" directive: "%s" is not a valid value for ' 'the "align" option. Valid values for "align" are: "%s".' % (self.name, self.options['align'], '", "'.join(self.align_h_values))) messages = [] reference = directives.uri(self.arguments[0]) self.options['uri'] = reference reference_node = None if 'target' in self.options: block = states.escape2null( self.options['target']).splitlines() block = [line for line in block] target_type, data = self.state.parse_target( block, self.block_text, self.lineno) if target_type == 'refuri': reference_node = nodes.reference(refuri=data) elif target_type == 'refname': reference_node = nodes.reference( refname=fully_normalize_name(data), name=whitespace_normalize_name(data)) reference_node.indirect_reference_name = data self.state.document.note_refname(reference_node) else: # malformed target messages.append(data) # data is a system message del self.options['target'] set_classes(self.options) image_node = nodes.image(self.block_text, **self.options) self.add_name(image_node) if reference_node: reference_node += image_node return messages + [reference_node] else: return messages + [image_node]
def phrase_ref(self, before, after, rawsource, escaped, text): match = self.patterns.embedded_link.search(escaped) if match: # embedded <URI> or <alias_> text = unescape(escaped[:match.start(0)]) aliastext = match.group(2) underscore_escaped = aliastext.endswith('\x00_') aliastext = unescape(aliastext) if aliastext.endswith('_') and not (underscore_escaped or self.patterns.uri.match(aliastext)): aliastype = 'name' alias = normalize_name(aliastext[:-1]) target = nodes.target(match.group(1), refname=alias) target.indirect_reference_name = aliastext[:-1] else: aliastype = 'uri' alias = ''.join(aliastext.split()) alias = self.adjust_uri(alias) if alias.endswith(r'\_'): alias = alias[:-2] + '_' target = nodes.target(match.group(1), refuri=alias) target.referenced = 1 if not aliastext: raise ApplicationError('problem with embedded link: %r' % aliastext) if not text: text = alias else: target = None refname = normalize_name(text) reference = nodes.reference(rawsource, text, name=whitespace_normalize_name(text)) node_list = [reference] if rawsource[-2:] == '__': if target and (aliastype == 'name'): reference['refname'] = alias self.document.note_refname(reference) # self.document.note_indirect_target(target) # required? elif target and (aliastype == 'uri'): reference['refuri'] = alias else: reference['anonymous'] = 1 else: if target: target['names'].append(refname) if aliastype == 'name': reference['refname'] = alias self.document.note_indirect_target(target) self.document.note_refname(reference) else: reference['refuri'] = alias self.document.note_explicit_target(target, self.parent) # target.note_referenced_by(name=refname) node_list.append(target) else: reference['refname'] = refname self.document.note_refname(reference) return before, node_list, after, []
def phrase_ref(self, before, after, rawsource, escaped, text): match = self.patterns.embedded_link.search(escaped) if match: # embedded <URI> or <alias_> text = unescape(escaped[:match.start(0)]) aliastext = match.group(2) underscore_escaped = aliastext.endswith('\x00_') aliastext = unescape(aliastext) if aliastext.endswith('_') and not (underscore_escaped or self.patterns.uri.match(aliastext)): aliastype = 'name' alias = normalize_name(aliastext[:-1]) target = nodes.target(match.group(1), refname=alias) target.indirect_reference_name = aliastext[:-1] else: aliastype = 'uri' alias_parts = split_escaped_whitespace(match.group(2)) alias = ' '.join(''.join(unescape(part).split()) for part in alias_parts) alias = self.adjust_uri(alias) if alias.endswith(r'\_'): alias = alias[:-2] + '_' target = nodes.target(match.group(1), refuri=alias) target.referenced = 1 if not aliastext: raise ApplicationError('problem with embedded link: %r' % aliastext) if not text: text = alias else: target = None refname = normalize_name(text) reference = nodes.reference(rawsource, text, name=whitespace_normalize_name(text)) node_list = [reference] if rawsource[-2:] == '__': if target and (aliastype == 'name'): reference['refname'] = alias self.document.note_refname(reference) # self.document.note_indirect_target(target) # required? elif target and (aliastype == 'uri'): reference['refuri'] = alias else: reference['anonymous'] = 1 else: if target: target['names'].append(refname) if aliastype == 'name': reference['refname'] = alias self.document.note_indirect_target(target) self.document.note_refname(reference) else: reference['refuri'] = alias self.document.note_explicit_target(target, self.parent) # target.note_referenced_by(name=refname) node_list.append(target) else: reference['refname'] = refname self.document.note_refname(reference) return before, node_list, after, []
def phrase_ref(self, before, after, rawsource, escaped, text): match = self.patterns.embedded_link.search(escaped) if match: # embedded <URI> or <alias_> text = unescape(escaped[:match.start(0)]) aliastext = unescape(match.group(2), restore_backslashes=True) if aliastext.endswith('_') and not (aliastext.endswith(r'\_') or self.patterns.uri.match(aliastext)): aliastype = 'name' alias = normalize_name(aliastext[:-1]) target = nodes.target(match.group(1), refname=alias) target.indirect_reference_name = aliastext[:-1] else: aliastype = 'uri' alias = ''.join(aliastext.split()) alias = self.adjust_uri(alias) if alias.endswith(r'\_'): alias = alias[:-2] + '_' target = nodes.target(match.group(1), refuri=alias) target.referenced = 1 if not aliastext: raise ApplicationError('problem with embedded link: %r' % aliastext) if not text: text = alias else: target = None refname = normalize_name(text) reference = nodes.reference(rawsource, text, name=whitespace_normalize_name(text)) node_list = [reference] if rawsource[-2:] == '__': if target and (aliastype == 'name'): reference['refname'] = alias self.document.note_refname(reference) # self.document.note_indirect_target(target) # required? elif target and (aliastype == 'uri'): reference['refuri'] = alias else: reference['anonymous'] = 1 else: if target: target['names'].append(refname) if aliastype == 'name': reference['refname'] = alias self.document.note_indirect_target(target) self.document.note_refname(reference) else: reference['refuri'] = alias self.document.note_explicit_target(target, self.parent) # target.note_referenced_by(name=refname) node_list.append(target) else: reference['refname'] = refname self.document.note_refname(reference) return before, node_list, after, []