diff options
Diffstat (limited to 'markdown/commandline.py')
-rw-r--r-- | markdown/commandline.py | 47 |
1 files changed, 12 insertions, 35 deletions
diff --git a/markdown/commandline.py b/markdown/commandline.py index 1eedc6d..dce2b8a 100644 --- a/markdown/commandline.py +++ b/markdown/commandline.py @@ -2,47 +2,25 @@ COMMAND-LINE SPECIFIC STUFF ============================================================================= -The rest of the code is specifically for handling the case where Python -Markdown is called from the command line. """ import markdown import sys +import optparse import logging from logging import DEBUG, INFO, WARN, ERROR, CRITICAL -EXECUTABLE_NAME_FOR_USAGE = "python markdown.py" -""" The name used in the usage statement displayed for python versions < 2.3. -(With python 2.3 and higher the usage statement is generated by optparse -and uses the actual name of the executable called.) """ - -OPTPARSE_WARNING = """ -Python 2.3 or higher required for advanced command line options. -For lower versions of Python use: - - %s INPUT_FILE > OUTPUT_FILE - -""" % EXECUTABLE_NAME_FOR_USAGE - def parse_options(): """ Define and parse `optparse` options for command-line usage. """ - - try: - optparse = __import__("optparse") - except: - if len(sys.argv) == 2: - return {'input': sys.argv[1], - 'output': None, - 'safe': False, - 'extensions': [], - 'encoding': None }, CRITICAL - else: - print OPTPARSE_WARNING - return None, None - - parser = optparse.OptionParser(usage="%prog INPUTFILE [options]") + usage = """%prog [options] [INPUTFILE] + (STDIN is assumed if no INPUTFILE is given)""" + desc = "A Python implementation of John Gruber's Markdown. " \ + "http://www.freewisdom.org/projects/python-markdown/" + ver = "%%prog %s" % markdown.version + + parser = optparse.OptionParser(usage=usage, description=desc, version=ver) parser.add_option("-f", "--file", dest="filename", default=sys.stdout, help="write output to OUTPUT_FILE", metavar="OUTPUT_FILE") @@ -56,10 +34,10 @@ def parse_options(): help="print info messages") parser.add_option("-s", "--safe", dest="safe", default=False, metavar="SAFE_MODE", - help="safe mode ('replace', 'remove' or 'escape' user's HTML tag)") + help="'replace', 'remove' or 'escape' HTML tags in input") parser.add_option("-o", "--output_format", dest="output_format", default='xhtml1', metavar="OUTPUT_FORMAT", - help="Format of output. One of 'xhtml1' (default) or 'html4'.") + help="'xhtml1' (default) or 'html4'.") parser.add_option("--noisy", action="store_const", const=DEBUG, dest="verbose", help="print debug messages") @@ -68,9 +46,8 @@ def parse_options(): (options, args) = parser.parse_args() - if not len(args) == 1: - parser.print_help() - return None, None + if len(args) == 0: + input_file = sys.stdin else: input_file = args[0] |