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 paramList = signature?.find((ele: any) => ele.hasOwnProperty("desc_parameterlist"))?.["desc_parameterlist"];
|
||||||
const parsedParams: string[] = paramList?.map((param: any) => {
|
const parsedParams: string[] = paramList?.map((param: any) => {
|
||||||
const descParam = param?.["desc_parameter"]?.[0];
|
const descParam = param?.["desc_parameter"];
|
||||||
const sigName = descParam?.["desc_sig_name"]?.find((ele: any) => ele?.["#text"]);
|
const textValues = descParam
|
||||||
return sigName?.["#text"] || "";
|
? 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) =>
|
const content = ensureArray(functionDefinition).find((ele: any) =>
|
||||||
ele.hasOwnProperty("desc_content")
|
ele.hasOwnProperty("desc_content")
|
||||||
@@ -364,7 +379,7 @@ export class PythonApiDocParser {
|
|||||||
stream += this.writeFrontMatter(module.name, `${module.name} Module Reference`);
|
stream += this.writeFrontMatter(module.name, `${module.name} Module Reference`);
|
||||||
stream += `${module.description}\n\n`;
|
stream += `${module.description}\n\n`;
|
||||||
if (module.functions.length > 0) {
|
if (module.functions.length > 0) {
|
||||||
stream += "# Functions\n\n";
|
stream += "## Functions\n\n";
|
||||||
for (const func of module.functions) {
|
for (const func of module.functions) {
|
||||||
stream += this.writeFunction(func);
|
stream += this.writeFunction(func);
|
||||||
}
|
}
|
||||||
@@ -374,7 +389,7 @@ export class PythonApiDocParser {
|
|||||||
|
|
||||||
private writeFunction(func: PythonApiDocFunction) {
|
private writeFunction(func: PythonApiDocFunction) {
|
||||||
let stream = "";
|
let stream = "";
|
||||||
stream += "## " + func.name + "\n\n";
|
stream += "### " + func.name + "\n\n";
|
||||||
if (func.definition) {
|
if (func.definition) {
|
||||||
let definition = func.definition.includes('->') ? func.definition : func.definition + " -> " + func.returns.type;
|
let definition = func.definition.includes('->') ? func.definition : func.definition + " -> " + func.returns.type;
|
||||||
stream += "```python\n" + definition + "\n```\n";
|
stream += "```python\n" + definition + "\n```\n";
|
||||||
@@ -386,8 +401,8 @@ export class PythonApiDocParser {
|
|||||||
}
|
}
|
||||||
if (func.params.length > 0) {
|
if (func.params.length > 0) {
|
||||||
stream += "##### Parameters\n\n";
|
stream += "##### Parameters\n\n";
|
||||||
const rows = func.params.map((param) => [`\`${param.name}\``, param.type, param.description]);
|
const rows = func.params.map((param) => [`\`${param.name}\``, param.description]);
|
||||||
stream += this.generateMarkdownTable(["Parameter Name", "Type", "Description"], rows) + "\n\n";
|
stream += this.generateMarkdownTable([" ", " "], rows) + "\n\n";
|
||||||
}
|
}
|
||||||
if (func.example) {
|
if (func.example) {
|
||||||
stream += "##### Example\n\n";
|
stream += "##### Example\n\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user