def make_node(self):
     parser = self.parser
     if parser.text[parser.caret] != '_':
         return None
     if parser.text[parser.caret-1] not in EMPTY:
         return None
     found = False
     index = parser.caret
     while found is False:
         index = parser.text.find('_', index+1, parser.end)
         if index == -1 or parser.text[index-1] in EMPTY:
             return None
         char = parser.text[index+1:index+2]
         if char.isalpha() or char in '&':
             pass
         else:
             found = True
     if parser.caret+1 == index:
         return None
     pos = parser.copy_pos()
     parser.update(parser.caret+1)
     node = Element('em')
     node.pos = pos
     node.smartem_end = index
     return node
Beispiel #2
0
 def make_node(self):
     parser = self.parser
     if parser.text[parser.caret] != '_':
         return None
     if parser.text[parser.caret - 1] not in EMPTY:
         return None
     found = False
     index = parser.caret
     while found is False:
         index = parser.text.find('_', index + 1, parser.end)
         if index == -1 or parser.text[index - 1] in EMPTY:
             return None
         char = parser.text[index + 1:index + 2]
         if char.isalpha() or char in '&':
             pass
         else:
             found = True
     if parser.caret + 1 == index:
         return None
     pos = parser.copy_pos()
     parser.update(parser.caret + 1)
     node = Element('em')
     node.pos = pos
     node.smartem_end = index
     return node
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     qchar = parser.text[caret:caret+1]
     if qchar not in "'\"":
         return None
     if parser.text[caret-1] not in EMPTY:
         parser.update(caret+1)
         return Entity(qchar)
     if parser.text[caret+1:caret+2] in EMPTY:
         parser.update(caret+1)
         return Entity(qchar)
     index = parser.text.find(qchar, caret+1)
     while index != -1:
         char = parser.text[index-1]
         if char == '\\':
             index = parser.text.find(qchar, index+1)
         elif char not in EMPTY:
             node = Element('quoted')
             node.pos = parser.copy_pos()
             node['char'] = qchar
             node.end_pos = index
             parser.update(parser.caret+1)
             return node
         else:
             break
     parser.update(parser.end)
     return Entity(qchar)
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     qchar = parser.text[caret:caret + 1]
     if qchar not in "'\"":
         return None
     if parser.text[caret - 1] not in EMPTY:
         parser.update(caret + 1)
         return Entity(qchar)
     if parser.text[caret + 1:caret + 2] in EMPTY:
         parser.update(caret + 1)
         return Entity(qchar)
     index = parser.text.find(qchar, caret + 1)
     while index != -1:
         char = parser.text[index - 1]
         if char == '\\':
             index = parser.text.find(qchar, index + 1)
         elif char not in EMPTY:
             node = Element('quoted')
             node.pos = parser.copy_pos()
             node['char'] = qchar
             node.end_pos = index
             parser.update(parser.caret + 1)
             return node
         else:
             break
     parser.update(parser.end)
     return Entity(qchar)
 def start_list(ltype):
     """Create a new list element. """
     if ltype == 'ol':
         node = Element('enumerate')
     else:
         node = Element('itemize')
     node.append_child(Element('li'))
     return node
Beispiel #6
0
 def make_list(main):
     """Return a list. """
     item = main[0]
     if item.name == '#text':
         if main.prev is not None and main.prev.name == '#text':
             main.prev.data += item.data
             del main[0]
             item = main[0]
         else:
             item = item.next
             main.parent.insert_before(main.index, item.prev)
     level = 1
     list_node = ListNC.start_list(item['type'])
     crt = list_node
     while item['level'] > level:
         crt[-1].append_child(ListNC.start_list(item['type']))
         crt = crt[-1][-1]
         level += 1
     crt[-1].extend_children(item)
     for key in item:
         if key.startswith('__'):
             crt[key[2:]] = item[key]
         elif key.startswith('_'):
             crt[-1][key[1:]] = item[key]
     item = item.next
     while item is not None:
         if 'flag' in item and item['flag'] == 'close':
             while level >= item['level']:
                 crt = crt.parent.parent
                 level -= 1
         else:
             if item['level'] == level:
                 crt.append_child(Element('li'))
             elif item['level'] > level:
                 if len(crt) == 0:
                     crt.append_child(Element('li'))
                 while item['level'] > level:
                     crt[-1].append_child(ListNC.start_list(item['type']))
                     crt = crt[-1][-1]
                     level += 1
             else:
                 while item['level'] < level:
                     crt = crt.parent.parent
                     level -= 1
                 crt.append_child(Element('li'))
         crt[-1].extend_children(item)
         for key in item:
             if key.startswith('__'):
                 crt[key[2:]] = item[key]
             elif key.startswith('_'):
                 crt[-1][key[1:]] = item[key]
         item = item.next
     del main[:]
     return list_node
 def make_node(self):
     parser = self.parser
     index = self.is_auto_link(parser, parser.caret, parser.end)
     if index is None:
         return None
     url = parser.text[parser.caret + 1 : index]
     node = Element("a")
     node["href"] = url
     node.append_child(Text(url))
     parser.update(index + 1)
     parser["ElementNP"].get_attribute_list(parser, node)
     return [node]
Beispiel #8
0
 def make_node(self):
     parser = self.parser
     index = self.is_auto_link(parser, parser.caret, parser.end)
     if index is None:
         return None
     url = parser.text[parser.caret + 1:index]
     node = Element('a')
     node['href'] = url
     node.append_child(Text(url))
     parser.update(index + 1)
     parser['ElementNP'].get_attribute_list(parser, node)
     return [node]
Beispiel #9
0
 def make_node(self):
     parser = self.parser
     index = self.is_auto_mail(parser, parser.caret, parser.end)
     if index is None:
         return None
     email = parser.text[parser.caret + 1:index]
     mailto = "mailto:" + email
     node = Element('a')
     node['href'] = mailto
     node.append_child(Text(email))
     parser.update(index + 1)
     parser['ElementNP'].get_attribute_list(parser, node)
     return [node]
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     if caret != 0:
         return None
     entry = self.get_entry(parser)
     if entry is None:
         return None
     node = Element('lexor-meta')
     while entry is not None:
         node.append_child(entry)
         entry = self.get_entry(parser)
     return [node]
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     if caret != 0:
         return None
     entry = self.get_entry(parser)
     if entry is None:
         return None
     node = Element('lexor-meta')
     while entry is not None:
         node.append_child(entry)
         entry = self.get_entry(parser)
     return [node]
 def make_node(self):
     parser = self.parser
     index = self.is_auto_mail(parser, parser.caret, parser.end)
     if index is None:
         return None
     email = parser.text[parser.caret + 1 : index]
     mailto = "mailto:" + email
     node = Element("a")
     node["href"] = mailto
     node.append_child(Text(email))
     parser.update(index + 1)
     parser["ElementNP"].get_attribute_list(parser, node)
     return [node]
    def make_node(self):
        """Returns a header element."""
        parser = self.parser
        match = SETEXT_RE.match(parser.text, parser.caret, parser.end)
        if match is None:
            return None
        index = parser.text.find('\n', parser.caret, parser.end)

        level = 1
        if parser.text[index+1] == '-':
            level = 2
        node = Element('h%d' % level)
        node.pos = parser.copy_pos()

        content_start = parser['EmptyNP'].skip_space(parser)
        final_pos = match.end(0)
        att = False
        left_b = None
        right_b = parser.text.rfind('}', content_start, index)
        if right_b != -1:
            if parser.text[right_b+1:index].strip() == '':
                left_b = parser.text.rfind('{', parser.caret, right_b)
                if left_b != -1 and parser.text[left_b-1] in ' \t':
                    att = True
        # Get the index where the content ends
        if att is True:
            content_end = left_b
        else:
            content_end = index

        node.content_end = content_end
        node.att = att
        node.left_b = left_b
        node.final_pos = final_pos
        return node
 def _create_node(self, parser, end_index, misaligned, doc_string):
     """Parse the doc_string and return the node. """
     node = Element('doc-comment')
     if self.lexor_parser and not misaligned:
         self.lexor_parser.parse(doc_string)
         node['parsed'] = 'true'
         node.extend_children(self.lexor_parser.document)
         if self.lexor_parser.log:
             parser.update_log(
                 self.lexor_parser.log,
                 delta=[self.line_start - 1, self.indentation + 2]
             )
     else:
         if not misaligned:
             self.msg('E404', parser.pos, [self.parser_name])
         node['parsed'] = 'false'
         node.append_child(Text(doc_string))
     parser.update(end_index)
     return [node]
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     content_start = caret+len(self.pattern)
     if parser.text[caret:content_start] != self.pattern:
         return None
     content_end = parser.text.find(self.pattern, content_start)
     if content_end == -1 or content_start == content_end:
         return None
     if self.tight is True:
         char_start = parser.text[content_start]
         char_end = parser.text[content_end-1]
         if char_start in EMPTY or char_end in EMPTY:
             return None
     node = Element(self.tagname)
     node.pos = parser.copy_pos()
     node.inlinepattern_end = content_end
     parser.update(content_start)
     return node
Beispiel #16
0
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     content_start = caret + len(self.pattern)
     if parser.text[caret:content_start] != self.pattern:
         return None
     content_end = parser.text.find(self.pattern, content_start)
     if content_end == -1 or content_start == content_end:
         return None
     if self.tight is True:
         char_start = parser.text[content_start]
         char_end = parser.text[content_end - 1]
         if char_start in EMPTY or char_end in EMPTY:
             return None
     node = Element(self.tagname)
     node.pos = parser.copy_pos()
     node.inlinepattern_end = content_end
     parser.update(content_start)
     return node
Beispiel #17
0
 def end(self, node):
     if node.name == 'strong_em':
         node.name = 'strong'
         tmp = Element('em')
         tmp.extend_children(node)
         node.append_child(tmp)
     else:
         node.name = 'em'
         tmp = Element('strong')
         tmp.extend_children(node)
         node.append_child(tmp)
     return node
    def make_node(self):
        parser = self.parser
        match = FENCED.match(parser.text, parser.caret-1)
        if match:
            return self.get_fenced_block(match)
        text = self.parser.text[parser.caret:parser.caret+4]
        if text != 4*' ' and text[0:1] != '\t':
            return None
        node = Element('codeblock')

        index = parser.text.find('\n', parser.caret, parser.end)
        if index == -1:
            index = parser.end
        left_b = parser.text.find('{', parser.caret, index)
        if left_b != -1:
            line = parser.text[parser.caret:left_b]
        else:
            line = parser.text[parser.caret:index]
        line_one = line[1:] if line[0:1] == '\t' else line[4:]

        block = code_hilite(line_one, node)

        if left_b != -1:
            parser.update(left_b)
            self.parser['ElementNP'].get_attribute_list(parser, node)

        while index < parser.end:
            old_index = index + 1
            index = parser.text.find('\n', old_index, parser.end)
            if index == -1:
                index = parser.end
            line = parser.text[old_index:index]
            if line[0:4] == 4*' ':
                block.append(line[4:])
            elif line[0:1] == '\t':
                block.append(line[1:])
            else:
                index = index + 1
                break
        node.append_child(Text('\n'.join(block)))
        parser.update(index)
        return [node]
 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)
     node = Element(parser.text[parser.caret+1:match.end(0)-1])
     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)
         return [node]  # Closed element no need to add position
     else:
         if self.read_attributes(parser, node, endindex):
             return [node]
     node.pos = pos
     return node
 def make_node(self):
     """Returns a paragraph element. """
     parser = self.parser
     index = parser.caret
     try:
         while parser.text[index] in ' \t\n\r\f\v':
             index += 1
     except IndexError:
         parser.update(index)
         return None
     end = parser.end
     tmp = parser['AutoLinkNP'].is_auto_link(parser, index, end)
     if tmp is None:
         tmp = parser['AutoMailNP'].is_auto_mail(parser, index, end)
         if tmp is None:
             tmp = parser['ElementNP'].get_tagname(parser)
             if tmp is not None and tmp not in VALID_TAGS:
                 return None
     node = Element('p')
     node.pos = parser.copy_pos()
     return node
    def make_node(self):
        """Returns a header element."""
        parser = self.parser
        match = SETEXT_RE.match(parser.text, parser.caret, parser.end)
        if match is None:
            return None
        index = parser.text.find("\n", parser.caret, parser.end)

        level = 1
        if parser.text[index + 1] == "-":
            level = 2
        node = Element("h%d" % level)
        node.pos = parser.copy_pos()

        content_start = parser["EmptyNP"].skip_space(parser)
        final_pos = match.end(0)
        att = False
        left_b = None
        right_b = parser.text.rfind("}", content_start, index)
        if right_b != -1:
            if parser.text[right_b + 1 : index].strip() == "":
                left_b = parser.text.rfind("{", parser.caret, right_b)
                if left_b != -1 and parser.text[left_b - 1] in " \t":
                    att = True
        # Get the index where the content ends
        if att is True:
            content_end = left_b
        else:
            content_end = index

        node.content_end = content_end
        node.att = att
        node.left_b = left_b
        node.final_pos = final_pos
        return node
 def make_node(self):
     parser = self.parser
     index = parser.caret + 1
     char = parser.text[index]
     if parser.text[index - 1] != '\n' or char not in '*+^':
         return None
     if char == '^':
         index += 1
         char = parser.text[index]
         if char not in '*+':
             return None
         flag = 'close'
         total = 0
         while parser.text[index] == char:
             index += 1
             total += 1
     else:
         flag = None
         total = 0
         while parser.text[index] == char:
             index += 1
             total += 1
     node = Element('list_item')
     if flag is not None:
         node['flag'] = flag
     node['level'] = total
     if char == '*':
         node['type'] = 'ul'
     else:
         node['type'] = 'ol'
     node.pos = parser.copy_pos()
     parser.update(index)
     total = node.attlen
     parser['ElementNP'].get_attribute_list(parser, node, '[', ']')
     for num in xrange(total, node.attlen):
         node.rename(num, '__' + node.attribute(num))
     total = node.attlen
     parser['ElementNP'].get_attribute_list(parser, node)
     for num in xrange(total, node.attlen):
         node.rename(num, '_' + node.attribute(num))
     if parser.text[parser.caret] == ' ':
         parser.update(parser.caret + 1)
     return node
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     if parser.text[caret] != '#':
         return None
     index = parser.caret + 1
     level = 1
     while parser.text[index:index+1] == '#':
         index += 1
         level += 1
         if level == 6:
             break
     tagname = 'h%d' % level
     node = Element(tagname)
     node.pos = parser.copy_pos()
     # Get attributes if they follow right after the hash
     parser.update(index)
     parser['ElementNP'].get_attribute_list(parser, node)
     # Get index where content starts
     content_start = parser['EmptyNP'].skip_space(parser)
     # Get indices of the left and right bracket
     index = parser.text.find('\n', content_start, parser.end)
     if index == -1:
         index = parser.end
     final_pos = index + 1
     att = False
     left_b = None
     right_b = parser.text.rfind('}', content_start, index)
     if right_b != -1:
         if parser.text[right_b+1:index].strip() == '':
             left_b = parser.text.rfind('{', parser.caret, right_b)
             char = parser.text[left_b-1]
             if left_b != -1 and char in ' \t#':
                 att = True
     # Get the index where the content ends
     if att is True:
         content_end = left_b
     else:
         content_end = index
     index = content_end - 1
     # Check if there are extra hashes so that we can ignore them
     while parser.text[index] in ' \t\r\f\v':
         index -= 1
     while parser.text[index] == '#':
         index -= 1
     if parser.text[index+1:index+2] == '#':
         content_end = index+1
     node.content_end = content_end
     node.att = att
     node.left_b = left_b
     node.final_pos = final_pos
     return node
 def make_node(self):
     parser = self.parser
     index = parser.caret + 1
     char = parser.text[index]
     if parser.text[index-1] != '\n' or char not in '*+^':
         return None
     if char == '^':
         index += 1
         char = parser.text[index]
         if char not in '*+':
             return None
         flag = 'close'
         total = 0
         while parser.text[index] == char:
             index += 1
             total += 1
     else:
         flag = None
         total = 0
         while parser.text[index] == char:
             index += 1
             total += 1
     node = Element('list_item')
     if flag is not None:
         node['flag'] = flag
     node['level'] = total
     if char == '*':
         node['type'] = 'ul'
     else:
         node['type'] = 'ol'
     node.pos = parser.copy_pos()
     parser.update(index)
     total = node.attlen
     parser['ElementNP'].get_attribute_list(parser, node, '[', ']')
     for num in xrange(total, node.attlen):
         node.rename(num, '__'+node.attribute(num))
     total = node.attlen
     parser['ElementNP'].get_attribute_list(parser, node)
     for num in xrange(total, node.attlen):
         node.rename(num, '_'+node.attribute(num))
     if parser.text[parser.caret] == ' ':
         parser.update(parser.caret+1)
     return node
 def end(self, node):
     if node.name == 'strong_em':
         node.name = 'strong'
         tmp = Element('em')
         tmp.extend_children(node)
         node.append_child(tmp)
     else:
         node.name = 'em'
         tmp = Element('strong')
         tmp.extend_children(node)
         node.append_child(tmp)
     return node
 def make_node(self):
     parser = self.parser
     caret = parser.caret
     if parser.text[caret] != "#":
         return None
     index = parser.caret + 1
     level = 1
     while parser.text[index : index + 1] == "#":
         index += 1
         level += 1
         if level == 6:
             break
     tagname = "h%d" % level
     node = Element(tagname)
     node.pos = parser.copy_pos()
     # Get attributes if they follow right after the hash
     parser.update(index)
     parser["ElementNP"].get_attribute_list(parser, node)
     # Get index where content starts
     content_start = parser["EmptyNP"].skip_space(parser)
     # Get indices of the left and right bracket
     index = parser.text.find("\n", content_start, parser.end)
     if index == -1:
         index = parser.end
     final_pos = index + 1
     att = False
     left_b = None
     right_b = parser.text.rfind("}", content_start, index)
     if right_b != -1:
         if parser.text[right_b + 1 : index].strip() == "":
             left_b = parser.text.rfind("{", parser.caret, right_b)
             char = parser.text[left_b - 1]
             if left_b != -1 and char in " \t#":
                 att = True
     # Get the index where the content ends
     if att is True:
         content_end = left_b
     else:
         content_end = index
     index = content_end - 1
     # Check if there are extra hashes so that we can ignore them
     while parser.text[index] in " \t\r\f\v":
         index -= 1
     while parser.text[index] == "#":
         index -= 1
     if parser.text[index + 1 : index + 2] == "#":
         content_end = index + 1
     node.content_end = content_end
     node.att = att
     node.left_b = left_b
     node.final_pos = final_pos
     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
Beispiel #28
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 get_fenced_block(self, match):
        """Parse a fenced block code. """
        parser = self.parser
        text = parser.text
        total = text[match.start()+1:match.end()].count('~')
        parser.update(match.end())
        node = Element('codeblock')

        index = parser.text.find('\n', parser.caret)
        if index == -1:
            index = parser.end
        left_b = parser.text.find('{', parser.caret, index)
        if left_b != -1:
            line = parser.text[parser.caret:left_b]
        else:
            line = parser.text[parser.caret:index]

        block = code_hilite(line, node)
        if block:
            append = block[0] + '\n'
        else:
            append = ''

        if left_b != -1:
            parser.update(left_b)
            self.parser['ElementNP'].get_attribute_list(parser, node)
            if text[parser.caret] == '\n':
                parser.update(parser.caret+1)
        else:
            parser.update(index+1)

        rfenced = re.compile(r'\n~{'+str(total-1)+',}[~]+[ ]*(\n|$)')
        match = rfenced.search(text, parser.caret)
        if not match:
            self.msg('E200', parser.pos, [total])
            node.append_child(append+text[parser.caret:])
            parser.update(parser.end)
            return [node]
        node.append_child(append+text[parser.caret:match.start()])
        parser.update(match.end())
        return [node]
 def build_node(parser, content):
     """Build the actual node with the given content. """
     node = Element('code')
     node.append_child(Text(content))
     parser['ElementNP'].get_attribute_list(parser, node)
     return [node]
Beispiel #31
0
 def start_list(ltype):
     """Create a new list element. """
     node = Element(ltype)
     node.append_child(Element('li'))
     return node