Example #1
0
    def _init_block_parser(self):
        # Top level parser, to break up block level items
        p = RuleParser(
            Rule(VERBATIM_BLOCK,
                 r'''
				^(?P<pre_indent>\t*) \'\'\' \s*?				# 3 "'"
				( (?:^.*\n)*? )									# multi-line text
				^(?P=pre_indent) \'\'\' \s*? \n					# another 3 "'" with matching indent
				''',
                 process=self.parse_pre),
            Rule(OBJECT,
                 r'''
				^(?P<obj_indent>\t*) \{\{\{ \s*? (\S+:.*\n)		# "{{{ object_type: attrib=..."
				( (?:^.*\n)*? ) 								# multi-line body
				^(?P=obj_indent) \}\}\} \s*? \n					# "}}}" with matching indent
				''',
                 process=self.parse_object),
            Rule(
                HEADING,
                r'^( ==+ [\ \t]+ \S.*? ) [\ \t]* =* \n',  # "==== heading ===="
                process=self.parse_heading),
            # standard table format
            Rule(TABLE,
                 r'''
				^(\|.*\|) \s*? \n								# starting and ending with |
				^( (?:\| [ \|\-:]+ \| \s*? \n)? )				# column align
				( (?:^\|.*\| \s*? \n)+ )							# multi-lines: starting and ending with |
				''',
                 process=self.parse_table),
            # line format
            Rule(LINE, r'(?<=\n)-{5,}(?=\n)',
                 process=self.parse_line)  # \n----\n
        )
        p.process_unmatched = self.parse_para
        return p
Example #2
0
    def _init_intermediate_parser(self):
        # Intermediate level, breaks up lists and indented blocks
        # TODO: deprecate this by taking lists out of the para
        #       and make a new para for each indented block
        p = RuleParser(
            Rule('X-Bullet-List',
                 r'''(
					^ %s .* \n								# Line starting with bullet
					(?:
						^ \t* %s .* \n						# Line with same or more indent and bullet
					)*										# .. repeat
				)''' % (bullet_pattern, bullet_pattern),
                 process=self.parse_list),
            Rule('X-Indented-Bullet-List',
                 r'''(
					^(?P<list_indent>\t+) %s .* \n			# Line with indent and bullet
					(?:
						^(?P=list_indent) \t* %s .* \n		# Line with same or more indent and bullet
					)*										# .. repeat
				)''' % (bullet_pattern, bullet_pattern),
                 process=self.parse_list),
            Rule('X-Indented-Block',
                 r'''(
					^(?P<block_indent>\t+) .* \n			# Line with indent
					(?:
						^(?P=block_indent) (?!\t|%s) .* \n	# Line with _same_ indent, no bullet
					)*										# .. repeat
				)''' % bullet_pattern,
                 process=self.parse_indent),
        )
        p.process_unmatched = self.inline_parser
        return p