#!/bin/python3
# -*- coding: utf-8 -*-
#
# This file is part of INGInious. See the LICENSE and the COPYRIGHTS files for
# more information about the licensing of this file.
#
# Tool to produce rst for code snippet

import sys
import argparse
from inginious_container_api import rst

parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, 
                                 description='Generates reStructuredText for a given snippet.',
                                 epilog='If code not specified, reads on stdin.')
parser.add_argument('-l', '--language', help="snippet language", default="")
parser.add_argument('-e', '--escape', help="interprets backslash escapes", action='store_true')
parser.add_argument('-c', '--code' , help="snippet code", default="")
args = parser.parse_args()

language = args.language
code = args.code if args.code else sys.stdin.read()
text = code.encode('utf-8').decode('unicode-escape').encode('latin1').decode('utf-8') if args.escape else code

# Do the real stuff 
print(rst.get_codeblock(language, text))
