-
Notifications
You must be signed in to change notification settings - Fork 374
chore(repo): typedoc - Render accessors to markdown in the same fashion as properties #6532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -218,9 +218,69 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const customizedModel = model; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
customizedModel.typeParameters = undefined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const output = superPartials.memberWithGroups(customizedModel, options); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Extract the Accessors group (if any) and prevent default rendering for it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const originalGroups = customizedModel.groups; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const accessorsGroup = originalGroups?.find(g => g.title === 'Accessors'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const groupsWithoutAccessors = originalGroups?.filter(g => g.title !== 'Accessors'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
customizedModel.groups = groupsWithoutAccessors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const nonAccessorOutput = superPartials.memberWithGroups(customizedModel, options); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
customizedModel.groups = originalGroups; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** @type {string[]} */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const md = [nonAccessorOutput]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (accessorsGroup && accessorsGroup.children && accessorsGroup.children.length > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
md.push('\n\n## Accessors\n'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Table header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// This needs to be 'Property' instead of 'Accessor' so that clerk.com renders it correctly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
md.push('| Property | Type | Description |'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
md.push('| --- | --- | --- |'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (const child of accessorsGroup.children) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** @type {import('typedoc').DeclarationReflection} */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// @ts-ignore - child is a DeclarationReflection for accessor members | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const decl = child; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Name and anchor id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const name = decl.name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const id = name.toLowerCase().replace(/[^a-z0-9]/g, ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Resolve the accessor type from the getter signature | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** @type {any} */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const getterSig = /** @type {any} */ (decl).getSignature; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** @type {any} */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const setterSig = /** @type {any} */ (decl).setSignature; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let typeStr = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (getterSig?.type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
typeStr = this.partials.someType(getterSig.type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (setterSig?.parameters?.[0]?.type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
typeStr = this.partials.someType(setterSig.parameters[0].type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (decl.type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
typeStr = this.partials.someType(decl.type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Prefer comment on the getter signature; fallback to declaration comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const summary = getterSig?.comment?.summary ?? decl.comment?.summary ?? setterSig?.comment?.summary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const description = Array.isArray(summary) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
? summary.reduce((acc, curr) => acc + (curr.text || ''), '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
: ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
md.push(`| <a id="${id}"></a> \`${escapeChars(name)}\` | ${typeStr} | ${description} |`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return md.join('\n'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Suppress default per-accessor member rendering; table is rendered in memberWithGroups instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param {import('typedoc').DeclarationReflection} model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param {{ headingLevel: number, nested?: boolean }} options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
member: (model, options) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (model.kind === ReflectionKind.Accessor) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return superPartials.member(model, options); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* This hides the "Type parameters" section and the declaration title from the output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -412,6 +472,17 @@ ${tabs} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Hide "Extends" and "Extended by" sections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hierarchy: () => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param {import('typedoc').DeclarationReflection} model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
accessor: model => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Fallback single-row rendering if used directly elsewhere | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const name = model.name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const typeStr = model.getSignature?.type ? this.partials.someType(model.getSignature.type) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const summary = model.getSignature?.comment?.summary ?? model.comment?.summary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const description = Array.isArray(summary) ? summary.reduce((acc, curr) => acc + (curr.text || ''), '') : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return '| ' + '`' + escapeChars(name) + '`' + ' | ' + typeStr + ' | ' + description + ' |'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+475
to
486
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Align fallback accessor partial with main table logic For consistency, compute type from getter or setter (with fallback placeholder) and use getCommentParts for the description. This keeps standalone accessor rendering consistent with the table. Apply this diff: - accessor: model => {
- // Fallback single-row rendering if used directly elsewhere
- const name = model.name;
- const typeStr = model.getSignature?.type ? this.partials.someType(model.getSignature.type) : '';
- const summary = model.getSignature?.comment?.summary ?? model.comment?.summary;
- const description = Array.isArray(summary) ? summary.reduce((acc, curr) => acc + (curr.text || ''), '') : '';
- return '| ' + '`' + escapeChars(name) + '`' + ' | ' + typeStr + ' | ' + description + ' |';
- },
+ accessor: model => {
+ // Fallback single-row rendering if used directly elsewhere
+ const name = model.name;
+ let typeStr = '';
+ if (model.getSignature?.type) {
+ typeStr = this.partials.someType(model.getSignature.type);
+ } else if (model.setSignature?.parameters?.[0]?.type) {
+ typeStr = this.partials.someType(model.setSignature.parameters[0].type);
+ } else if (model.type) {
+ typeStr = this.partials.someType(model.type);
+ }
+ if (!typeStr) {
+ typeStr = '—';
+ }
+ const summaryParts =
+ model.getSignature?.comment?.summary ?? model.comment?.summary ?? model.setSignature?.comment?.summary;
+ const description = summaryParts ? this.helpers.getCommentParts(summaryParts) : '';
+ return '| ' + '`' + escapeChars(name) + '`' + ' | ' + typeStr + ' | ' + description + ' |';
+ }, 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use getCommentParts for descriptions and add a safe fallback for empty types
Two improvements:
Apply this diff:
Optional: to minimize potential ID collisions, consider prefixing the anchor with the parent name (e.g.,
${decl.parent?.name}-${name}
) before sanitizing.📝 Committable suggestion
🤖 Prompt for AI Agents