def make_node(self):
     parser = self.parser
     caret = parser.caret
     endindex = self.is_element(parser)
     if endindex is None:
         return None
     pos = parser.copy_pos()
     match = RE.search(parser.text, caret+1)
     tagname = parser.text[parser.caret+1:match.end(0)-1].lower()
     if tagname in VOID_ELEMENT:
         node = Void(tagname)
     elif tagname in RAWTEXT_ELEMENT:
         node = RawText(tagname)
     else:
         node = Element(tagname)
     parser.update(match.end(0)-1)
     if parser.text[parser.caret] is '>':
         parser.update(parser.caret+1)
     elif parser.text[parser.caret] is '/':
         parser.update(endindex+1)
     else:
         self.read_attributes(parser, node, endindex, tagname)
     if isinstance(node, Void):
         return [node]
     if isinstance(node, RawText):
         node.data = self.get_raw_text(parser, tagname, pos)
         return [node]
     node.pos = pos
     return node
Example #2
0
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     if parser.text[caret:caret + 2] == '\\\\':
         parser.update(parser.caret + 2)
         return Void('br')
     return None
    def make_node(self):
        parser = self.parser
        if parser.text[parser.caret:parser.caret + 3] == '\n%%':
            return None
        index = parser.text.find('\n', parser.caret + 1)
        while index != -1:
            if parser.text[index - 1] == '\\':
                index = parser.text.find('\n', index + 1)
            else:
                break
        if index == -1:
            parser.update(parser.caret + 1)
            return None

        pos = parser.compute(parser.caret + 1)
        content = parser.text[parser.caret:index].strip()
        parser.update(index)

        flag = 'set_delayed'
        index = content.find(':=')
        if index == -1:
            flag = 'set'
            index = content.find('=')
            if index == -1:
                self.msg('E100', pos)
                node = Void('macro', {'flag': 'failed'})
                return node

        name = content[:index].strip()
        if name[0] == '\\':
            name, arg = self.get_function(pos, name)

        if flag == 'set':
            value = content[index + 1:]
        else:
            value = content[index + 2:]
        value = re.sub(RE, ' ', value.strip().replace('\\\n', ''))

        node = Void('macro')
        node['flag'] = flag
        node['name'] = name
        node['value'] = value
        if name[0] == '\\':
            node['arg'] = arg
        return node
 def is_block_reference(self, parser):
     """Checks to see if the parser is placed at a block
     reference. If it is, then it returns the node that will hold
     the information. The returned node will have two properties:
     pos and line_end. Make sure to delete them before returning
     the node. """
     empty = 0
     index = parser.caret
     char = parser.text[index : index + 1]
     while char in " \t":
         if char == " ":
             empty += 1
         else:
             empty += 4
         index += 1
         char = parser.text[index : index + 1]
     if empty > 3 or char not in "[{":
         return None
     parser.update(index)
     ref_begin = index + 1
     if char == "[":
         closing_char = "]"
         tagname = "address_reference"
     else:
         closing_char = "}"
         tagname = "attribute_reference"
     line_end = parser.text.find("\n", ref_begin)
     if line_end == -1:
         line_end = parser.end
         self.msg("E100", parser.compute(parser.end))
     index = parser.text.rfind(closing_char, ref_begin, line_end)
     if index == -1:
         return None
     if parser.text[index + 1] != ":":
         return None
     node = Void(tagname)
     node.line_end = line_end
     node["_reference_name"] = parser.text[ref_begin:index]
     node["_pos"] = parser.copy_pos()
     parser.update(index + 2)
     parser["EmptyNP"].skip_space(parser)
     return node
 def is_block_reference(self, parser):
     """Checks to see if the parser is placed at a block
     reference. If it is, then it returns the node that will hold
     the information. The returned node will have two properties:
     pos and line_end. Make sure to delete them before returning
     the node. """
     empty = 0
     index = parser.caret
     char = parser.text[index:index+1]
     while char in ' \t':
         if char == ' ':
             empty += 1
         else:
             empty += 4
         index += 1
         char = parser.text[index:index+1]
     if empty > 3 or char not in '[{':
         return None
     parser.update(index)
     ref_begin = index + 1
     if char == '[':
         closing_char = ']'
         tagname = 'address_reference'
     else:
         closing_char = '}'
         tagname = 'attribute_reference'
     line_end = parser.text.find('\n', ref_begin)
     if line_end == -1:
         line_end = parser.end
         self.msg('E100', parser.compute(parser.end))
     index = parser.text.rfind(closing_char, ref_begin, line_end)
     if index == -1:
         return None
     if parser.text[index+1] != ':':
         return None
     node = Void(tagname)
     node.line_end = line_end
     node['_reference_name'] = parser.text[ref_begin:index]
     node['_pos'] = parser.copy_pos()
     parser.update(index+2)
     parser['EmptyNP'].skip_space(parser)
     return node
    def make_node(self):
        parser = self.parser
        if parser.text[parser.caret] not in "![":
            return None
        if parser.text[parser.caret] == "!":
            tagtype = "img"
            if parser.text[parser.caret + 1 : parser.caret + 2] != "[":
                return None
            ref_begin = parser.caret + 2
        else:
            tagtype = "a"
            ref_begin = parser.caret + 1

        parity, ref_end = check_parity(parser, ref_begin)
        if parity != 0:
            return None

        if tagtype == "img":
            node = Void("reference")
            node["alt"] = parser.text[ref_begin:ref_end]
            node["_pos"] = parser.copy_pos()
            parser.update(ref_end + 1)
            char = parser.text[ref_end + 1 : ref_end + 2]
            if char == "(":
                node.name = "img"
                self.get_inline_info(parser, node)
            elif char in "[ ":
                get_inline_id(parser, node)
            else:
                parser.update(ref_end + 1)
            parser["ElementNP"].get_attribute_list(parser, node)
            return node
        node = Element("reference")
        node.pos = parser.copy_pos()
        node["_pos"] = parser.copy_pos()
        node.ref_end = ref_end
        parser.update(parser.caret + 1)
        return node
Example #7
0
 def make_node(self):
     """Returns an `Element` node. """
     parser = self.parser
     caret = parser.caret
     tmp = self.is_element(parser)
     if tmp is None:
         return None
     endindex = tmp[0]
     shift = tmp[1]
     pos = parser.copy_pos()
     match = RE.search(parser.text, caret+shift)
     tagname = parser.text[parser.caret+shift:match.end(0)-1].lower()
     if tagname == '' or tagname[0] in '.#!@':
         tagname = 'span'
         parser.update(caret+3)
     else:
         parser.update(match.end(0)-1)
     if tagname in VOID_ELEMENT:
         node = Void(tagname)
     elif tagname in RAWTEXT_ELEMENT:
         node = RawText(tagname)
     else:
         node = Element(tagname)
     if parser.text[parser.caret] == END_CHAR[shift]:
         parser.update(parser.caret+1)
     elif parser.text[parser.caret] == '/':
         parser.update(endindex+1)
     else:
         self.read_attributes(parser, node, endindex)
     if isinstance(node, Void):
         return [node]
     if isinstance(node, RawText):
         node.data = self.get_raw_text(parser, tagname, pos, shift)
         return [node]
     node.pos = pos
     node.type__ = shift
     return node
    def make_node(self):
        parser = self.parser
        if parser.text[parser.caret] not in '![':
            return None
        if parser.text[parser.caret] == '!':
            tagtype = 'img'
            if parser.text[parser.caret+1:parser.caret+2] != '[':
                return None
            ref_begin = parser.caret+2
        else:
            tagtype = 'a'
            ref_begin = parser.caret+1

        parity, ref_end = check_parity(parser, ref_begin)
        if parity != 0:
            return None

        if tagtype == 'img':
            node = Void('reference')
            node['alt'] = parser.text[ref_begin:ref_end]
            node['_pos'] = parser.copy_pos()
            parser.update(ref_end+1)
            char = parser.text[ref_end+1:ref_end+2]
            if char == '(':
                node.name = 'img'
                self.get_inline_info(parser, node)
            elif char in '[ ':
                get_inline_id(parser, node)
            else:
                parser.update(ref_end+1)
            parser['ElementNP'].get_attribute_list(parser, node)
            return node
        node = Element('reference')
        node.pos = parser.copy_pos()
        node['_pos'] = parser.copy_pos()
        node.ref_end = ref_end
        parser.update(parser.caret+1)
        return node