Skip to content

Commit

Permalink
fix(Formatters): add newline in codeBlock (#8369)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Jul 27, 2022
1 parent e9920a9 commit 5d8bd03
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/builders/__tests__/messages/formatters.test.ts
Expand Up @@ -24,11 +24,11 @@ import {
describe('Message formatters', () => {
describe('codeBlock', () => {
test('GIVEN "discord.js" with no language THEN returns "```\\ndiscord.js```"', () => {
expect<'```\ndiscord.js```'>(codeBlock('discord.js')).toEqual('```\ndiscord.js```');
expect<'```\ndiscord.js\n```'>(codeBlock('discord.js')).toEqual('```\ndiscord.js\n```');
});

test('GIVEN "discord.js" with "js" as language THEN returns "```js\\ndiscord.js```"', () => {
expect<'```js\ndiscord.js```'>(codeBlock('js', 'discord.js')).toEqual('```js\ndiscord.js```');
expect<'```js\ndiscord.js\n```'>(codeBlock('js', 'discord.js')).toEqual('```js\ndiscord.js\n```');
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/builders/src/messages/formatters.ts
Expand Up @@ -6,17 +6,17 @@ import type { Snowflake } from 'discord-api-types/globals';
*
* @param content - The content to wrap
*/
export function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\`\`\``;
export function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\n\`\`\``;

/**
* Wraps the content inside a codeblock with the specified language
*
* @param language - The language for the codeblock
* @param content - The content to wrap
*/
export function codeBlock<L extends string, C extends string>(language: L, content: C): `\`\`\`${L}\n${C}\`\`\``;
export function codeBlock<L extends string, C extends string>(language: L, content: C): `\`\`\`${L}\n${C}\n\`\`\``;
export function codeBlock(language: string, content?: string): string {
return typeof content === 'undefined' ? `\`\`\`\n${language}\`\`\`` : `\`\`\`${language}\n${content}\`\`\``;
return typeof content === 'undefined' ? `\`\`\`\n${language}\n\`\`\`` : `\`\`\`${language}\n${content}\n\`\`\``;
}

/**
Expand Down

0 comments on commit 5d8bd03

Please sign in to comment.