fix(Formatters): add newline in codeBlock (#8369)

This commit is contained in:
A. Román
2022-07-27 12:09:34 +02:00
committed by GitHub
parent e9920a9c98
commit 5d8bd030d6
2 changed files with 5 additions and 5 deletions

View File

@@ -24,11 +24,11 @@ import {
describe('Message formatters', () => { describe('Message formatters', () => {
describe('codeBlock', () => { describe('codeBlock', () => {
test('GIVEN "discord.js" with no language THEN returns "```\\ndiscord.js```"', () => { 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```"', () => { 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```');
}); });
}); });

View File

@@ -6,7 +6,7 @@ import type { Snowflake } from 'discord-api-types/globals';
* *
* @param content - The content to wrap * @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 * Wraps the content inside a codeblock with the specified language
@@ -14,9 +14,9 @@ export function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\`\`\``;
* @param language - The language for the codeblock * @param language - The language for the codeblock
* @param content - The content to wrap * @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 { 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\`\`\``;
} }
/** /**