fix: parsing of python method arguments
- Add proper handling of typing suggestions within Python parameters. - Remove table headers to improve visual design (parameters are already within the `Parameters` section, and description is self-explanatory)
This commit is contained in:
@@ -195,10 +195,25 @@ export class PythonApiDocParser {
|
||||
|
||||
const paramList = signature?.find((ele: any) => ele.hasOwnProperty("desc_parameterlist"))?.["desc_parameterlist"];
|
||||
const parsedParams: string[] = paramList?.map((param: any) => {
|
||||
const descParam = param?.["desc_parameter"]?.[0];
|
||||
const sigName = descParam?.["desc_sig_name"]?.find((ele: any) => ele?.["#text"]);
|
||||
return sigName?.["#text"] || "";
|
||||
});
|
||||
const descParam = param?.["desc_parameter"];
|
||||
const textValues = descParam
|
||||
? descParam
|
||||
.flatMap((item: any) => {
|
||||
if (item.desc_sig_space) return [' '];
|
||||
const sigs = item.desc_sig_name || item.desc_sig_operator || item.desc_sig_punctuation || [];
|
||||
const texts = sigs.flatMap((sub: any) => {
|
||||
if (sub.desc_sig_space) return [" "];
|
||||
return [
|
||||
sub["#text"] || sub.reference?.[0]?.["#text"] || "",
|
||||
...(sub.desc_sig_punctuation?.map((p: any) => p["#text"] || "") || []),
|
||||
];
|
||||
}).filter((text: string) => text);
|
||||
return texts.join("");
|
||||
})
|
||||
.filter((text: string) => text)
|
||||
: [];
|
||||
return textValues.join("");
|
||||
})?.filter((param: string) => param) || [];
|
||||
|
||||
const content = ensureArray(functionDefinition).find((ele: any) =>
|
||||
ele.hasOwnProperty("desc_content")
|
||||
@@ -364,7 +379,7 @@ export class PythonApiDocParser {
|
||||
stream += this.writeFrontMatter(module.name, `${module.name} Module Reference`);
|
||||
stream += `${module.description}\n\n`;
|
||||
if (module.functions.length > 0) {
|
||||
stream += "# Functions\n\n";
|
||||
stream += "## Functions\n\n";
|
||||
for (const func of module.functions) {
|
||||
stream += this.writeFunction(func);
|
||||
}
|
||||
@@ -374,7 +389,7 @@ export class PythonApiDocParser {
|
||||
|
||||
private writeFunction(func: PythonApiDocFunction) {
|
||||
let stream = "";
|
||||
stream += "## " + func.name + "\n\n";
|
||||
stream += "### " + func.name + "\n\n";
|
||||
if (func.definition) {
|
||||
let definition = func.definition.includes('->') ? func.definition : func.definition + " -> " + func.returns.type;
|
||||
stream += "```python\n" + definition + "\n```\n";
|
||||
@@ -386,8 +401,8 @@ export class PythonApiDocParser {
|
||||
}
|
||||
if (func.params.length > 0) {
|
||||
stream += "##### Parameters\n\n";
|
||||
const rows = func.params.map((param) => [`\`${param.name}\``, param.type, param.description]);
|
||||
stream += this.generateMarkdownTable(["Parameter Name", "Type", "Description"], rows) + "\n\n";
|
||||
const rows = func.params.map((param) => [`\`${param.name}\``, param.description]);
|
||||
stream += this.generateMarkdownTable([" ", " "], rows) + "\n\n";
|
||||
}
|
||||
if (func.example) {
|
||||
stream += "##### Example\n\n";
|
||||
|
||||
Reference in New Issue
Block a user