Skip to content

Commit

Permalink
fix: Add new line after tags (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jun 30, 2022
1 parent 15bda2f commit 396121e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Handlebars from 'handlebars';
import { Comment } from 'typedoc';
import { camelToTitleCase } from '../../utils';

export default function () {
Handlebars.registerHelper('comments', function (comment: Comment) {
Expand All @@ -14,9 +15,9 @@ export default function () {
.filter((tag) => tag.tag !== '@returns')
.map(
(tag) =>
`**\`${tag.tag.substring(1)}\`** ${Handlebars.helpers.comment(
tag.content,
)}`,
`**\`${camelToTitleCase(
tag.tag.substring(1),
)}\`**\n\n ${Handlebars.helpers.comment(tag.content)}`,
);
md.push(tags.join('\n\n'));
}
Expand Down
7 changes: 7 additions & 0 deletions packages/typedoc-plugin-markdown/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ export function stripLineBreaks(str: string) {
? str.replace(/\n/g, ' ').replace(/\r/g, ' ').replace(/\t/g, ' ').trim()
: '';
}

export function camelToTitleCase(text: string) {
return (
text.substring(0, 1).toUpperCase() +
text.substring(1).replace(/[a-z][A-Z]/g, (x) => `${x[0]} ${x[1]}`)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,24 @@ include:class-example.hbs
`;

exports[`Comments: should convert comments with tags' 1`] = `
"**\`name\`** Tag description on same line
"**\`Description\`**
**\`description\`** Tag description on new line
Tag description on new line
- Tag description on another line
**\`deprecated\`** Another tag description
**\`Deprecated\`**
Another tag description
Gets the application version.
**\`Example\`**
\`\`\`typescript
import { getVersion } from '@tauri-apps/api/app';
const appVersion = await getVersion();
\`\`\`
"
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,17 @@ exports[`Declarations: should compile object literal cast as a const 1`] = `
Comments
**\`param\`** Comment for object.
**\`Param\`**
**\`param\`** Comment for Prop1.
Comment for object.
**\`param\`** Comment for Prop2.
**\`Param\`**
Comment for Prop1.
**\`Param\`**
Comment for Prop2.
#### Type declaration
Expand All @@ -147,11 +153,17 @@ Comments
exports[`Declarations: should compile object literal declaration 1`] = `
"• \`Const\` **objectLiteralDeclaration**: \`Object\`
**\`param\`** description for valueX
**\`Param\`**
description for valueX
**\`Param\`**
description for valueZ
**\`param\`** description for valueZ
**\`Param\`**
**\`param\`** description for valueY
description for valueY
#### Type declaration
Expand Down
8 changes: 7 additions & 1 deletion test/stubs/src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ export const commentsWithHTML = true;
export const commentsWithIncludes = true;

/**
* @name Tag description on same line
* @description
* Tag description on new line
*
* - Tag description on another line
*
* @deprecated
* Another tag description
*
* Gets the application version.
* @example
* ```typescript
* import { getVersion } from '@tauri-apps/api/app';
* const appVersion = await getVersion();
* ```
*/
export const commentsWithTags = true;

Expand Down

0 comments on commit 396121e

Please sign in to comment.