Commit 215bc50
authored
fix(pretty): Fix bug where commands and options were displayed in the… (#17)
## Pull Request: Add Support for Parsing and Rendering Command Tables in
Markdown CLI Docs
### Summary
This PR enhances the `pretty.py` module to support parsing and rendering
a **Commands** section in CLI documentation. The changes allow the
system to recognize, store, and output tables of subcommands (with names
and descriptions) in both the markdown-to-tree and tree-to-markdown
conversions.
### Details
- **New Model:**
- Added a `CommandEntry` Pydantic model to represent individual commands
with `name` and `description` fields.
- Updated the `CommandNode` model to include a `commands:
List[CommandEntry]` field.
- **Markdown Parsing (`parse_markdown_to_tree`):**
- Recognizes the `**Commands**:` section in markdown.
- Parses each command entry (name and description) and adds it to the
`commands` list of the current command node.
- Handles both the standard `* `name`: description` and fallback `*
`name`` formats.
- **Markdown Rendering (`tree_to_markdown`):**
- Adds a "Commands" table to the generated markdown if any commands are
present.
- Formats the table with columns for "Name" and "Description".
- **Other Improvements:**
- Ensures section state is correctly managed when switching between
arguments, options, and commands.
- Adds tests for edge cases in command parsing and rendering.
### Motivation
This change makes the CLI documentation more comprehensive by including
a structured list of subcommands, improving both the parsing of existing
markdown and the generation of new documentation.
### Example
A markdown section like:
```markdown
**Commands**:
* `serve`: Start the server
* `build`: Build the project
```
Will now be parsed into the tree and rendered back as a markdown table.
---
**Closes:** #161 parent a384c2a commit 215bc50
File tree
5 files changed
+82
-3
lines changed- src/mkdocs_typer2
- tests
5 files changed
+82
-3
lines changedBinary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
| |||
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
| 77 | + | |
71 | 78 | | |
72 | 79 | | |
73 | 80 | | |
| |||
81 | 88 | | |
82 | 89 | | |
83 | 90 | | |
| 91 | + | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| |||
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
| 108 | + | |
100 | 109 | | |
101 | 110 | | |
102 | 111 | | |
| |||
110 | 119 | | |
111 | 120 | | |
112 | 121 | | |
| 122 | + | |
113 | 123 | | |
114 | 124 | | |
115 | 125 | | |
116 | 126 | | |
117 | 127 | | |
118 | 128 | | |
119 | 129 | | |
| 130 | + | |
120 | 131 | | |
121 | 132 | | |
122 | | - | |
| 133 | + | |
123 | 134 | | |
124 | 135 | | |
125 | 136 | | |
| 137 | + | |
| 138 | + | |
126 | 139 | | |
127 | 140 | | |
128 | 141 | | |
| |||
147 | 160 | | |
148 | 161 | | |
149 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
150 | 180 | | |
151 | 181 | | |
152 | 182 | | |
| |||
191 | 221 | | |
192 | 222 | | |
193 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
194 | 232 | | |
195 | 233 | | |
196 | 234 | | |
| |||
213 | 251 | | |
214 | 252 | | |
215 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
216 | 257 | | |
217 | 258 | | |
218 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
0 commit comments