| 1 |
Using Python-Markdown on the Command Line |
| 2 |
========================================= |
| 3 |
|
| 4 |
While Python-Markdown is primarily a python library, a command line script is |
| 5 |
included as well. While there are many other command line implementations |
| 6 |
of Markdown, you may not have them installed, or you may prefer to use |
| 7 |
Python-Markdown's various extensions. |
| 8 |
|
| 9 |
Setup |
| 10 |
----- |
| 11 |
|
| 12 |
Generally, you may simply call the ``markdown`` file from the command |
| 13 |
line. However, if you have fully installed Markdown (``setup.py install`` or |
| 14 |
``easy_install``), then the ``markdown`` script will have been copied to |
| 15 |
you Python "Scripts" directory. Different systems require different methods to |
| 16 |
ensure that any files in the Python "Scripts" directory are on your system |
| 17 |
path. |
| 18 |
|
| 19 |
* **Windows**: |
| 20 |
|
| 21 |
Assuming a default install on Windows, your "Scripts" directory is most |
| 22 |
likely something like ``C:\\Python25\Scripts``. Verify the location of |
| 23 |
your "Scripts" directory and add it to you system path. |
| 24 |
|
| 25 |
Calling ``markdown`` from th ecommand line will call the wrapper batch file |
| 26 |
``markdown.bat`` in the "Scripts" directory created during install. |
| 27 |
|
| 28 |
* **Linux**: |
| 29 |
|
| 30 |
As each Linux distribution is different and we can't possibly document all |
| 31 |
of them here, we'll provide a few helpful pointers: |
| 32 |
|
| 33 |
* Some systems will automatically install the script on your path. Try it |
| 34 |
and see if it works. Just run ``markdown`` from the command line. |
| 35 |
|
| 36 |
* Other systems may maintain a separate "Scripts" directory which you |
| 37 |
need to add to your path. Find it (check with your distribution) and |
| 38 |
either add it to your path or make a symbolic link to it from your path. |
| 39 |
|
| 40 |
* If you are sure ``markdown`` is on your path, but it still isn't being |
| 41 |
found, check the permissions of the file and make sure it is executable. |
| 42 |
|
| 43 |
As an alternative, you could just ``cd`` into the directory which contains |
| 44 |
the source distribution, and run it from there. However, remember that your |
| 45 |
markdown text files will not likely be in that directory, so it is much more |
| 46 |
convenient to have ``markdown`` on your path. |
| 47 |
|
| 48 |
The Basics |
| 49 |
---------- |
| 50 |
|
| 51 |
To use ``markdown`` from the command line, run it as |
| 52 |
|
| 53 |
$ markdown input_file.txt |
| 54 |
|
| 55 |
or |
| 56 |
|
| 57 |
$ markdown input_file.txt > output_file.html |
| 58 |
|
| 59 |
More Options |
| 60 |
------------ |
| 61 |
|
| 62 |
If you are using Python 2.3 or higher, you can also use advanced |
| 63 |
command line options to specify encoding or to run extensions. |
| 64 |
|
| 65 |
$ markdown --help |
| 66 |
Usage: markdown INPUTFILE [options] |
| 67 |
|
| 68 |
Options: |
| 69 |
-h, --help show this help message and exit |
| 70 |
-f OUTPUT_FILE, --file=OUTPUT_FILE |
| 71 |
write output to OUTPUT_FILE |
| 72 |
-e ENCODING, --encoding=ENCODING |
| 73 |
encoding for input and output files |
| 74 |
-q, --quiet suppress all messages |
| 75 |
-v, --verbose print info messages |
| 76 |
-s SAFE_MODE, --safe=SAFE_MODE |
| 77 |
safe mode ('replace', 'remove' or 'escape' user's |
| 78 |
HTML tag) |
| 79 |
-o OUTPUT_FORMAT, --output_format=OUTPUT_FORMAT |
| 80 |
Format of output. One of 'xhtml1' (default) or |
| 81 |
'html4'. |
| 82 |
--noisy print debug messages |
| 83 |
-x EXTENSION, --extension=EXTENSION |
| 84 |
load extension EXTENSION |
| 85 |
|
| 86 |
Using Extensions |
| 87 |
---------------- |
| 88 |
|
| 89 |
For an extension to be ran this way it must be provided in a module |
| 90 |
which should be in your python path (see [[writing_extensions]] for details). |
| 91 |
It can then be invoked by the name of that module: |
| 92 |
|
| 93 |
$ markdown -x footnotes text_with_footnotes.txt > output.html |
| 94 |
|
| 95 |
If the extension supports config options, you can pass them in as well: |
| 96 |
|
| 97 |
$ markdown -x "footnotes(PLACE_MARKER=~~~~~~~~)" input.txt |