PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/samples/module/module-full.py

http://txt2tags.googlecode.com/
Python | 39 lines | 16 code | 8 blank | 15 comment | 0 complexity | 4a3a9b9f900705f3ef3cd0d8e50682f7 MD5 | raw file
 1#!/usr/bin/env python
 2#
 3# Sample of txt2tags being used as a module (http://txt2tags.org)
 4#
 5# Details:
 6#   The full marked text is a string with headers, config and body.
 7#   No post config or setting is made.
 8#
 9
10import sys
11
12import setup
13
14setup.setup_paths()
15
16import txt2tags
17
18# Here is the marked text, it must be a list.
19txt = "Header1\nHeader2\nHeader3\n%!target: html\nBody line 1."
20txt = txt.split('\n')
21
22# Let's do the conversion
23try:
24    # First we parse the text, splitting parts and getting config.
25    data = txt2tags.process_source_file(contents=txt)
26    # Then we convert it, dumping results to the 'tagged' list.
27    tagged, config = txt2tags.convert_this_files([data])
28    # Show the tagged file on the screen.
29    print '\n'.join(tagged)
30
31# Txt2tags error, show the message to the user
32except txt2tags.error, msg:
33    print msg
34    sys.exit(1)
35
36# Unknown error, show the traceback to the user
37except:
38    print txt2tags.getUnknownErrorMessage()
39    sys.exit(1)