@@ -12,6 +12,8 @@ Generally, you will want to have the Markdown library fully installed on your
1212system to run the command line script. See the
1313[ Installation instructions] ( install.md ) for details.
1414
15+ ## Basic Usage
16+
1517Python-Markdown's command line script takes advantage of Python's ` -m ` flag.
1618Therefore, assuming the python executable is on your system path, use the
1719following format:
@@ -28,92 +30,62 @@ At its most basic usage, one would simply pass in a file name as the only argume
2830python -m markdown input_file.txt
2931```
3032
31- Piping input and output (on ` STDIN ` and ` STDOUT ` ) is fully supported as well.
32- For example:
33-
34- ``` bash
35- echo " Some **Markdown** text." | python -m markdown > output.html
36- ```
37-
38- Use the ` --help ` option for a list all available options and arguments:
33+ Use the ` --help ` option for a list of all available options and arguments:
3934
4035``` bash
4136python -m markdown --help
4237```
4338
44- If you don't want to call the python executable directly (using the ` -m ` flag),
45- follow the instructions below to use a wrapper script:
46-
47- Setup
48- -----
49-
50- Upon installation, the ` markdown_py ` script will have been copied to
51- your Python "Scripts" directory. Different systems require different methods to
52- ensure that any files in the Python "Scripts" directory are on your system
53- path.
54-
55- * ** Windows** :
56-
57- Assuming a default install of Python on Windows, your "Scripts" directory
58- is most likely something like ` C:\\Python37\Scripts ` . Verify the location
59- of your "Scripts" directory and add it to you system path.
39+ !!! warning
6040
61- Calling ` markdown_py ` from the command line will call the wrapper batch
62- file ` markdown_py.bat ` in the ` "Scripts" ` directory created during install.
63-
64- * __ * nix __ (Linux, OSX, BSD, Unix, etc.):
41+ The Python-Markdown library does ***not*** sanitize its HTML output. If
42+ you are processing Markdown input from an untrusted source, it is your
43+ responsibility to ensure that it is properly sanitized. For more
44+ information see [Sanitizing HTML Output](sanitization.md).
6545
66- As each \* nix distribution is different and we can't possibly document all
67- of them here, we'll provide a few helpful pointers:
68-
69- * Some systems will automatically install the script on your path. Try it
70- and see if it works. Just run ` markdown_py ` from the command line.
71-
72- * Other systems may maintain a separate "Scripts" ("bin") directory which
73- you need to add to your path. Find it (check with your distribution) and
74- either add it to your path or make a symbolic link to it from your path.
46+ ## Piping Input and Output
7547
76- * If you are sure ` markdown_py ` is on your path, but it still is not being
77- found, check the permissions of the file and make sure it is executable.
78-
79- As an alternative, you could just ` cd ` into the directory which contains
80- the source distribution, and run it from there. However, remember that your
81- markdown text files will not likely be in that directory, so it is much
82- more convenient to have ` markdown_py ` on your path.
83-
84- !!!Note
85- Python-Markdown uses ` "markdown_py" ` as a script name because the Perl
86- implementation has already taken the more obvious name "markdown".
87- Additionally, the default Python configuration on some systems would cause a
88- script named ` "markdown.py" ` to fail by importing itself rather than the
89- markdown library. Therefore, the script has been named ` "markdown_py" ` as a
90- compromise. If you prefer a different name for the script on your system, it
91- is suggested that you create a symbolic link to ` markdown_py ` with your
92- preferred name.
93-
94- Usage
95- -----
96-
97- To use ` markdown_py ` from the command line, run it as
48+ Piping input and output (on ` STDIN ` and ` STDOUT ` ) is fully supported.
49+ For example:
9850
9951``` bash
100- markdown_py input_file.txt
52+ echo " Some **Markdown** text. " | python -m markdown > output.html
10153```
10254
103- or
55+ The above command would generate a file named ` output.html ` with the following content:
56+ ``` html
57+ <p >Some <strong >Markdown</strong > Text.</p >
58+ ```
59+
60+ As Python-Markdown only ever outputs HTML fragments (no ` <html> ` , ` <head> ` ,
61+ and ` <body> ` tags), it is generally expected that the command line interface
62+ will always be used to pipe output to a templating engine. In the event that
63+ no additional content is needed and the output only needs to be wrapped in
64+ otherwise empty ` <html> ` , ` <head> ` , and ` <body> ` tags,
65+ [ JustHTML] ( https://emilstenstrom.github.io/justhtml/ ) can do that with with
66+ a single command:
10467
10568``` bash
106- markdown_py input_file.txt > output_file .html
69+ echo " Some **Markdown** text. " | python -m markdown | justhtml - --fragment > output .html
10770```
10871
109- For a complete list of options, run
72+ The above command would generate a file named ` output.html ` with the following content:
11073
111- ``` bash
112- markdown_py --help
74+ ``` html
75+ <html >
76+ <head ></head >
77+ <body >
78+ <p >Some <strong >Markdown</strong > Text.</p >
79+ </body >
80+ </html >
11381```
11482
115- Using Extensions
116- ----------------
83+ If you don't need or want JustHTML's HTML sanitation, you can disable it with the
84+ ` --unsafe ` flag, although that is not recommended. See JustHTML's
85+ [ Command Line Interface] ( https://emilstenstrom.github.io/justhtml/cli.html )
86+ documentation for details.
87+
88+ ## Using Extensions
11789
11890To load a Python-Markdown extension from the command line use the ` -x `
11991(or ` --extension ` ) option. The extension module must be on your ` PYTHONPATH `
@@ -187,3 +159,74 @@ dependencies. The format of your configuration file is automatically detected.
187159[ JSON ] : https://json.org/
188160[ PyYAML ] : https://pyyaml.org/
189161[ 2.5 release notes ] : change_log/release-2.5.md
162+
163+ ## Using the ` markdown_py ` Command
164+
165+ If you don't want to call the python executable directly (using the ` -m ` flag),
166+ follow the instructions below to use a wrapper script:
167+
168+ ### Setup ` markdown_py `
169+
170+ Upon installation, the ` markdown_py ` script will have been copied to
171+ your Python "Scripts" directory. Different systems require different methods to
172+ ensure that any files in the Python "Scripts" directory are on your system
173+ path.
174+
175+ * ** Windows** :
176+
177+ Assuming a default install of Python on Windows, your "Scripts" directory
178+ is most likely something like ` C:\\Python37\Scripts ` . Verify the location
179+ of your "Scripts" directory and add it to you system path.
180+
181+ Calling ` markdown_py ` from the command line will call the wrapper batch
182+ file ` markdown_py.bat ` in the ` "Scripts" ` directory created during install.
183+
184+ * __ * nix__ (Linux, OSX, BSD, Unix, etc.):
185+
186+ As each \* nix distribution is different and we can't possibly document all
187+ of them here, we'll provide a few helpful pointers:
188+
189+ * Some systems will automatically install the script on your path. Try it
190+ and see if it works. Just run ` markdown_py ` from the command line.
191+
192+ * Other systems may maintain a separate "Scripts" ("bin") directory which
193+ you need to add to your path. Find it (check with your distribution) and
194+ either add it to your path or make a symbolic link to it from your path.
195+
196+ * If you are sure ` markdown_py ` is on your path, but it still is not being
197+ found, check the permissions of the file and make sure it is executable.
198+
199+ As an alternative, you could just ` cd ` into the directory which contains
200+ the source distribution, and run it from there. However, remember that your
201+ markdown text files will not likely be in that directory, so it is much
202+ more convenient to have ` markdown_py ` on your path.
203+
204+ !!!Note
205+ Python-Markdown uses ` "markdown_py" ` as a script name because the Perl
206+ implementation has already taken the more obvious name "markdown".
207+ Additionally, the default Python configuration on some systems would cause a
208+ script named ` "markdown.py" ` to fail by importing itself rather than the
209+ markdown library. Therefore, the script has been named ` "markdown_py" ` as a
210+ compromise. If you prefer a different name for the script on your system, it
211+ is suggested that you create a symbolic link to ` markdown_py ` with your
212+ preferred name.
213+
214+ ### Using ` markdown_py `
215+
216+ To use ` markdown_py ` from the command line, run it as
217+
218+ ``` bash
219+ markdown_py input_file.txt
220+ ```
221+
222+ or
223+
224+ ``` bash
225+ markdown_py input_file.txt > output_file.html
226+ ```
227+
228+ For a complete list of options, run
229+
230+ ``` bash
231+ markdown_py --help
232+ ```
0 commit comments