File tree Expand file tree Collapse file tree 2 files changed +69
-12
lines changed Expand file tree Collapse file tree 2 files changed +69
-12
lines changed Original file line number Diff line number Diff line change 35
35
pip install markdown-it-py
36
36
```
37
37
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:
39
43
40
44
``` python
41
45
from markdown_it import MarkdownIt
@@ -66,17 +70,39 @@ tokens = md.parse(text)
66
70
html_text = md.render(text)
67
71
```
68
72
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:
70
76
71
77
``` 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
+
80
106
```
81
107
82
108
## References / Thanks
Original file line number Diff line number Diff line change 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
2
8
import sys
3
9
4
10
from markdown_it import __version__
@@ -59,7 +65,32 @@ def interactive(import_readline=False):
59
65
60
66
def parse_args (args ):
61
67
"""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
+ )
63
94
parser .add_argument ("-v" , "--version" , action = "version" , version = version_str )
64
95
parser .add_argument (
65
96
"filenames" , nargs = "*" , help = "specify an optional list of files to convert"
You can’t perform that action at this time.
0 commit comments