2
0
Fork 0
textout/scripts/textout2html

33 lines
853 B
Plaintext
Raw Normal View History

2018-01-16 13:34:11 +01:00
#!/usr/bin/env python3
""" textout to HTML converter for the command line. """
2018-01-16 13:34:11 +01:00
import sys, argparse
import textoutpc
def parse_args():
""" Parse the arguments. """
ap = argparse.ArgumentParser(prog='textout2html',
description='Convert textout BBcode to HTML.')
ap.add_argument('-o', dest='output', default=sys.stdout,
type=lambda x: sys.stdout if x == '-' else open(x, 'w'),
help='the output source, stdout by default.')
2018-01-16 13:34:11 +01:00
ap.add_argument('input', nargs='?', default=sys.stdin,
type=lambda x: sys.stdin if x == '-' else open(x, 'r'),
help='the input source, stdin by default.')
2018-01-16 13:34:11 +01:00
args = ap.parse_args()
return args
def main():
""" Main function of the script. """
args = parse_args()
print(textoutpc.tohtml(args.input.read()), file=args.output, end='')
2018-01-16 13:34:11 +01:00
if __name__ == '__main__':
# TODO: manage exceptions
main()
# End of file.