File: module-body.py

package info (click to toggle)
txt2tags 2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,264 kB
  • ctags: 471
  • sloc: python: 2,461; lisp: 414; ruby: 347; xml: 96; php: 95; sh: 83; makefile: 26
file content (48 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
#
# Sample of txt2tags being used as a module (http://txt2tags.sf.net) 
#
# Details:
#   The document body is a string.
#   Headers and config are set with Python code.
#

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

# Here is the marked body text, it must be a list.
txt = "Hi!\n\nHave a **nice** day.\n\nBye."
txt = txt.split('\n')

# Set the three header fields
headers = ['Header 1', 'Header 2', 'Header 3'] 

# Set the configuration on the 'config' dict.
config = txt2tags.ConfigMaster()._get_defaults()
config['outfile'] = txt2tags.MODULEOUT  # results as list
config['target'] = 'html'               # target type: HTML
config['encoding'] = 'iso-8859-1'       # document encoding
config['css-sugar'] = 1                 # CSS flag

# The Pre (and Post) processing config is a list of lists:
# [ [this, that], [foo, bar], [patt, replace] ]
config['preproc'] = []
config['preproc'].append(['nice','VERY NICE'])
config['preproc'].append(['day','life'])

# Let's do the conversion
try:
	headers   = txt2tags.doHeader(headers, config)
	body, toc = txt2tags.convert(txt, config)
	footer    = txt2tags.doFooter(config)
	full_doc  = headers + toc + body + footer
	finished  = txt2tags.finish_him(full_doc, config)
	print '\n'.join(finished)

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

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