Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ See the [Contributing Guide](contributing.md) for details.
performance for repeated inline patterns (#1619).
* Officially support Python 3.15 and drop support for Python 3.10
* Walk backtick runs in `BacktickInlineProcessor` without a regex (#1620).
* Switch static site generator for documentation from MkDocs to Zensical
(#1627, #1635, #1637, and #1638).

### Fixed

Expand Down
75 changes: 55 additions & 20 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,56 @@ Python-Markdown's command line script takes advantage of Python's `-m` flag.
Therefore, assuming the python executable is on your system path, use the
following format:

```bash
``` shell
python -m markdown [options] [args]
```

That will run the module as a script with the options and arguments provided.

At its most basic usage, one would simply pass in a file name as the only argument:

```bash
``` shell
python -m markdown input_file.txt
```

Use the `--help` option for a list of all available options and arguments:

```bash
python -m markdown --help
``` console
$ python -m markdown --help
Usage: __main__.py [options] [INPUTFILE]
(STDIN is assumed if no INPUTFILE is given)

A Python implementation of John Gruber's Markdown. https://python-
markdown.github.io/

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-f OUTPUT_FILE, --file=OUTPUT_FILE
Write output to OUTPUT_FILE. Defaults to STDOUT.
-e ENCODING, --encoding=ENCODING
Encoding for input and output files.
-o OUTPUT_FORMAT, --output_format=OUTPUT_FORMAT
Use output format 'xhtml' (default) or 'html'.
-x EXTENSION, --extension=EXTENSION
Load extension EXTENSION.
-c CONFIG_FILE, --extension_configs=CONFIG_FILE
Read extension configurations from CONFIG_FILE.
CONFIG_FILE must be of JSON or YAML format. YAML
format requires that a python YAML library be
installed. The parsed JSON or YAML must result in a
python dictionary which would be accepted by the
'extension_configs' keyword on the markdown.Markdown
class. The extensions must also be loaded with the
`--extension` option.
-q, --quiet Suppress all warnings.
-v, --verbose Print all warnings.
--noisy Print debug messages.

WARNING: The Python-Markdown library does NOT sanitize its HTML output. If you
are processing Markdown input from an untrusted source, it is your
responsibility to ensure that it is properly sanitized. For more information
see <https://python-markdown.github.io/sanitization/>.
```

!!! warning
Expand All @@ -50,14 +84,15 @@ python -m markdown --help
Piping input and output (on `STDIN` and `STDOUT`) is fully supported.
For example:

```bash
``` shell { title="Console" }
echo "Some **Markdown** text." | python -m markdown > output.html
```

The above command would generate a file named `output.html` with the following content:
```html
/// html | div.result
```html { title='output.html'}
<p>Some <strong>Markdown</strong> Text.</p>
```
///

As Python-Markdown only ever outputs HTML fragments (no `<html>`, `<head>`,
and `<body>` tags), it is generally expected that the command line interface
Expand All @@ -67,20 +102,20 @@ otherwise empty `<html>`, `<head>`, and `<body>` tags,
[JustHTML](https://emilstenstrom.github.io/justhtml/) can do that with with
a single command:

```bash
``` shell { title="Console" }
echo "Some **Markdown** text." | python -m markdown | justhtml - --fragment > output.html
```

The above command would generate a file named `output.html` with the following content:

```html
/// html | div.result
```html { title='output.html'}
<html>
<head></head>
<body>
<p>Some <strong>Markdown</strong> Text.</p>
</body>
</html>
```
///

If you don't need or want JustHTML's HTML sanitation, you can disable it with the
`--unsafe` flag, although that is not recommended. See JustHTML's
Expand All @@ -98,27 +133,27 @@ notation to point to an extension
For example, to load an extension with the assigned entry point name `myext`,
run the following command:

```bash
``` shell
python -m markdown -x myext input.txt
```

And to load an extension with Python's dot notation:

```bash
``` shell
python -m markdown -x path.to.module:MyExtClass input.txt
```

To load multiple extensions, specify an `-x` option for each extension:

```bash
``` shell
python -m markdown -x myext -x path.to.module:MyExtClass input.txt
```

If the extension supports configuration options (see the documentation for the
extension you are using to determine what settings it supports, if any), you
can pass them in as well:

```bash
``` shell
python -m markdown -x myext -c config.yml input.txt
```

Expand All @@ -128,15 +163,15 @@ map to a Python Dictionary in the format required by the
[`extension_configs`][ec] keyword of the `markdown.Markdown` class. Therefore,
the file `config.yaml` referenced in the above example might look like this:

```yaml
``` yaml
myext:
option1: 'value1'
option2: True
```

Similarly, a JSON configuration file might look like this:

```json
``` json
{
"myext":
{
Expand Down Expand Up @@ -216,18 +251,18 @@ path.

To use `markdown_py` from the command line, run it as

```bash
``` shell
markdown_py input_file.txt
```

or

```bash
``` shell
markdown_py input_file.txt > output_file.html
```

For a complete list of options, run

```bash
``` shell
markdown_py --help
```
Loading
Loading