Exemple #1
0
 def parsemeta(self, match):
     name = self.parse_field_marker(match)
     name = utils.unescape(utils.escape2null(name))
     indented, indent, line_offset, blank_finish = \
           self.state_machine.get_first_known_indented(match.end())
     node = self.meta()
     pending = nodes.pending(components.Filter,
                             {'component': 'writer',
                              'format': 'html',
                              'nodes': [node]})
     node['content'] = utils.unescape(utils.escape2null(
                                         ' '.join(indented)))
     if not indented:
         line = self.state_machine.line
         msg = self.reporter.info(
               'No content for meta tag "%s".' % name,
               nodes.literal_block(line, line))
         return msg, blank_finish
     tokens = name.split()
     try:
         attname, val = utils.extract_name_value(tokens[0])[0]
         node[attname.lower()] = val
     except utils.NameValueError:
         node['name'] = tokens[0]
     for token in tokens[1:]:
         try:
             attname, val = utils.extract_name_value(token)[0]
             node[attname.lower()] = val
         except utils.NameValueError, detail:
             line = self.state_machine.line
             msg = self.reporter.error(
                   'Error parsing meta tag attribute "%s": %s.'
                   % (token, detail), nodes.literal_block(line, line))
             return msg, blank_finish
Exemple #2
0
 def _process_node(self, node):
     # Avoid literals etc
     if not isinstance(node.parent, nodes.paragraph):
         return
     in_str = node.rawsource
     processed = txt_dollars_to_math(in_str)
     if MATH_MARKER not in processed:
         return
     parts = processed.split(MATH_MARKER)
     new_nodes = []
     for i, part in enumerate(parts):
         with_nulls = escape2null(part)
         to_backslashes = unescape(with_nulls, restore_backslashes=True)
         if part == '':
             continue
         if i % 2:  # See sphinx.ext.mathbase
             if SPHINX_ge_18:
                 new_node = math()
                 new_node += nodes.Text(to_backslashes, to_backslashes)
             else:
                 new_node = math(latex=to_backslashes)
         else:
             new_node = nodes.Text(unescape(with_nulls), to_backslashes)
         new_node.parent = node.parent
         new_nodes.append(new_node)
     # Put new nodes into parent's list of children
     new_children = []
     for child in node.parent.children:
         if not child is node:
             new_children.append(child)
         else:
             new_children += new_nodes
     node.parent.children = new_children
    def parse(
        self, text: str, lineno: int, memo: Any, parent: Any
    ) -> Tuple[List[nodes.Node], List[nodes.system_message]]:
        """
        Return 2 lists: nodes (text and inline elements), and system_messages.

        1. Using `self.patterns.initial`, a pattern which matches start-strings
           (emphasis, strong, interpreted, phrase reference, literal,
           substitution reference, and inline target) and complete constructs
           (simple reference, footnote reference), search for a candidate.
        2. When one is found, check for validity (e.g., not a quoted '*' character).
        3. If valid, search for the corresponding end string if applicable, and
           check it for validity.
        4. If not found or invalid, generate a warning and ignore the start-string.
        5. Implicit inline markup (e.g. standalone URIs) is found last.
        """
        self.reporter = memo.reporter
        self.document = memo.document
        self.language = memo.language
        self.parent = parent
        remaining = escape2null(text)
        processed = []
        unprocessed = []
        messages = []
        current_character = 0
        while remaining:
            match = self.patterns.initial.search(remaining)
            if match:
                groups = match.groupdict()
                method = self.dispatch_methods[
                    groups["start"]
                    or groups["backquote"]
                    or groups["refend"]
                    or groups["fnend"]
                ]
                before, inlines, remaining, sysmessages = method(match, lineno)
                start_character = current_character + len(before)
                end_character = current_character = len(text) - len(remaining)
                inlines = self.record_source_data(
                    lineno=lineno,
                    text=text,
                    start_character=start_character,
                    end_character=end_character,
                    method=method,
                    inlines=inlines,
                )
                unprocessed.append(before)
                messages += sysmessages
                if inlines:
                    processed += self.implicit_inline("".join(unprocessed), lineno)
                    processed += inlines
                    unprocessed = []
            else:
                break
        remaining = "".join(unprocessed) + remaining
        if remaining:
            processed += self.implicit_inline(remaining, lineno)
        return processed, messages
Exemple #4
0
 def parsemeta(self, match):
     name = self.parse_field_marker(match)
     name = utils.unescape(utils.escape2null(name))
     (
         indented,
         indent,
         line_offset,
         blank_finish,
     ) = self.state_machine.get_first_known_indented(match.end())
     node = self.meta()
     pending = nodes.pending(
         components.Filter,
         {
             "component": "writer",
             "format": "html",
             "nodes": [node]
         },
     )
     node["content"] = utils.unescape(utils.escape2null(" ".join(indented)))
     if not indented:
         line = self.state_machine.line
         msg = self.reporter.info('No content for meta tag "%s".' % name,
                                  nodes.literal_block(line, line))
         return msg, blank_finish
     tokens = name.split()
     try:
         attname, val = utils.extract_name_value(tokens[0])[0]
         node[attname.lower()] = val
     except utils.NameValueError:
         node["name"] = tokens[0]
     for token in tokens[1:]:
         try:
             attname, val = utils.extract_name_value(token)[0]
             node[attname.lower()] = val
         except utils.NameValueError as detail:
             line = self.state_machine.line
             msg = self.reporter.error(
                 'Error parsing meta tag attribute "%s": %s.' %
                 (token, detail),
                 nodes.literal_block(line, line),
             )
             return msg, blank_finish
     self.document.note_pending(pending)
     return pending, blank_finish
Exemple #5
0
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri
Exemple #6
0
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri
Exemple #7
0
    def parse(self, text, lineno, memo, parent):
        # Needs to be refactored for nested inline markup.
        # Add nested_parse() method?
        """
        Return 2 lists: nodes (text and inline elements), and system_messages.

        Using `self.patterns.initial`, a pattern which matches start-strings
        (emphasis, strong, interpreted, phrase reference, literal,
        substitution reference, and inline target) and complete constructs
        (simple reference, footnote reference), search for a candidate.  When
        one is found, check for validity (e.g., not a quoted '*' character).
        If valid, search for the corresponding end string if applicable, and
        check it for validity.  If not found or invalid, generate a warning
        and ignore the start-string.  Implicit inline markup (e.g. standalone
        URIs) is found last.
        """
        self.reporter = memo.reporter
        self.document = memo.document
        self.language = memo.language
        self.parent = parent
        pattern_search = self.patterns.initial.search
        dispatch = self.dispatch
        remaining = escape2null(text)
        processed = []
        unprocessed = []
        messages = []
        while remaining:
            match = pattern_search(remaining)
            if match:
                groups = match.groupdict()
                method = dispatch[groups['start'] or groups['backquote']
                                  or groups['refend'] or groups['fnend']]
                before, inlines, remaining, sysmessages = method(self, match,
                                                                 lineno)
                unprocessed.append(before)
                messages += sysmessages
                if inlines:
                    processed += self.implicit_inline(''.join(unprocessed),
                                                      lineno)
                    processed += inlines
                    unprocessed = []
            else:
                break
        remaining = ''.join(unprocessed) + remaining
        if remaining:
            processed += self.implicit_inline(remaining, lineno)
        return processed, messages