mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-25 10:25:41 +01:00
164 lines
4.7 KiB
TypeScript
164 lines
4.7 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import * as assert from 'assert';
|
|
import { MarkdownString } from 'vs/base/common/htmlContent';
|
|
|
|
suite('MarkdownString', () => {
|
|
|
|
test('Escape leading whitespace', function () {
|
|
const mds = new MarkdownString();
|
|
mds.appendText('Hello\n Not a code block');
|
|
assert.strictEqual(mds.value, 'Hello\n\n Not a code block');
|
|
});
|
|
|
|
test('MarkdownString.appendText doesn\'t escape quote #109040', function () {
|
|
const mds = new MarkdownString();
|
|
mds.appendText('> Text\n>More');
|
|
assert.strictEqual(mds.value, '\\> Text\n\n\\>More');
|
|
});
|
|
|
|
test('appendText', () => {
|
|
|
|
const mds = new MarkdownString();
|
|
mds.appendText('# foo\n*bar*');
|
|
|
|
assert.strictEqual(mds.value, '\\# foo\n\n\\*bar\\*');
|
|
});
|
|
|
|
test('appendLink', function () {
|
|
|
|
function assertLink(target: string, label: string, title: string | undefined, expected: string) {
|
|
const mds = new MarkdownString();
|
|
mds.appendLink(target, label, title);
|
|
assert.strictEqual(mds.value, expected);
|
|
}
|
|
|
|
assertLink(
|
|
'https://example.com\\()', 'hello', undefined,
|
|
'[hello](https://example.com\\(\\))'
|
|
);
|
|
assertLink(
|
|
'https://example.com', 'hello', 'title',
|
|
'[hello](https://example.com "title")'
|
|
);
|
|
assertLink(
|
|
'foo)', 'hello]', undefined,
|
|
'[hello\\]](foo\\))'
|
|
);
|
|
assertLink(
|
|
'foo\\)', 'hello]', undefined,
|
|
'[hello\\]](foo\\))'
|
|
);
|
|
assertLink(
|
|
'fo)o', 'hell]o', undefined,
|
|
'[hell\\]o](fo\\)o)'
|
|
);
|
|
assertLink(
|
|
'foo)', 'hello]', 'title"',
|
|
'[hello\\]](foo\\) "title\\"")'
|
|
);
|
|
});
|
|
|
|
suite('appendCodeBlock', () => {
|
|
function assertCodeBlock(lang: string, code: string, result: string) {
|
|
const mds = new MarkdownString();
|
|
mds.appendCodeblock(lang, code);
|
|
assert.strictEqual(mds.value, result);
|
|
}
|
|
|
|
test('common cases', () => {
|
|
// no backticks
|
|
assertCodeBlock('ts', 'const a = 1;', `\n${[
|
|
'```ts',
|
|
'const a = 1;',
|
|
'```'
|
|
].join('\n')}\n`);
|
|
// backticks
|
|
assertCodeBlock('ts', 'const a = `1`;', `\n${[
|
|
'```ts',
|
|
'const a = `1`;',
|
|
'```'
|
|
].join('\n')}\n`);
|
|
});
|
|
|
|
// @see https://github.com/microsoft/vscode/issues/193746
|
|
test('escape fence', () => {
|
|
// fence in the first line
|
|
assertCodeBlock('md', '```\n```', `\n${[
|
|
'````md',
|
|
'```\n```',
|
|
'````'
|
|
].join('\n')}\n`);
|
|
// fence in the middle of code
|
|
assertCodeBlock('md', '\n\n```\n```', `\n${[
|
|
'````md',
|
|
'\n\n```\n```',
|
|
'````'
|
|
].join('\n')}\n`);
|
|
// longer fence at the end of code
|
|
assertCodeBlock('md', '```\n```\n````\n````', `\n${[
|
|
'`````md',
|
|
'```\n```\n````\n````',
|
|
'`````'
|
|
].join('\n')}\n`);
|
|
});
|
|
});
|
|
|
|
suite('ThemeIcons', () => {
|
|
|
|
suite('Support On', () => {
|
|
|
|
test('appendText', () => {
|
|
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
|
|
mds.appendText('$(zap) $(not a theme icon) $(add)');
|
|
|
|
assert.strictEqual(mds.value, '\\\\$\\(zap\\) $\\(not a theme icon\\) \\\\$\\(add\\)');
|
|
});
|
|
|
|
test('appendMarkdown', () => {
|
|
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
|
|
mds.appendMarkdown('$(zap) $(not a theme icon) $(add)');
|
|
|
|
assert.strictEqual(mds.value, '$(zap) $(not a theme icon) $(add)');
|
|
});
|
|
|
|
test('appendMarkdown with escaped icon', () => {
|
|
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
|
|
mds.appendMarkdown('\\$(zap) $(not a theme icon) $(add)');
|
|
|
|
assert.strictEqual(mds.value, '\\$(zap) $(not a theme icon) $(add)');
|
|
});
|
|
|
|
});
|
|
|
|
suite('Support Off', () => {
|
|
|
|
test('appendText', () => {
|
|
const mds = new MarkdownString(undefined, { supportThemeIcons: false });
|
|
mds.appendText('$(zap) $(not a theme icon) $(add)');
|
|
|
|
assert.strictEqual(mds.value, '$\\(zap\\) $\\(not a theme icon\\) $\\(add\\)');
|
|
});
|
|
|
|
test('appendMarkdown', () => {
|
|
const mds = new MarkdownString(undefined, { supportThemeIcons: false });
|
|
mds.appendMarkdown('$(zap) $(not a theme icon) $(add)');
|
|
|
|
assert.strictEqual(mds.value, '$(zap) $(not a theme icon) $(add)');
|
|
});
|
|
|
|
test('appendMarkdown with escaped icon', () => {
|
|
const mds = new MarkdownString(undefined, { supportThemeIcons: true });
|
|
mds.appendMarkdown('\\$(zap) $(not a theme icon) $(add)');
|
|
|
|
assert.strictEqual(mds.value, '\\$(zap) $(not a theme icon) $(add)');
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
});
|