示例#1
0
	def t_FORMATEDTEXT_STRING(self, t):
		u'([^{}\n])+'
		if _enable_string_parsing:
			stringlexer = StringLexer()
			stringlexer.build()
			stringparser = StringParser(stringlexer)
			stringparser.build()
			d = stringparser.parser.parse(t.value.strip())
			stringhtml = StringHTML(d)
			t.value = stringhtml.generateHTML()
		else:  # do old parsing
			t.value = t.value.strip()
		return t
示例#2
0
						model.append(s)
					elif elem['type'] == 'title':
						model.append('<h%(size)s>%(string)s</h%(size)s>' % elem)
					elif elem['type'] == 'link':
						model.append('<a href="%(href)s">%(string)s</a>' % elem)

		return "\n".join(model)

if __name__ == "__main__":
	"""Runs a small test with the htmlgenerator"""
	import sys
	from stringlexer import StringLexer
	from stringparser import StringParser

	if len(sys.argv) < 2:
		print "first argument must be the string."
		sys.exit(1)

	# Build the lexer
	stringlexer = StringLexer()
	stringlexer.build()
	stringparser = StringParser(stringlexer)
	stringparser.build()
	d = stringparser.parser.parse(sys.argv[1])
	if not d:
		print "Parsing failed!"
	else:
		stringhtml = StringHTML(d)
		print stringhtml.generateHTML()