mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
feat(Util): escape more markdown characters (#8701)
* feat(Util): escape more markdown characters Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com> * types(EscapeMarkdownOptions): update types Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com> * fix: lists bulleted with `*` Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com> * tests(escapeMarkdown): add tests Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com> Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
const Util = require('../src/util/Util');
|
||||
const testString = "`_Behold!_`\n||___~~***```js\n`use strict`;\nrequire('discord.js');```***~~___||";
|
||||
const testStringForums =
|
||||
'# Title\n## Subtitle\n### Subsubtitle\n- Bullet list\n - # Title with bullet\n * Subbullet\n1. Number list\n 1. Sub number list';
|
||||
|
||||
describe('escapeCodeblock', () => {
|
||||
test('shared', () => {
|
||||
@@ -94,6 +96,48 @@ describe('escapeSpoiler', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('escapeHeading', () => {
|
||||
test('shared', () => {
|
||||
expect(Util.escapeHeading(testStringForums)).toEqual(
|
||||
'\\# Title\n\\## Subtitle\n\\### Subsubtitle\n- Bullet list\n - \\# Title with bullet\n * Subbullet\n1. Number list\n 1. Sub number list',
|
||||
);
|
||||
});
|
||||
|
||||
test('basic', () => {
|
||||
expect(Util.escapeHeading('# test')).toEqual('\\# test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('escapeBulletedList', () => {
|
||||
test('shared', () => {
|
||||
expect(Util.escapeBulletedList(testStringForums)).toEqual(
|
||||
'# Title\n## Subtitle\n### Subsubtitle\n\\- Bullet list\n \\- # Title with bullet\n \\* Subbullet\n1. Number list\n 1. Sub number list',
|
||||
);
|
||||
});
|
||||
|
||||
test('basic', () => {
|
||||
expect(Util.escapeBulletedList('- test')).toEqual('\\- test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('escapeNumberedList', () => {
|
||||
test('shared', () => {
|
||||
expect(Util.escapeNumberedList(testStringForums)).toEqual(
|
||||
'# Title\n## Subtitle\n### Subsubtitle\n- Bullet list\n - # Title with bullet\n * Subbullet\n1\\. Number list\n 1\\. Sub number list',
|
||||
);
|
||||
});
|
||||
|
||||
test('basic', () => {
|
||||
expect(Util.escapeNumberedList('1. test')).toEqual('1\\. test');
|
||||
});
|
||||
});
|
||||
|
||||
describe('escapeMaskedLink', () => {
|
||||
test('basic', () => {
|
||||
expect(Util.escapeMaskedLink('[test](https://discord.js.org)')).toEqual('\\[test](https://discord.js.org)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('escapeMarkdown', () => {
|
||||
test('shared', () => {
|
||||
expect(Util.escapeMarkdown(testString)).toEqual(
|
||||
@@ -176,7 +220,7 @@ describe('escapeMarkdown', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('edge-case odd number of fenses with no code block content', () => {
|
||||
test('edge-case odd number of fences with no code block content', () => {
|
||||
expect(
|
||||
Util.escapeMarkdown('**foo** ```**bar**``` **fizz** ``` **buzz**', {
|
||||
codeBlock: false,
|
||||
|
||||
Reference in New Issue
Block a user