Ejemplo n.º 1
0
def parsetext(text):
    # Escape <,>,& from text for HTML
    pre = re.compile(r'<code>(.*?)</code>', re.M | re.S)
    text = pre.split(text)
    for i in range(len(text)):
        text[i] = escape(text[i])
        if i % 2 == 0:
            for regex, replace in g.regexes:
                text[i] = refn.sub(regex, replace, text[i])
        else:
            text[i] = '<pre>' + text[i] + '</pre>'
    return ''.join(text)
Ejemplo n.º 2
0
def parsetext(text):
	# Escape <,>,& from text for HTML
	pre = re.compile(r'<code>(.*?)</code>', re.M | re.S)
	text = pre.split(text)
	for i in range(len(text)):
		text[i] = escape(text[i])
		if i%2==0 :
			for regex, replace in g.regexes:
				text[i] = refn.sub(regex, replace, text[i])
		else :
			text[i] = '<pre>'+text[i]+'</pre>'
	return ''.join(text)
	
Ejemplo n.º 3
0
def lists (text) :
	prefix = re.match('[\r\n]*', text).group()
	text = text.lstrip('\r\n')
	level = re.match('[ \t]*', text).group()
	testfix = re.match('[\r\n]*', text).group()
	
	regex = re.compile('(?:\n?(?:%s)\*([^\n]*))((?:\n?(?:%s)[ \t]+\*[^\n]*)+)?' % (level, level),re.S | re.M)
	# \1: List items on the same level
	# \2: Sublists
	#
	# Note: re.VERBOSE cannot be used, as level is rendered directly, and verbose ignores newlines
	# Regex explained in verbose:
	#(?:
	#	\n?					# Newline to ensure the start of a line
	#	(?:%s)				# Level whitespace
	#	\*([^\n]*)		# \1: Match and CAPTURE the item
	#)
	#(					# \2: Open \2, sublists.
	#	(?:					# See comments from above...
	#		\n?
	#		(?:%s)[ \t]+	# Identify an item that starts with more than level whitespace
	#		\*[^\n]*
	#	)+					# Include all list items within the sublist
	#)?					# \2: Close
	
	print regex
	
	def listitems(list) :
		if (isinstance(list[1], basestring)) :
			list[0] = '<li>'+list[0]+lists(list[1])+'</li>'
			return list[0]
		else :
			list[0] = '<li>'+list[0]+'</li>'
			return list[0]
			
	
	text = refn.sub(regex, listitems, text)
	
	text = prefix+'<ul>'+text+'</ul>'
	return text
Ejemplo n.º 4
0
def lists(text):
    prefix = re.match("[\r\n]*", text).group()
    text = text.lstrip("\r\n")
    level = re.match("[ \t]*", text).group()
    testfix = re.match("[\r\n]*", text).group()

    regex = re.compile("(?:\n?(?:%s)\*([^\n]*))((?:\n?(?:%s)[ \t]+\*[^\n]*)+)?" % (level, level), re.S | re.M)
    # \1: List items on the same level
    # \2: Sublists
    #
    # Note: re.VERBOSE cannot be used, as level is rendered directly, and verbose ignores newlines
    # Regex explained in verbose:
    # (?:
    # 	\n?					# Newline to ensure the start of a line
    # 	(?:%s)				# Level whitespace
    # 	\*([^\n]*)		# \1: Match and CAPTURE the item
    # )
    # (					# \2: Open \2, sublists.
    # 	(?:					# See comments from above...
    # 		\n?
    # 		(?:%s)[ \t]+	# Identify an item that starts with more than level whitespace
    # 		\*[^\n]*
    # 	)+					# Include all list items within the sublist
    # )?					# \2: Close

    print regex

    def listitems(list):
        if isinstance(list[1], basestring):
            list[0] = "<li>" + list[0] + lists(list[1]) + "</li>"
            return list[0]
        else:
            list[0] = "<li>" + list[0] + "</li>"
            return list[0]

    text = refn.sub(regex, listitems, text)

    text = prefix + "<ul>" + text + "</ul>"
    return text