Sophie

Sophie

distrib > Mageia > 5 > x86_64 > by-pkgid > 7bf104dbf63bf6c91543fb652c9f6b37 > files > 107

txt2tags-2.6-7.mga5.noarch.rpm

#!/usr/bin/env python
#
# Sample of txt2tags being used as a module (http://txt2tags.org) 
#
# Details:
#   The full marked text is a string with headers, config and body.
#   No post config or setting is made.
#

# Remember to place the 'txt2tags.py' file on the same dir
import txt2tags

# Here is the marked text, it must be a list.
txt = "Header1\nHeader2\nHeader3\n%!target: html\nBody line 1."
txt = txt.split('\n')

# Let's do the conversion
try:
	# First we parse the text, splitting parts and getting config.
	data = txt2tags.process_source_file(contents=txt)
	# Then we convert it, dumping results to the 'tagged' list.
	tagged, config = txt2tags.convert_this_files([data])
	# Show the tagged file on the screen.
	print '\n'.join(tagged)

# Txt2tags error, show the message to the user
except txt2tags.error, msg:
	print msg

# Unknown error, show the traceback to the user
except:
	print txt2tags.getUnknownErrorMessage()