From 396121e63db25b028b91fb935c7b1fbe8b25d9c4 Mon Sep 17 00:00:00 2001 From: tgreyuk Date: Thu, 30 Jun 2022 18:12:14 +0100 Subject: [PATCH] fix: Add new line after tags (#324) --- .../src/resources/helpers/comments.ts | 7 +++--- packages/typedoc-plugin-markdown/src/utils.ts | 7 ++++++ .../specs/__snapshots__/comments.spec.ts.snap | 17 ++++++++++--- .../__snapshots__/declarations.spec.ts.snap | 24 ++++++++++++++----- test/stubs/src/comments.ts | 8 ++++++- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/packages/typedoc-plugin-markdown/src/resources/helpers/comments.ts b/packages/typedoc-plugin-markdown/src/resources/helpers/comments.ts index 578e72a6a..e528077a3 100644 --- a/packages/typedoc-plugin-markdown/src/resources/helpers/comments.ts +++ b/packages/typedoc-plugin-markdown/src/resources/helpers/comments.ts @@ -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) { @@ -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')); } diff --git a/packages/typedoc-plugin-markdown/src/utils.ts b/packages/typedoc-plugin-markdown/src/utils.ts index fa50aa175..1c6f16c7f 100644 --- a/packages/typedoc-plugin-markdown/src/utils.ts +++ b/packages/typedoc-plugin-markdown/src/utils.ts @@ -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]}`) + ); +} diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap index f4d6da422..291804236 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/comments.spec.ts.snap @@ -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(); +\`\`\` " `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap index 3d8507cf9..6d3343294 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/declarations.spec.ts.snap @@ -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 @@ -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 diff --git a/test/stubs/src/comments.ts b/test/stubs/src/comments.ts index d041a7da3..934034ade 100644 --- a/test/stubs/src/comments.ts +++ b/test/stubs/src/comments.ts @@ -39,7 +39,6 @@ export const commentsWithHTML = true; export const commentsWithIncludes = true; /** - * @name Tag description on same line * @description * Tag description on new line * @@ -47,6 +46,13 @@ export const commentsWithIncludes = true; * * @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;