diff --git a/.changeset/pink-steaks-invent.md b/.changeset/pink-steaks-invent.md new file mode 100644 index 000000000..bd60db21c --- /dev/null +++ b/.changeset/pink-steaks-invent.md @@ -0,0 +1,5 @@ +--- +'typedoc-plugin-markdown': patch +--- + +- Enhanced the formatting and structure of accessor output (#711) diff --git a/packages/typedoc-plugin-markdown/src/theme/context/partials/member.accessor.ts b/packages/typedoc-plugin-markdown/src/theme/context/partials/member.accessor.ts index 4a51d13da..b6df38c37 100644 --- a/packages/typedoc-plugin-markdown/src/theme/context/partials/member.accessor.ts +++ b/packages/typedoc-plugin-markdown/src/theme/context/partials/member.accessor.ts @@ -10,6 +10,12 @@ export function accessor( const md: string[] = []; if (model.getSignature) { + md.push( + heading( + options.headingLevel, + this.internationalization.proxy.kind_get_signature(), + ), + ); md.push( this.partials.signatureTitle(model.getSignature, { accessor: 'get', @@ -18,46 +24,60 @@ export function accessor( if (model.getSignature.comment) { md.push( this.partials.comment(model.getSignature.comment, { - headingLevel: options.headingLevel, + headingLevel: options.headingLevel + 1, + }), + ); + } + if (model.getSignature?.type) { + md.push( + this.partials.signatureReturns(model.getSignature, { + headingLevel: options.headingLevel + 1, }), ); } } if (model.setSignature) { + md.push( + heading( + options.headingLevel, + this.internationalization.proxy.kind_set_signature(), + ), + ); md.push( this.partials.signatureTitle(model.setSignature, { accessor: 'set', }), ); + if (model.setSignature.comment) { md.push( this.partials.comment(model.setSignature.comment, { - headingLevel: options.headingLevel, + headingLevel: options.headingLevel + 1, }), ); } - } - if (model.setSignature?.parameters?.length) { - md.push( - heading( - options.headingLevel, - this.internationalization.kindPluralString(ReflectionKind.Parameter), - ), - ); - if (this.helpers.useTableFormat('parameters')) { - md.push(this.partials.parametersTable(model.setSignature.parameters)); - } else { - md.push(this.partials.parametersList(model.setSignature.parameters)); + if (model.setSignature?.parameters?.length) { + md.push( + heading( + options.headingLevel + 1, + this.internationalization.kindPluralString(ReflectionKind.Parameter), + ), + ); + if (this.helpers.useTableFormat('parameters')) { + md.push(this.partials.parametersTable(model.setSignature.parameters)); + } else { + md.push(this.partials.parametersList(model.setSignature.parameters)); + } } - } - if (model.getSignature?.type) { - md.push( - this.partials.signatureReturns(model.getSignature, { - headingLevel: options.headingLevel, - }), - ); + if (model.setSignature?.type) { + md.push( + this.partials.signatureReturns(model.setSignature, { + headingLevel: options.headingLevel + 1, + }), + ); + } } if (model.comment) { diff --git a/packages/typedoc-plugin-markdown/src/theme/context/partials/member.signatureTitle.ts b/packages/typedoc-plugin-markdown/src/theme/context/partials/member.signatureTitle.ts index 996060c7a..1076c44c1 100644 --- a/packages/typedoc-plugin-markdown/src/theme/context/partials/member.signatureTitle.ts +++ b/packages/typedoc-plugin-markdown/src/theme/context/partials/member.signatureTitle.ts @@ -21,7 +21,7 @@ export function signatureTitle( } if (options?.accessor) { - md.push(backTicks(options?.accessor) + ' '); + md.push(bold(options?.accessor) + ' '); } if (model.parent) { diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap index 9b7501c4a..750d21562 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap @@ -556,35 +556,51 @@ comment for y.z ### accessorA -> \`get\` **accessorA**(): [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> +#### Get Signature + +> **get** **accessorA**(): [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> Comments for accessorA getter -> \`set\` **accessorA**(\`x\`: [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\>): \`void\` +##### Returns + +[\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> + +#### Set Signature + +> **set** **accessorA**(\`x\`: [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\>): \`void\` Comments for accessorA setter -#### Parameters +##### Parameters • **x**: [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> -#### Returns +##### Returns -[\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> +\`void\` ### accessorB -> \`get\` **accessorB**(): \`string\` +#### Get Signature -> \`set\` **accessorB**(\`x\`: \`string\`): \`void\` +> **get** **accessorB**(): \`string\` -#### Parameters +##### Returns + +\`string\` + +#### Set Signature + +> **set** **accessorB**(\`x\`: \`string\`): \`void\` + +##### Parameters • **x**: \`string\` -#### Returns +##### Returns -\`string\` +\`void\` ### someFunction() @@ -707,47 +723,63 @@ z: (x: string) => string; ### accessorA +#### Get Signature + \`\`\`ts get accessorA(): Promise \`\`\` Comments for accessorA getter +##### Returns + +[\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> + +#### Set Signature + \`\`\`ts set accessorA(x: Promise): void \`\`\` Comments for accessorA setter -#### Parameters +##### Parameters | Parameter | Type | | :------ | :------ | | \`x\` | [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> | -#### Returns +##### Returns -[\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> +\`void\` ### accessorB +#### Get Signature + \`\`\`ts get accessorB(): string \`\`\` +##### Returns + +\`string\` + +#### Set Signature + \`\`\`ts set accessorB(x: string): void \`\`\` -#### Parameters +##### Parameters | Parameter | Type | | :------ | :------ | | \`x\` | \`string\` | -#### Returns +##### Returns -\`string\` +\`void\` ### someFunction() diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap index 8fb85e2ac..be3f2668b 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap @@ -266,23 +266,31 @@ Comments for ClassWithAccessors ### accessor -> \`get\` **accessor**(): \`string\` +#### Get Signature + +> **get** **accessor**(): \`string\` Comments for getter -> \`set\` **accessor**(\`value\`): \`void\` +##### Returns + +\`string\` + +#### Set Signature + +> **set** **accessor**(\`value\`): \`void\` Comments for setter -#### Parameters +##### Parameters • **value**: \`string\` Param comments -#### Returns +##### Returns -\`string\` +\`void\` #### Source @@ -292,12 +300,18 @@ Param comments ### noGetter -> \`set\` **noGetter**(\`x\`): \`void\` +#### Set Signature -#### Parameters +> **set** **noGetter**(\`x\`): \`void\` + +##### Parameters • **x**: \`string\` +##### Returns + +\`void\` + #### Source [classes.ts:1](http://source-url) @@ -306,9 +320,11 @@ Param comments ### noSetter -> \`get\` **noSetter**(): \`string\` +#### Get Signature -#### Returns +> **get** **noSetter**(): \`string\` + +##### Returns \`string\` @@ -345,27 +361,35 @@ new ClassWithAccessors(): ClassWithAccessors ### accessor +#### Get Signature + \`\`\`ts get accessor(): string \`\`\` Comments for getter +##### Returns + +\`string\` + +#### Set Signature + \`\`\`ts set accessor(value: string): void \`\`\` Comments for setter -#### Parameters +##### Parameters | Parameter | Type | Description | | :------ | :------ | :------ | | \`value\` | \`string\` | Param comments | -#### Returns +##### Returns -\`string\` +\`void\` #### Source @@ -375,16 +399,22 @@ Comments for setter ### noGetter +#### Set Signature + \`\`\`ts set noGetter(x: string): void \`\`\` -#### Parameters +##### Parameters | Parameter | Type | | :------ | :------ | | \`x\` | \`string\` | +##### Returns + +\`void\` + #### Source [classes.ts:1](http://source-url) @@ -393,11 +423,13 @@ set noGetter(x: string): void ### noSetter +#### Get Signature + \`\`\`ts get noSetter(): string \`\`\` -#### Returns +##### Returns \`string\` diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.type-alias.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.type-alias.spec.ts.snap index b52330629..d8c1fca2d 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.type-alias.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.type-alias.spec.ts.snap @@ -165,35 +165,51 @@ comment for y.z ### accessorA -> \`get\` **accessorA**(): [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> +#### Get Signature + +> **get** **accessorA**(): [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> Comments for accessorA getter -> \`set\` **accessorA**(\`x\`): \`void\` +##### Returns + +[\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> + +#### Set Signature + +> **set** **accessorA**(\`x\`): \`void\` Comments for accessorA setter -#### Parameters +##### Parameters • **x**: [\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> -#### Returns +##### Returns -[\`Promise\`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)\\<\`string\`\\> +\`void\` ### accessorB -> \`get\` **accessorB**(): \`string\` +#### Get Signature -> \`set\` **accessorB**(\`x\`): \`void\` +> **get** **accessorB**(): \`string\` -#### Parameters +##### Returns + +\`string\` + +#### Set Signature + +> **set** **accessorB**(\`x\`): \`void\` + +##### Parameters • **x**: \`string\` -#### Returns +##### Returns -\`string\` +\`void\` ### someFunction()