Skip to content

Commit aca9a93

Browse files
committed
Reorganize cli.md for clarity
1 parent 46096dd commit aca9a93

File tree

2 files changed

+104
-69
lines changed

2 files changed

+104
-69
lines changed

.spell-dict

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ munge
7878
namespace
7979
NanoDOM
8080
Neale
81-
nh3
8281
nosetests
8382
OrderedDict
8483
OrderedDicts

docs/cli.md

Lines changed: 104 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Generally, you will want to have the Markdown library fully installed on your
1212
system to run the command line script. See the
1313
[Installation instructions](install.md) for details.
1414

15+
## Basic Usage
16+
1517
Python-Markdown's command line script takes advantage of Python's `-m` flag.
1618
Therefore, assuming the python executable is on your system path, use the
1719
following format:
@@ -28,13 +30,6 @@ At its most basic usage, one would simply pass in a file name as the only argume
2830
python -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-
3833
Use the `--help` option for a list of all available options and arguments:
3934

4035
```bash
@@ -48,79 +43,49 @@ python -m markdown --help
4843
responsibility to ensure that it is properly sanitized. For more
4944
information see [Sanitizing HTML Output](sanitization.md).
5045

51-
If you don't want to call the python executable directly (using the `-m` flag),
52-
follow the instructions below to use a wrapper script:
53-
54-
Setup
55-
-----
56-
57-
Upon installation, the `markdown_py` script will have been copied to
58-
your Python "Scripts" directory. Different systems require different methods to
59-
ensure that any files in the Python "Scripts" directory are on your system
60-
path.
61-
62-
* **Windows**:
63-
64-
Assuming a default install of Python on Windows, your "Scripts" directory
65-
is most likely something like `C:\\Python37\Scripts`. Verify the location
66-
of your "Scripts" directory and add it to you system path.
67-
68-
Calling `markdown_py` from the command line will call the wrapper batch
69-
file `markdown_py.bat` in the `"Scripts"` directory created during install.
70-
71-
* __*nix__ (Linux, OSX, BSD, Unix, etc.):
72-
73-
As each \*nix distribution is different and we can't possibly document all
74-
of them here, we'll provide a few helpful pointers:
75-
76-
* Some systems will automatically install the script on your path. Try it
77-
and see if it works. Just run `markdown_py` from the command line.
78-
79-
* Other systems may maintain a separate "Scripts" ("bin") directory which
80-
you need to add to your path. Find it (check with your distribution) and
81-
either add it to your path or make a symbolic link to it from your path.
82-
83-
* If you are sure `markdown_py` is on your path, but it still is not being
84-
found, check the permissions of the file and make sure it is executable.
85-
86-
As an alternative, you could just `cd` into the directory which contains
87-
the source distribution, and run it from there. However, remember that your
88-
markdown text files will not likely be in that directory, so it is much
89-
more convenient to have `markdown_py` on your path.
90-
91-
!!!Note
92-
Python-Markdown uses `"markdown_py"` as a script name because the Perl
93-
implementation has already taken the more obvious name "markdown".
94-
Additionally, the default Python configuration on some systems would cause a
95-
script named `"markdown.py"` to fail by importing itself rather than the
96-
markdown library. Therefore, the script has been named `"markdown_py"` as a
97-
compromise. If you prefer a different name for the script on your system, it
98-
is suggested that you create a symbolic link to `markdown_py` with your
99-
preferred name.
100-
101-
Usage
102-
-----
46+
## Piping Input and Output
10347

104-
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:
10550

10651
```bash
107-
markdown_py input_file.txt
52+
echo "Some **Markdown** text." | python -m markdown > output.html
10853
```
10954

110-
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:
11167

11268
```bash
113-
markdown_py input_file.txt > output_file.html
69+
echo "Some **Markdown** text." | python -m markdown | justhtml - --fragment > output.html
11470
```
11571

116-
For a complete list of options, run
72+
The above command would generate a file named `output.html` with the following content:
11773

118-
```bash
119-
markdown_py --help
74+
```html
75+
<html>
76+
<head></head>
77+
<body>
78+
<p>Some <strong>Markdown</strong> Text.</p>
79+
</body>
80+
</html>
12081
```
12182

122-
Using Extensions
123-
----------------
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
12489

12590
To load a Python-Markdown extension from the command line use the `-x`
12691
(or `--extension`) option. The extension module must be on your `PYTHONPATH`
@@ -194,3 +159,74 @@ dependencies. The format of your configuration file is automatically detected.
194159
[JSON]: https://json.org/
195160
[PyYAML]: https://pyyaml.org/
196161
[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

Comments
 (0)