File: module-full.py

package info (click to toggle)
txt2tags 3.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,160 kB
  • sloc: python: 3,002; sh: 45; makefile: 35
file content (31 lines) | stat: -rwxr-xr-x 978 bytes parent folder | download | duplicates (2)
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
#!/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))
except txt2tags.error as err:
    # Txt2tags error, show the message to the user
    print(err)
except Exception:
    # Unknown error, show the traceback to the user
    print(txt2tags.getUnknownErrorMessage())