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 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 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): """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 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): """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 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 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 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
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
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 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 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