MCPcopy Create free account
hub / github.com/PRQL/prql / generate_markdown_docs

Function generate_markdown_docs

prqlc/prqlc/src/cli/docs_generator.rs:175–309  ·  view source on GitHub ↗

Generate Markdown documentation.

(stmts: Vec<Stmt>)

Source from the content-addressed store, hash-verified

173
174/// Generate Markdown documentation.
175pub fn generate_markdown_docs(stmts: Vec<Stmt>) -> String {
176 let markdown = format!(
177 r#"# Documentation
178
179{{{{ content }}}}
180
181Generated with [prqlc](https://prql-lang.org/) {}.
182"#,
183 prqlc::compiler_version()
184 );
185
186 let mut docs = String::new();
187
188 docs.push_str("## Functions\n");
189 for stmt in stmts
190 .clone()
191 .into_iter()
192 .filter(|stmt| matches!(stmt.kind, StmtKind::VarDef(_)))
193 {
194 let var_def = stmt.kind.as_var_def().unwrap();
195 docs.push_str(&format!("* [{}](#{})\n", var_def.name, var_def.name));
196 }
197 docs.push('\n');
198
199 if stmts
200 .clone()
201 .into_iter()
202 .filter(|stmt| matches!(stmt.kind, StmtKind::VarDef(_)))
203 .count()
204 == 0
205 {
206 docs.push_str("None.\n\n");
207 }
208
209 if stmts
210 .clone()
211 .into_iter()
212 .filter(|stmt| matches!(stmt.kind, StmtKind::TypeDef(_)))
213 .count()
214 > 0
215 {
216 docs.push_str("## Types\n");
217 for stmt in stmts
218 .clone()
219 .into_iter()
220 .filter(|stmt| matches!(stmt.kind, StmtKind::TypeDef(_)))
221 {
222 let type_def = stmt.kind.as_type_def().unwrap();
223 docs.push_str(&format!(
224 "* `{}` – {:?}\n",
225 type_def.name, type_def.value.kind
226 ));
227 }
228 docs.push('\n');
229 }
230
231 if stmts
232 .clone()

Callers 1

executeMethod · 0.85

Calls 3

into_iterMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected