import { marked } from "marked";
import type { PropItem } from "react-docgen-typescript";
import { getPropTypeText } from "./getPropTypeText.ts";
const TABLE_TAG_START = `
| Name |
Description |
`;
const PROP_ROW = `
| [[name]] |
[[description]] |
`;
const TABLE_TAG_STOP = `
`;
export async function propsToTable(props: PropItem[]) {
const htmlStrings = [];
if (props.length > 0) {
htmlStrings.push(TABLE_TAG_START);
for (const prop of props) {
const type = getPropTypeText(prop);
const description = await marked(prop.description);
htmlStrings.push(
PROP_ROW.replace("[[name]]", prop.name)
.replace("[[type]]", type)
.replace("[[description]]", description)
);
}
htmlStrings.push(TABLE_TAG_STOP);
}
return htmlStrings.join("");
}