Skip to content

Commit d14f915

Browse files
authored
📚 DOCS: Improve documentation for CLI (#54)
1 parent a4b828c commit d14f915

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ or
3535
pip install markdown-it-py
3636
```
3737

38-
## Basic usage
38+
## Usage
39+
40+
### Python API Usage
41+
Render markdown to HTML with markdown-it-py and a custom configuration
42+
with and without plugins and features:
3943

4044
```python
4145
from markdown_it import MarkdownIt
@@ -66,17 +70,39 @@ tokens = md.parse(text)
6670
html_text = md.render(text)
6771
```
6872

69-
Also you can use it from the command-line:
73+
### Command-line Usage
74+
Render markdown to HTML with markdown-it-py from the
75+
command-line:
7076

7177
```console
72-
$ markdown-it
73-
markdown-it-py [version 0.1.0] (interactive)
74-
Type Ctrl-D to complete input, or Ctrl-C to exit.
75-
>>> > **hallo** there!
76-
...
77-
<blockquote>
78-
<p><strong>hallo</strong> there!</p>
79-
</blockquote>
78+
usage: markdown-it [-h] [-v] [filenames [filenames ...]]
79+
80+
Parse one or more markdown files, convert each to HTML, and print to stdout
81+
82+
positional arguments:
83+
filenames specify an optional list of files to convert
84+
85+
optional arguments:
86+
-h, --help show this help message and exit
87+
-v, --version show program's version number and exit
88+
89+
Interactive:
90+
91+
$ markdown-it
92+
markdown-it-py [version 0.0.0] (interactive)
93+
Type Ctrl-D to complete input, or Ctrl-C to exit.
94+
>>> # Example
95+
... > markdown *input*
96+
...
97+
<h1>Example</h1>
98+
<blockquote>
99+
<p>markdown <em>input</em></p>
100+
</blockquote>
101+
102+
Batch:
103+
104+
$ markdown-it README.md README.footer.md > index.html
105+
80106
```
81107

82108
## References / Thanks

markdown_it/cli/parse.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
from argparse import ArgumentParser
1+
#!/usr/bin/env python
2+
"""
3+
CLI interface to markdown-it-py
4+
5+
Parse one or more markdown files, convert each to HTML, and print to stdout.
6+
"""
7+
import argparse
28
import sys
39

410
from markdown_it import __version__
@@ -59,7 +65,32 @@ def interactive(import_readline=False):
5965

6066
def parse_args(args):
6167
"""Parse input CLI arguments."""
62-
parser = ArgumentParser()
68+
parser = argparse.ArgumentParser(
69+
description="Parse one or more markdown files, "
70+
"convert each to HTML, and print to stdout",
71+
# NOTE: Remember to update README.md w/ the output of `markdown-it -h`
72+
epilog=(
73+
"""
74+
Interactive:
75+
76+
$ markdown-it
77+
markdown-it-py [version 0.0.0] (interactive)
78+
Type Ctrl-D to complete input, or Ctrl-C to exit.
79+
>>> # Example
80+
... > markdown *input*
81+
...
82+
<h1>Example</h1>
83+
<blockquote>
84+
<p>markdown <em>input</em></p>
85+
</blockquote>
86+
87+
Batch:
88+
89+
$ markdown-it README.md README.footer.md > index.html
90+
"""
91+
),
92+
formatter_class=argparse.RawDescriptionHelpFormatter,
93+
)
6394
parser.add_argument("-v", "--version", action="version", version=version_str)
6495
parser.add_argument(
6596
"filenames", nargs="*", help="specify an optional list of files to convert"

0 commit comments

Comments
 (0)